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

propagated for cc_library and cc_binary #9267

Closed
wants to merge 10 commits into from

Conversation

ishikhman
Copy link
Contributor

@ishikhman ishikhman commented Aug 28, 2019

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.

@ishikhman ishikhman marked this pull request as ready for review August 28, 2019 16:08
@ishikhman ishikhman requested a review from hlopko as a code owner August 28, 2019 16:08
@ishikhman ishikhman requested a review from buchgr August 28, 2019 16:08
Copy link
Contributor

@buchgr buchgr left a 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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.*;
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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()))
}

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be final?

Copy link
Member

Choose a reason for hiding this comment

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

Nit: Use ImmutableMap.builder()

Copy link
Contributor Author

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<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

remove?

Copy link
Contributor Author

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",
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Member

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...)

Copy link
Contributor Author

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 :)

Copy link
Member

@hlopko hlopko Aug 29, 2019

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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: ''"

Copy link
Member

@hlopko hlopko left a 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();
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Contributor Author

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) {
Copy link
Member

Choose a reason for hiding this comment

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

Why nullable?

Copy link
Contributor Author

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)
Copy link
Member

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<>();
Copy link
Member

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",
Copy link
Member

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",
Copy link
Member

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...)

@ishikhman
Copy link
Contributor Author

@hlopko ok, I'll have a look at the tests and BuildViewTestCases :)

What do you think about changes from RuleContext -> Rule and ActionCreationContext?

@iirina iirina added the team-Remote-Exec Issues and PRs for the Execution (Remote) team label Aug 29, 2019
@bazel-io bazel-io closed this in 94c24b3 Aug 30, 2019
@ishikhman ishikhman mentioned this pull request Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes team-Remote-Exec Issues and PRs for the Execution (Remote) team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants