Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m2local: solve files not getting resolved #961

Merged

Conversation

gergelyfabian
Copy link
Contributor

@gergelyfabian gergelyfabian commented Sep 22, 2023

Coursier can resolve m2local artifacts when pinning. However, if you try using them, they will fail stamping:

Stamping the manifest of @maven//:dev_zio_zio_test_2_12 failed: missing input file 'external/maven/dev/zio/zio-test_2.12/2.0.18-RC0-whatever/zio-test_2.12-2.0.18-RC0-whatever.jar', owner: '@maven//:dev/zio/zio-test_2.12/2.0.18-RC0-whatever/zio-test_2.12-2.0.18-RC0-whatever.jar'

This is assuming, that I have built dev.zio:zio-test-junit_2.12:2.0.18-RC0-whatever locally, deployed it to ~/.m2/repository and then set up a dependency on it, enabled m2local and tried using the artifact.

There are two reasons to that:

  1. In coursier.bzl we are not adding a local url to the generated http_file() usage (so it does not download it)
  2. A corresponding genrule entry is not generated in dependency_tree_parser.bzl

Fix it by adding a local url in coursier.bzl and ensure a genrule is added. This way the file is downloaded and then properly copied (and is available for stamping).

Added has_m2local to v2_lock_file.bzl.

@gergelyfabian
Copy link
Contributor Author

This is demonstration PR first and foremost (how the reported problem could be fixed - I use this branch for local testing).
Please feel free to get inspired, and solve it totally differently :)

@gergelyfabian
Copy link
Contributor Author

Probably related to #935.

@gergelyfabian
Copy link
Contributor Author

To be exact, yes, I use m2local, and I pin the artifacts.

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gergelyfabian. Thank you for prepping the PR and explaining how and why it works, and my apologies for a slow turn-around on this review. That's really appreciated.

Could you please add a test for this, as it's the kind of thing that I think will easily slip through the cracks as we make changes? You may find it easiest to add something to the tests/bazel_run_tests.sh script we have: there's definitely at least one test in there to do with working with m2local. If you need a hand with this, please comment here or just ping me on the public Bazel slack and I'll do what I can.

@@ -189,4 +193,5 @@ v2_lock_file = struct(
get_artifacts = _get_artifacts,
get_netrc_entries = _get_netrc_entries,
render_lock_file = _render_lock_file,
has_m2local = _has_m2local,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to make a matching change in the v1_lock_file.bzl file too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@gergelyfabian
Copy link
Contributor Author

Hi @gergelyfabian. Thank you for prepping the PR and explaining how and why it works, and my apologies for a slow turn-around on this review. That's really appreciated.

Could you please add a test for this, as it's the kind of thing that I think will easily slip through the cracks as we make changes? You may find it easiest to add something to the tests/bazel_run_tests.sh script we have: there's definitely at least one test in there to do with working with m2local. If you need a hand with this, please comment here or just ping me on the public Bazel slack and I'll do what I can.

Thank you! Great advice. I tried and realized that the aspect I was fixing in this PR is not covered in those tests (quite expected though).

Thinking about current master:
If I add a usage and build that (in this test), it will work, if there was no pinning before that. But if there was pinning, then building the usage site will fail.

I'll try covering this (and more) with tests.

@gergelyfabian
Copy link
Contributor Author

What's more, even just this will fail:

  bazel run @m2local_testing//:pin >> "$TEST_LOG" 2>&1
  bazel build @m2local_testing//:com_example_kt >> "$TEST_LOG" 2>&1

@gergelyfabian
Copy link
Contributor Author

gergelyfabian commented Sep 29, 2023

Will update the PR, two separate commits: 1. fix, 2. test extensions. One could prove the tests are reproducing this issue by reverting the fix (and then they fail).

@gergelyfabian
Copy link
Contributor Author

Here is the reproduction from the tests:

Loading: 
Loading: 
Loading: 0 packages loaded
Analyzing: target @m2local_testing_repin//:com_example_kt (1 packages loaded, 0 targets configured)
INFO: Analyzed target @m2local_testing_repin//:com_example_kt (1 packages loaded, 198 targets configured).
INFO: Found 1 target...
[0 / 2] [Prepa] BazelWorkspaceStatusAction stable-status.txt
ERROR: /home/user/.cache/bazel/_bazel_user/1bb95ac349d3f130ffd59ff30271af69/external/m2local_testing_repin/BUILD:9:11: Stamping the manifest of @m2local_testing_repin//:com_example_kt failed: missing input file '@m2local_testing_repin//:com/example/kt/1.0.0/kt-1.0.0.jar'
ERROR: /home/user/.cache/bazel/_bazel_user/1bb95ac349d3f130ffd59ff30271af69/external/m2local_testing_repin/BUILD:9:11: Stamping the manifest of @m2local_testing_repin//:com_example_kt failed: 1 input file(s) do not exist
Target @m2local_testing_repin//:com_example_kt failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/user/.cache/bazel/_bazel_user/1bb95ac349d3f130ffd59ff30271af69/external/m2local_testing_repin/BUILD:9:11 Stamping the manifest of @m2local_testing_repin//:com_example_kt failed: 1 input file(s) do not exist
INFO: Elapsed time: 0.180s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
FAILED: Build did NOT complete successfully

@gergelyfabian
Copy link
Contributor Author

Missing parts added, tests added (reverting the fix fails them), windows issues solved. All tests are passing. Should be ready for re-review.

@gergelyfabian
Copy link
Contributor Author

@shs96c did you have a chance to review this one maybe? I think all issues should be solved.

Coursier can resolve m2local artifacts when pinning.
However, if you try using them, they will fail stamping:

```
Stamping the manifest of @maven//:dev_zio_zio_test_2_12 failed: missing input file 'external/maven/dev/zio/zio-test_2.12/2.0.18-RC0-whatever/zio-test_2.12-2.0.18-RC0-whatever.jar', owner: '@maven//:dev/zio/zio-test_2.12/2.0.18-RC0-whatever/zio-test_2.12-2.0.18-RC0-whatever.jar'
```

This is assuming, that I have built dev.zio:zio-test-junit_2.12:2.0.18-RC0-whatever
locally and deployed it to ~/.m2/repository.

There are two reasons to that:
1. In coursier.bzl we are not adding a local url to the generated
   http_file() usage (so it does not download it)
2. A corresponding genrule entry is not generated in dependency_tree_parser.bzl

Fix it by adding a local url in coursier.bzl and ensure a genrule is added.
This way the file is downloaded and then properly copied (and is available
for stamping).

Added has_m2local to v1_lock_file.bzl and v2_lock_file.bzl.
Extended pinning test cases with also building the local artifact
(the bug is only reproducible with pinning and occurs when building the
artifact).
Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@shs96c shs96c merged commit aa44247 into bazel-contrib:master Dec 11, 2023
8 checks passed
@gergelyfabian gergelyfabian deleted the load_m2local_artifacts_properly branch December 12, 2023 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants