-
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
propagated for cc_library and cc_binary #9267
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. Thanks!
return this.getAnalysisEnvironment().getSkylarkSemantics().experimentalAllowTagsPropagation(); | ||
} catch (InterruptedException e) { | ||
// fallback to false if value of experimentalAllowTagsPropagation cannot be fetched | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InterruptedException does not mean that the value can't be fetched but that something (i.e. ctrl+c) told it to stop fetching. I think the proper thing to do here is to add a throws InterruptedException
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense. Fixed.
import javax.annotation.Nullable; | ||
import java.util.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for future: add the google-java-style in your IDE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed :)
* actions' execution requirements, for more details {@see | ||
* SkylarkSematicOptions#experimentalAllowTagsPropagation} | ||
*/ | ||
public static Map<String, String> getExecutionInfo(Rule rule, boolean allowTagsPropagation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method is only called in three different sides. Remove it and instead use ternary operator at the call side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -1548,6 +1554,9 @@ private CppCompileActionBuilder initializeCompileAction(Artifact sourceArtifact) | |||
builder.setCcCompilationContext(ccCompilationContext); | |||
builder.setCoptsFilter(coptsFilter); | |||
builder.setFeatureConfiguration(featureConfiguration); | |||
if (ruleContext != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (ruleContext != null && ruleContext.isAllowTagsPropagation()) {
builder.addExecutionInfo(TargetUtils.getExecutionInfo(ruleContext.getRule()))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -141,19 +143,21 @@ public CcLinkingOutputs getCcLinkingOutputs() { | |||
* @param ccToolchain the C++ toolchain provider for the build | |||
* @param fdoContext the C++ FDO optimization support provider for the build | |||
* @param configuration the configuration that gives the directory of output artifacts | |||
* @param ruleContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a comment here explaining ruleContext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -148,6 +148,7 @@ public Artifact create( | |||
// of them. | |||
private boolean isTestOrTestOnlyTarget; | |||
private boolean isStampingEnabled; | |||
private Map<String, String> executionInfo = new LinkedHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be final?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Use ImmutableMap.builder()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, done
@@ -1022,15 +1023,15 @@ public CppLinkAction build() throws InterruptedException, RuleErrorException { | |||
// If the crosstool uses action_configs to configure cc compilation, collect execution info | |||
// from there, otherwise, use no execution info. | |||
// TODO(b/27903698): Assert that the crosstool has an action_config for this action. | |||
Map<String, String> executionRequirements = new LinkedHashMap<>(); | |||
// Map<String, String> executionRequirements = new LinkedHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -767,6 +767,14 @@ sh_test( | |||
tags = ["no_windows"], | |||
) | |||
|
|||
sh_test( | |||
name = "tags_propagation_native_test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hlopko should this test be part of the bazel_rules_cc_test.sh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think we don't need an integration test for this, wdyt about adding an unit test to CcLibraryConfiguredTargetTest? We're testing analysis-only behavior anyway. You'll assert that the action in constructed as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and also a test to CcBinaryConfiguredTargetTest, GenruleConfiguredTargetTest...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, we could do that. I just prefer integration tests in this case - to make sure that in 'real' env it actually works. I also find them more readable here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you find them more readable because you didn't spend much time in the area :) We actually like our BuildViewTestCases more becasue they allow us to inspect the state of the world more easily. Instead of comparing handwritten line of text that aquery outputs you can have assertThat(executionInfo).containsExactly(...).
Plus the integration test will have exactly same coverage as the BuildViewTestCase. And you wouldn't have to deal with platform specific tags such as requires-darwin.
|| fail "should have generated output successfully" | ||
|
||
if [[ "${PLATFORM}" = "darwin" ]]; then | ||
assert_contains "ExecutionInfo: {local: '', no-cache: '', no-remote: '', requires-darwin: ''}" output1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is 'requires-darwin' relevant to this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because if you run a test on iOS platform, then testRunner (or smth like that) will add "requires-darwin" to the actions' execution requirements.
if [[ "${PLATFORM}" = "darwin" ]]; then | ||
assert_contains "ExecutionInfo: {local: '', no-cache: '', no-remote: '', requires-darwin: ''}" output1 | ||
else | ||
assert_contains "ExecutionInfo: {local: '', no-cache: '', no-remote: ''}" output1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nicer if the test didn't depend on the order. Consider
assert_contains "local: ''"
assert_contains "no-cache: ''"
assert_contains "no-remote: ''"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! It really looks like this is the reasonable way forward!
if (allowTagsPropagation){ | ||
return getExecutionInfo(rule); | ||
} else { | ||
return Collections.emptyMap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suuuper nit: ImmutableMap.of() and a change in signature to return ImmutableMap. Or inline as Jakob suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the method :)
@@ -352,7 +352,7 @@ public static ConfiguredTarget init(CppSemantics semantics, RuleContext ruleCont | |||
semantics, | |||
featureConfiguration, | |||
ccToolchain, | |||
fdoContext) | |||
fdoContext, ruleContext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try hard not to pass RuleContext into CcCompilationHelper and CcLinkingHelper because of its huge powers (e.g. it allows you to access rule attributes which is something we don't want to allow in our helpers to keep our code layering clean). Can we instead use ActionConstructionContext that is already passed to CcLinkingInfo? If not, let's pass executionInfo, not rule context, into the constructor of the Helper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, it might work!
I've replaced RuleContext directly with a Rule and pushed isAllowTagsPropagation up to the ActionConstructionContext, @hlopko ptal?
CcToolchainProvider ccToolchain, | ||
FdoContext fdoContext, | ||
BuildConfiguration buildConfiguration, | ||
@Nullable RuleContext ruleContext) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why nullable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it can be null in case of sandwich, like we understood it with Jakob yesterday. See: https://github.com/bazelbuild/bazel/pull/9267/files/49ca1c4f3364a34a398a03b39b29a83552ce1e69#r318975035
I'll also have a look at ActionConstructionContext, maybe we could use that => this @nullable will not be needed at all, as well as RuleContext
@@ -1432,7 +1432,7 @@ public boolean isCcToolchainResolutionEnabled(SkylarkRuleContext skylarkRuleCont | |||
.getActionConstructionContext() | |||
.getConfiguration() | |||
.getFragment(CppConfiguration.class), | |||
((BazelStarlarkContext) starlarkContext).getSymbolGenerator()) | |||
((BazelStarlarkContext) starlarkContext).getSymbolGenerator(), null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is null here ok? You can get to action construction context using actions.getActionConstructionContext() there.
@@ -148,6 +148,7 @@ public Artifact create( | |||
// of them. | |||
private boolean isTestOrTestOnlyTarget; | |||
private boolean isStampingEnabled; | |||
private Map<String, String> executionInfo = new LinkedHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Use ImmutableMap.builder()
@@ -767,6 +767,14 @@ sh_test( | |||
tags = ["no_windows"], | |||
) | |||
|
|||
sh_test( | |||
name = "tags_propagation_native_test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think we don't need an integration test for this, wdyt about adding an unit test to CcLibraryConfiguredTargetTest? We're testing analysis-only behavior anyway. You'll assert that the action in constructed as expected.
@@ -767,6 +767,14 @@ sh_test( | |||
tags = ["no_windows"], | |||
) | |||
|
|||
sh_test( | |||
name = "tags_propagation_native_test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and also a test to CcBinaryConfiguredTargetTest, GenruleConfiguredTargetTest...)
@hlopko ok, I'll have a look at the tests and BuildViewTestCases :) What do you think about changes from RuleContext -> Rule and ActionCreationContext? |
Part of #8830
RELNOTES[NEW]: tags: use
--experimental_allow_tags_propagation
flag to propagate tags to the action's execution requirements from cc_library or cc_binary targets. Such tags should start with:no-
,requires-
,supports-
,block-
,disable-
,cpu:
. See #8830 for details.