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

gopackagesdriver aspect output filename collision (.pkg.json) #3106

Closed
ok32 opened this issue Apr 6, 2022 · 2 comments
Closed

gopackagesdriver aspect output filename collision (.pkg.json) #3106

ok32 opened this issue Apr 6, 2022 · 2 comments

Comments

@ok32
Copy link

ok32 commented Apr 6, 2022

What version of rules_go are you using?

451f267

What version of gazelle are you using?

What version of Bazel are you using?

5.0.0-homebrew

Does this issue reproduce with the latest releases of all the above?

yes

What operating system and processor architecture are you using?

macos, x86-64

Any other potentially useful information about your toolchain?

What did you do?

Tried using //go/tools/gopackagesdriver in a repo structured like the following minial example: https://github.com/ok32/rules_go_aspect_bug .

What did you expect to see?

I expected it to work.

What did you see instead?

It breaks down on abc/abc_test.go.

Further investigation has shown that it generally breaks if:

  • the target is a test
  • that tests embeds a library which has a dependecy on a package with the same name as the library

How to reproduce

git clone https://github.com/ok32/rules_go_aspect_bug

This works (not a test target):

bazel build \
    --experimental_convenience_symlinks=ignore \
    --aspects=@io_bazel_rules_go//go/tools/gopackagesdriver:aspect.bzl%go_pkg_info_aspect \
    --output_groups=go_pkg_driver_json_file,go_pkg_driver_stdlib_json_file,go_pkg_driver_srcs \
    //abc:abc --subcommands

But this doesn't:

bazel build \
    --experimental_convenience_symlinks=ignore \
    --aspects=@io_bazel_rules_go//go/tools/gopackagesdriver:aspect.bzl%go_pkg_info_aspect \
    --output_groups=go_pkg_driver_json_file,go_pkg_driver_stdlib_json_file,go_pkg_driver_srcs \
    //abc:abc_test --subcommands

It outputs an error:

ERROR: file 'abc/abc.pkg.json' is generated by these conflicting actions:
Label: //abc:abc, //abc:abc_test
RuleClass: go_library rule, go_test rule
Configuration: 6ce34163bfbd3676ac846c4d40d7bd78b19138e848dffd069ada524d4e8e5a67, a7058d315debeef2eff4e053ea51cf00209814c3324262972d58300e41d5054a
Mnemonic: FileWrite
Action key: 64914f125e758196376624426b91b0caf41e87b1af8978762498baa836d346c2, 705900d71e6d42536e6578136d957d67a6660d4caeb2f55e168ed10b750de01e
Progress message: Writing file abc/abc.pkg.json
PrimaryInput: (null)
PrimaryOutput: File:[[<execution_root>]bazel-out/darwin-fastbuild/bin]abc/abc.pkg.json
Owner information: []#@io_bazel_rules_go//go/tools/gopackagesdriver:aspect.bzl%go_pkg_info_aspect BuildConfigurationValue.Key[6ce34163bfbd3676ac846c4d40d7bd78b19138e848dffd069ada524d4e8e5a67] ConfiguredTargetKey{label=//abc:abc, config=BuildConfigurationValue.Key[6ce34163bfbd3676ac846c4d40d7bd78b19138e848dffd069ada524d4e8e5a67]} {}, []#@io_bazel_rules_go//go/tools/gopackagesdriver:aspect.bzl%go_pkg_info_aspect BuildConfigurationValue.Key[a7058d315debeef2eff4e053ea51cf00209814c3324262972d58300e41d5054a] ConfiguredTargetKey{label=//abc:abc_test, config=BuildConfigurationValue.Key[a7058d315debeef2eff4e053ea51cf00209814c3324262972d58300e41d5054a]} {}
MandatoryInputs: are equal
Outputs: are equal

Basically, it tries to create two abc.pkg.json's in the same dir, one for each of the targets: //a/abc and //abc.

What helps

As a workaround, patching this line https://github.com/bazelbuild/rules_go/blob/451f26754eeb2c4002984873774414caab1cfd57/go/tools/gopackagesdriver/aspect.bzl#L54 to

pkg_json_file = ctx.actions.declare_file(archive.data.importpath + "/" + archive.data.name + ".pkg.json")

works.

But I'm not sure it's the best way to fix it.

@skevy
Copy link

skevy commented Apr 7, 2022

Will be fixed by whatever approach is landed on in #3053.

@linzhp
Copy link
Contributor

linzhp commented May 16, 2022

Should be fixed by #3111. Reopen if it doesn't

@linzhp linzhp closed this as completed May 16, 2022
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

No branches or pull requests

3 participants