Skip to content

Don't swallow runfiles of srcs in data runfiles of filegroup#25365

Closed
fmeum wants to merge 1 commit intobazelbuild:masterfrom
fmeum:fix-filegroup
Closed

Don't swallow runfiles of srcs in data runfiles of filegroup#25365
fmeum wants to merge 1 commit intobazelbuild:masterfrom
fmeum:fix-filegroup

Conversation

@fmeum
Copy link
Collaborator

@fmeum fmeum commented Feb 24, 2025

The data_runfiles of a filegroup should contain the data_runfiles of all deps in srcs, plus the data_runfiles of all deps in data. Previously, they didn't contain the former.

Related to #25329 (comment)

The `data_runfiles` of a `filegroup` should contain the `data_runfiles`
of all deps in `srcs`, plus the `data_runfiles` of all deps in `data`.
Previously, they didn't contain the former.
@fmeum
Copy link
Collaborator Author

fmeum commented Feb 24, 2025

I'm not entirely sure whether the correct behavior would be to merge in the data_runfiles or the default_runfiles of srcs as these have been deprecated for a while and Starlark rules rarely distinguish between the two. @lberki Are you able to make the call? :-)

@fmeum fmeum marked this pull request as ready for review February 24, 2025 12:04
@fmeum fmeum requested a review from lberki as a code owner February 24, 2025 12:04
@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Feb 24, 2025
@meteorcloudy
Copy link
Member

@fmeum
Copy link
Collaborator Author

fmeum commented Feb 24, 2025

Thanks, the run looks good, all failures are caused by known issues.

@meteorcloudy
Copy link
Member

Nice, @comius @lberki please double check this change is safe.

@iancha1992 iancha1992 added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Feb 25, 2025
@lberki
Copy link
Contributor

lberki commented Feb 26, 2025

Ow. This is definitely a change that I'd love to land (DATA_RUNFILES should die) but also has a chance that it'd break things at Google. How about this: I'll kick off a test run for Google's tests tomorrow morning (Europe) (it's already too late for that today) and report back. If it comes back clean, let's submit it, if not, depending on the amount of fallout, either we'll fix it at Google or you go with the sh_library approach.

Hm?

@fmeum
Copy link
Collaborator Author

fmeum commented Feb 26, 2025

Sounds good!

@lberki
Copy link
Contributor

lberki commented Feb 27, 2025

Update: the overnight test sampling run (all I could do overnight) came back clean and I kicked off the full test run. Results should be in in a few hours.

ruleContext.getWorkspaceName(), configuration.legacyExternalRunfiles())
.addTransitiveArtifacts(filesToBuild)
.addDataDeps(ruleContext)
.addRunfiles(ruleContext, RunfilesProvider.DATA_RUNFILES)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lberki If you want this to be DEFAULT_RUNFILES so that it's not changed again later, I'm okay with that too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Meh let's not poke that beast

@lberki
Copy link
Contributor

lberki commented Feb 28, 2025

I ran our internal test battery and it looks fine. Let's merge this and thanks for your patience!

@lberki lberki added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Feb 28, 2025
@copybara-service copybara-service bot closed this in 15a3526 Mar 1, 2025
@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Mar 1, 2025
@fmeum fmeum deleted the fix-filegroup branch March 1, 2025 08:05
copybara-service bot pushed a commit that referenced this pull request Mar 5, 2025
*** Reason for rollback ***

b/400902205, breaks blaze nightly build 2025-03-01 ff.

*** Original change description ***

Don't swallow runfiles of `srcs` in data runfiles of `filegroup`

The `data_runfiles` of a `filegroup` should contain the `data_runfiles` of all deps in `srcs`, plus the `data_runfiles` of all deps in `data`. Previously, they didn't contain the former.

Related to #25329 (comment)

Closes #25365.

PiperOrigin-RevId: 733682081
Change-Id: Ibdc06c70e585758fe19ff8666aa4a02adaa0d348
@fmeum
Copy link
Collaborator Author

fmeum commented Mar 12, 2025

@lberki Can you share more details on the reason for the rollback?

@lberki
Copy link
Contributor

lberki commented Mar 14, 2025

It's a few failing tests with quite possible a single root cause that I keep not finding enough time to debug :(

@lberki
Copy link
Contributor

lberki commented Mar 20, 2025

I did some debugging (for Googlers, link is b/405063764) and it looks like there are three different root causes, all because this change adds some extra files to the runfiles trees of some tests, which tips two tests over the maximum size of nput files and confuses one test.

I'm afraid this'll require quite some debugging on our part.

@lberki
Copy link
Contributor

lberki commented Mar 20, 2025

Looking at this more deeply, I'm not entirely sure that this is the right fix. I do realize that there is a comment that says that filegroups should visit their data dependencies as data and their srcs as default, but one could argue that semantically, not doing the latter works better.

Is there an alternative fix? I'm currently elbow deep into some hairy Starlark rules to figure out where the extra files come from and I'm not sure if I can fix these without causing collateral damage.

@lberki
Copy link
Contributor

lberki commented Mar 20, 2025

I tracked down one of the failures and it's indeed as I suspected. The structure is like this:

cc_library(name="lib", data=[":one"]
filegroup(name="one", data=[":big"])
filegroup(name="big", srcs=[<big files>])

And this change adds <big files> to the data runfiles of :big, therefore, to the regular runfiles of :lib. Which is not unreasonable.

@fmeum
Copy link
Collaborator Author

fmeum commented Mar 20, 2025

I would go as far as calling that the only reasonable behavior, but I can see how that would require some cleanup. :⁠-⁠)

@lberki
Copy link
Contributor

lberki commented Mar 20, 2025

I would go as far as calling that the only reasonable behavior, but I can see how that would require some cleanup. :⁠-⁠)

Why's that? My mental model is that the concept of "data runfiles" is not very well defined and if you accept that as a fact, it's difficult to argue for any sort of behavior based on principles.

@fmeum
Copy link
Collaborator Author

fmeum commented Mar 20, 2025

Did you mean to write "to the data runfiles of :one" above? My mental model always has been that a data dependency edge translates data runfiles into ordinary runfiles.

@fmeum
Copy link
Collaborator Author

fmeum commented Mar 20, 2025

A different perspective: filegroup(..., srcs = [...]) should probably be referentially transparent in the sense that

cc_library(name="lib", data=[":one"]
filegroup(name="one", data=[":big"])
filegroup(name="big", srcs=["big1", "big2"])

behaves just like

cc_library(name="lib", data=[":one"]
filegroup(name="one", data=["big1", "big2"])

whatever data semantics are precisely.

@lberki
Copy link
Contributor

lberki commented Mar 24, 2025

@fmeum that's a sound line of reasoning, although if you think a step deeper, the inevitable conclusion is that since filegroup is just, well, a group of files, the "data" attribute on it doesn't make sense at all. But there we are...

Did you mean to write "to the data runfiles of :one" above?

Technically, yes, to the data runfiles of :one, but those eventually land in the regular runfiles of ``:lib` also.

@fmeum
Copy link
Collaborator Author

fmeum commented Mar 26, 2025

@lberki I took another look at the motivating issue #25513, which doesn't use the data attribute on filegroup. The dependency structure is equivalent to:

sh_test(name = "test", srcs = ["test.sh"], data = [":filegroup"])
filegroup(name = "filegroup", srcs = [":binary"])
sh_binary(name = "binary", srcs = ["binary.sh"], data = ["foo.txt"])

I find it extremely surprising that the runfile foo.txt is lost in this case. As a result, filegroup practically isn't safe to use in data attributes of any rule as long as it references binary targets. This is particularly bad for Bazel, where the filegroup may be authored by a first party user while the binary target comes from a ruleset.

I'm ultimately fine with any kind of semantics of filegroup(data = ...) as long as we can preserve existing runfiles for filegroup(srcs = ...). We could also guard the new behavior behind a flag that is never flipped for Blaze.

@meteorcloudy
Copy link
Member

@lberki Do you think if it's feasible to just fix the internal tests? If so, I can also help with that.

@lberki
Copy link
Contributor

lberki commented Apr 4, 2025

It's at least not easy. The obvious fix would be to merge the runfiles so that what filegroup() does is the same regardless of which attribute the files are under, but it's been experimentally proven that that causes "too many input files" errors.

@meteorcloudy
Copy link
Member

@fmeum Sorry, it looks like it'll take a significant amount of work to fix google internal projects, is there any other workaround to make Bazel's downstream green again?

@fmeum
Copy link
Collaborator Author

fmeum commented Apr 14, 2025

I'll send a targeted fix.

copybara-service bot pushed a commit that referenced this pull request Jun 18, 2025
If true, runfiles of targets listed in the srcs attribute of a filegroup are available to targets that consume the filegroup as a data dependency.

Reland of #25365 behind an incompatible flag

Closes #25978.

PiperOrigin-RevId: 772841978
Change-Id: Ia8f126bb33e02969eafdbd6972c83f5350d58be2
fmeum added a commit to fmeum/bazel that referenced this pull request Jul 5, 2025
If true, runfiles of targets listed in the srcs attribute of a filegroup are available to targets that consume the filegroup as a data dependency.

Reland of bazelbuild#25365 behind an incompatible flag

Closes bazelbuild#25978.

PiperOrigin-RevId: 772841978
Change-Id: Ia8f126bb33e02969eafdbd6972c83f5350d58be2
(cherry picked from commit cac453b)
fmeum added a commit to fmeum/bazel that referenced this pull request Jul 5, 2025
If true, runfiles of targets listed in the srcs attribute of a filegroup are available to targets that consume the filegroup as a data dependency.

Reland of bazelbuild#25365 behind an incompatible flag

Closes bazelbuild#25978.

PiperOrigin-RevId: 772841978
Change-Id: Ia8f126bb33e02969eafdbd6972c83f5350d58be2
(cherry picked from commit cac453b)
github-merge-queue bot pushed a commit that referenced this pull request Jul 7, 2025
If true, runfiles of targets listed in the srcs attribute of a filegroup
are available to targets that consume the filegroup as a data
dependency.

Reland of #25365 behind an
incompatible flag

Closes #25978.

PiperOrigin-RevId: 772841978
Change-Id: Ia8f126bb33e02969eafdbd6972c83f5350d58be2 
(cherry picked from commit cac453b)

Closes #26419
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants