-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
fix: expand_location binary target inputs #16381
fix: expand_location binary target inputs #16381
Conversation
The previous behaviour was that location expansion on native rules would accept binary targets as inputs and resolve to a single location. This was not an option on custom rules. This patch aligns the behaviour of Starlark's ctx.expand_location to the native rules. E.g. a py_binary can be expanded using location/execpath/rootpath instead of previously only locations/execpaths/rootpaths. Signed-off-by: Thulio Ferraz Assis <[email protected]>
Hello @f0rmiga, Can you please fix the failed buildkite checks. Thanks! |
That's a funny failure since the same test passed on all other platforms, including other centos. Any chance it flaked? |
For context: formiga came across this difference in behavior when trying to put a After a big of digging, we were found the difference is how StarlarkRuleContext and native rules create their LocationExpander. StarlarkRuleContext (through StarlarkRuleContext.expandLocation) creates an expander that doesn't look at the data attribute and passes in a label map with the default outputs of the In comparison, a native rule usually creates the location expanded through RunfilesSupport (RunfilesSupport.computeActionEnvironment). It creates an expander that does look at the data attribute and passes in a empty/null label map. LocationExpander has hard-coded logic to look at the deps, data, and tools attributes and only add targets from them that have FilesToRunProvider; these are then added to the label map it builds before processing. The net effect is the map has HTH |
src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java
Outdated
Show resolved
Hide resolved
...est/java/com/google/devtools/build/lib/starlark/StarlarkRuleImplementationFunctionsTest.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java
Outdated
Show resolved
Hide resolved
...est/java/com/google/devtools/build/lib/starlark/StarlarkRuleImplementationFunctionsTest.java
Show resolved
Hide resolved
@sgowroji I've removed the team-Rules-Python tag -- this isn't Python specific and this code isn't part of the Python implementation. I'm not sure offhand who the domain owner is for this |
Signed-off-by: Thulio Ferraz Assis <[email protected]>
Signed-off-by: Thulio Ferraz Assis <[email protected]>
Signed-off-by: Thulio Ferraz Assis <[email protected]>
src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Thulio Ferraz Assis <[email protected]>
@comius it looks like you've been reviewing changes to StarlarkRuleContext and expand_location recently? I think this PR is ready for review. If the behavior change here isn't acceptable, then see #16382 for some other ideas/discussion about how we might let Starlark code better act here. In the mean time, I've imported this internally and started a TGP. |
@rickeylev (tagging myself to make this findable) |
The global regression tests finally finished, but it's unclear if there was an infrastructure failure, this broke many things, or just broke a handful of very low-level dependencies. I'm having a look. |
Ok, I think i figured out what's going on. The basic code in question is:
Without this PR, the expansion is bla/thing. With this PR, it expands to bla/thing_executable As a concrete example, this seems to happen when the wasm rules apply a transition to a cc_test. The cc_test puts the original test executable in the default outputs, but then the wasm transition somehow causes it to put a wasm-specific executable as the test's executable, but it doesn't show up in default outputs. I think wasm changing the name is WAI; I see some code that seems to indicate the cc toolchain (wasm in this case) can affect the output name. So the general case is when a rule doesn't put its own executable in the default outputs. That seems very strange -- why would one do that on purpose? This seems like a bug in the cc_test rules. Actually, wait, I thought the executable was always added? Aha, yes, Executable rules docs say:
So this definitely sounds like a bug somewhere. |
Quick update: I've found the owner of the code that fails and they're going to have a look. At a glance, it looks more like a bug in their code. After they assess, we'll figure out next steps (maybe it's an easy fix, or medium and need to wait, or hard and adding a flag somewhere might be needed, etc). |
I've fixed the particular internal rule that was failing, and the related tests pass with this import. |
Thank you @trybka. |
The previous behaviour was that location expansion on native rules would accept binary targets as inputs and resolve to a single location. This was not an option on custom rules. This patch aligns the behaviour of Starlark's ctx.expand_location to the native rules. E.g. a py_binary can be expanded using location/execpath/rootpath instead of previously only locations/execpaths/rootpaths. For more context, see bazelbuild/rules_python#846. To be able to add the multi-toolchain feature to rules_python, I had to trick `ctx.expand_location` using the `tools` attribute while this is not fixed. Closes #16381. PiperOrigin-RevId: 502466606 Change-Id: I3977f2dd479a55308bdda982588697fb04abcedf
The previous behaviour was that location expansion on native rules would accept binary targets as inputs and resolve to a single location. This was not an option on custom rules. This patch aligns the behaviour of Starlark's ctx.expand_location to the native rules. E.g. a py_binary can be expanded using location/execpath/rootpath instead of previously only locations/execpaths/rootpaths.
For more context, see bazelbuild/rules_python#846. To be able to add the multi-toolchain feature to rules_python, I had to trick
ctx.expand_location
using thetools
attribute while this is not fixed.