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

Always collect FileProvider's filesToBuild as data runfiles #15052

Closed
wants to merge 3 commits into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Mar 15, 2022

Guidelines for Starlark rules suggest that data-like attributes on
rules should always merge the default outputs of rule targets into the
transitive runfiles. See:
https://docs.bazel.build/versions/main/skylark/rules.html#runfiles-features-to-avoid

As a result, Starlark rules generally don't (and shouldn't) explicitly
include their default outputs into their runfiles. Before this commit,
native rules did not merge these outputs in the same way as idiomatic
Starlark rules, which led to unexpectedly absent runfiles.

Fixes #15043

@fmeum fmeum changed the title Always collect files as data runfiles TEMP: Always collect files as data runfiles Mar 15, 2022
@fmeum fmeum force-pushed the always-collect-files-as-data branch from 5385e74 to c7d937d Compare March 15, 2022 14:32
@fmeum fmeum force-pushed the always-collect-files-as-data branch from c7d937d to f9dbbe8 Compare March 15, 2022 16:29
@fmeum fmeum changed the title TEMP: Always collect files as data runfiles Always collect FileProvider's filesToBuild as data runfiles Mar 15, 2022
@fmeum fmeum marked this pull request as ready for review March 15, 2022 16:40
@comius
Copy link
Contributor

comius commented Mar 16, 2022

This looks reasonable. Mind that we're rewriting all the rules where this applies to Starlark.

I'll run internal unit tests, to see if this breaks anything, but I don't expect it to.

@comius
Copy link
Contributor

comius commented Mar 16, 2022

I'll run internal unit tests, to see if this breaks anything, but I don't expect it to.

There are some breakages on internal unit tests, but it seems just the tests have to be updated.

@fmeum fmeum force-pushed the always-collect-files-as-data branch from f9dbbe8 to 40552e4 Compare March 16, 2022 20:07
@fmeum
Copy link
Collaborator Author

fmeum commented Mar 16, 2022

This looks reasonable. Mind that we're rewriting all the rules where this applies to Starlark.

I'll run internal unit tests, to see if this breaks anything, but I don't expect it to.

Thanks!

@sgowroji sgowroji added team-Rules-Java Issues for Java rules team-Starlark-Integration Issues involving Bazel's integration with Starlark, excluding builtin symbols and removed team-Rules-Java Issues for Java rules labels Mar 17, 2022
@fmeum fmeum force-pushed the always-collect-files-as-data branch from 40552e4 to 98e13a1 Compare March 19, 2022 19:47
@fmeum
Copy link
Collaborator Author

fmeum commented Apr 8, 2022

@comius Did you get a chance to look into the internal unit tests blocking this?

@comius
Copy link
Contributor

comius commented Apr 8, 2022

@comius Did you get a chance to look into the internal unit tests blocking this?

I've put this on my backlog, I will need to do a bit more research and that will take more time.

What happens is that .ifso files from data dependency of a dynamic cc_binary (linkstatic=0) get added to runfiles, and there's tests, that verifies this doesn't happen.

And .so and .a gets added from data dep in the case of static cc_binary (linkstatic=1)

@sgowroji sgowroji added the awaiting-review PR is awaiting review from an assigned reviewer label May 5, 2022
@fmeum
Copy link
Collaborator Author

fmeum commented Jul 5, 2022

@comius Is there anything I can do to help get this into 5.3.0?

The issue fixed by the PR is, based on my personal experience, one of the top gotchas for users writing their first custom rules (including myself and many of my coworkers at some point). It also frequently comes up on the Bazel Slack (most recently at https://bazelbuild.slack.com/archives/CA31HN1T3/p1657044541910759?thread_ts=1657044541.910759&cid=CA31HN1T3). Getting it fixed in Bazel 5 would also help rule authors ditch data_runfiles possibly 9 months earlier.

Would it help if I guarded the change behind a flag that you could flip back inside Google? Or, alternatively, can the failing tests be open-sourced? I could then try to fix the runfile pollution issues in the cc rules.

@fmeum fmeum force-pushed the always-collect-files-as-data branch from 98e13a1 to ca229a4 Compare September 10, 2022 12:26
@fmeum
Copy link
Collaborator Author

fmeum commented Sep 10, 2022

@comius Friendly ping. This is still coming up on Bazel Slack over and over again as a major inconsistency.

Do you think we can get this into Bazel 6? It looks like Starlark cc_binary already has the fixed behavior, otherwise the test wouldn't pass. Presumably the internal tests have been fixed?

Copy link
Contributor

@comius comius left a comment

Choose a reason for hiding this comment

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

I did the changes needed internally - and I'm waiting for feedback from reviewers.

@comius comius added awaiting-user-response Awaiting a response from the author and removed awaiting-review PR is awaiting review from an assigned reviewer labels Oct 6, 2022
@fmeum fmeum force-pushed the always-collect-files-as-data branch from ca229a4 to f8bbf1d Compare October 6, 2022 22:36
@comius comius self-requested a review October 13, 2022 10:29
Copy link
Contributor

@comius comius left a comment

Choose a reason for hiding this comment

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

I have a lot of failures running this change through the depot, I still need to analyse them thought.

It makes sense to put this behind an incompatible flag - because others might have similar problems (and if I don't fix all the failures internally we can still release this in Bazel).

One bug that I already located in the run and you can probably fix from stack trace:

Caused by: java.lang.IllegalArgumentException: Order mismatch: preorder != postorder
	at com.google.common.base.Preconditions.checkArgument(Preconditions.java:441)
	at com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder.addTransitive(NestedSetBuilder.java:138)
	at com.google.devtools.build.lib.analysis.Runfiles$Builder.addTransitiveArtifacts(Runfiles.java:777)
	at com.google.devtools.build.lib.analysis.Runfiles$Builder.addTargetIncludingFileTargets(Runfiles.java:988)
	at com.google.devtools.build.lib.analysis.Runfiles$Builder.addTarget(Runfiles.java:964)
	at com.google.devtools.build.lib.analysis.Runfiles$Builder.addTargets(Runfiles.java:957)
	at com.google.devtools.build.lib.analysis.Runfiles$Builder.addDataDeps(Runfiles.java:938)
	at com.google.devtools.build.lib.analysis.Runfiles$Builder.addRunfiles(Runfiles.java:910)
	at com.google.devtools.build.lib.view.sh.ShBinary.create(ShBinary.java:71)
	at com.google.devtools.build.lib.view.sh.ShBinary.create(ShBinary.java:30)
	at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createRule(ConfiguredTargetFactory.java:371)

Guidelines for Starlark rules suggest that `data`-like attributes on
rules should always merge the default outputs of rule targets into the
transitive runfiles. See:
https://docs.bazel.build/versions/main/skylark/rules.html#runfiles-features-to-avoid

As a result, Starlark rules generally don't (and shouldn't) explicitly
include their default outputs into their runfiles. Before this commit,
native rules did not merge these outputs in the same way as idiomatic
Starlark rules, which led to unexpectedly absent runfiles.

RELNOTES: Native rules now add `DefaultInfo.files` of data dependencies
to their runfiles, which matches the recommended behavior for Starlark
rules (https://bazel.build/extending/rules#runfiles_features_to_avoid).
This new behavior can be controlled via
`--incompatible_always_include_files_in_data`.
@fmeum fmeum force-pushed the always-collect-files-as-data branch from 469914b to 841c19b Compare November 4, 2022 10:09
@fmeum fmeum force-pushed the always-collect-files-as-data branch from 841c19b to 27e3ee9 Compare November 4, 2022 10:10
@fmeum
Copy link
Collaborator Author

fmeum commented Nov 4, 2022

@comius @meteorcloudy Sorry, forgot to update the tests. Should be fixed now.

@meteorcloudy
Copy link
Member

@fmeum Can you follow https://bazel.build/contribute/breaking-changes to file a tracking issue for this incompatible change?

Once this is merged, I'll add the correct labels and it'll be tested in the incompatible flag pipeline

@fmeum
Copy link
Collaborator Author

fmeum commented Nov 4, 2022

@meteorcloudy I created #16654.

@brandjon brandjon added team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts untriaged and removed team-Build-Language untriaged labels Nov 5, 2022
@copybara-service copybara-service bot closed this in 95f9adc Nov 7, 2022
@fmeum fmeum deleted the always-collect-files-as-data branch November 7, 2022 17:01
@fmeum
Copy link
Collaborator Author

fmeum commented Nov 7, 2022

@bazel-io flag

@fmeum
Copy link
Collaborator Author

fmeum commented Nov 7, 2022

@meteorcloudy This has been merged, could you add it to the pipeline?

@meteorcloudy
Copy link
Member

@bazel-io fork 6.0.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Nov 7, 2022
fmeum added a commit to fmeum/bazel that referenced this pull request Nov 7, 2022
Guidelines for Starlark rules suggest that `data`-like attributes on
rules should always merge the default outputs of rule targets into the
transitive runfiles. See:
https://docs.bazel.build/versions/main/skylark/rules.html#runfiles-features-to-avoid

As a result, Starlark rules generally don't (and shouldn't) explicitly
include their default outputs into their runfiles. Before this commit,
native rules did not merge these outputs in the same way as idiomatic
Starlark rules, which led to unexpectedly absent runfiles.

Fixes bazelbuild#15043

Closes bazelbuild#15052.

PiperOrigin-RevId: 486663801
Change-Id: I4a30b8b8a4dfc84bf4de27fd7894dd48e795c081
@meteorcloudy
Copy link
Member

@fmeum This flag is already tested in https://buildkite.com/bazel/bazelisk-plus-incompatible-flags/builds/1325, currently failing with "Unrecognized option" error, we'll get some real result tomorrow ;)

fmeum added a commit to fmeum/bazel that referenced this pull request Nov 7, 2022
Guidelines for Starlark rules suggest that `data`-like attributes on
rules should always merge the default outputs of rule targets into the
transitive runfiles. See:
https://docs.bazel.build/versions/main/skylark/rules.html#runfiles-features-to-avoid

As a result, Starlark rules generally don't (and shouldn't) explicitly
include their default outputs into their runfiles. Before this commit,
native rules did not merge these outputs in the same way as idiomatic
Starlark rules, which led to unexpectedly absent runfiles.

Fixes bazelbuild#15043

Closes bazelbuild#15052.

PiperOrigin-RevId: 486663801
Change-Id: I4a30b8b8a4dfc84bf4de27fd7894dd48e795c081
fmeum added a commit to fmeum/bazel that referenced this pull request Nov 7, 2022
Guidelines for Starlark rules suggest that `data`-like attributes on
rules should always merge the default outputs of rule targets into the
transitive runfiles. See:
https://docs.bazel.build/versions/main/skylark/rules.html#runfiles-features-to-avoid

As a result, Starlark rules generally don't (and shouldn't) explicitly
include their default outputs into their runfiles. Before this commit,
native rules did not merge these outputs in the same way as idiomatic
Starlark rules, which led to unexpectedly absent runfiles.

Fixes bazelbuild#15043

Closes bazelbuild#15052.

PiperOrigin-RevId: 486663801
Change-Id: I4a30b8b8a4dfc84bf4de27fd7894dd48e795c081
fmeum added a commit to fmeum/bazel that referenced this pull request Nov 7, 2022
Guidelines for Starlark rules suggest that `data`-like attributes on
rules should always merge the default outputs of rule targets into the
transitive runfiles. See:
https://docs.bazel.build/versions/main/skylark/rules.html#runfiles-features-to-avoid

As a result, Starlark rules generally don't (and shouldn't) explicitly
include their default outputs into their runfiles. Before this commit,
native rules did not merge these outputs in the same way as idiomatic
Starlark rules, which led to unexpectedly absent runfiles.

Fixes bazelbuild#15043

Closes bazelbuild#15052.

PiperOrigin-RevId: 486663801
Change-Id: I4a30b8b8a4dfc84bf4de27fd7894dd48e795c081
@sgowroji sgowroji removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Nov 8, 2022
ShreeM01 pushed a commit that referenced this pull request Nov 8, 2022
Guidelines for Starlark rules suggest that `data`-like attributes on
rules should always merge the default outputs of rule targets into the
transitive runfiles. See:
https://docs.bazel.build/versions/main/skylark/rules.html#runfiles-features-to-avoid

As a result, Starlark rules generally don't (and shouldn't) explicitly
include their default outputs into their runfiles. Before this commit,
native rules did not merge these outputs in the same way as idiomatic
Starlark rules, which led to unexpectedly absent runfiles.

Fixes #15043

Closes #15052.

PiperOrigin-RevId: 486663801
Change-Id: I4a30b8b8a4dfc84bf4de27fd7894dd48e795c081
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sh_binary's data dependencies are not triggered during the build
7 participants