diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java index f73e7234837fae..d4e3e0d9740b10 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java @@ -125,6 +125,10 @@ public final class RuleContext extends TargetContext implements ActionConstructionContext, ActionRegistry, RuleErrorConsumer { + public boolean isAllowTagsPropagation() throws InterruptedException { + return this.getAnalysisEnvironment().getSkylarkSemantics().experimentalAllowTagsPropagation(); + } + /** * The configured version of FilesetEntry. */ diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcModule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcModule.java index 88e4c2668f384c..8f055601225891 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcModule.java @@ -84,7 +84,7 @@ public Tuple compile( boolean disallowNopicOutputs, Location location, Environment environment) - throws EvalException { + throws EvalException, InterruptedException { return compile( skylarkActionFactoryApi, skylarkFeatureConfiguration, diff --git a/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java b/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java index b60aacaa9bf68f..82f220adf08410 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java +++ b/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java @@ -234,6 +234,24 @@ public static Map getExecutionInfo(Rule rule) { return ImmutableMap.copyOf(map); } + /** + * Returns the execution info from the tags declared on the target. These include only some tags + * {@link #legalExecInfoKeys} as keys with empty values. + * + * @param rule a rule instance to get tags from + * @param allowTagsPropagation if set to true, tags will be propagated from a target to the + * actions' execution requirements, for more details {@see + * SkylarkSematicOptions#experimentalAllowTagsPropagation} + */ + public static ImmutableMap getExecutionInfo( + Rule rule, boolean allowTagsPropagation) { + if (allowTagsPropagation) { + return ImmutableMap.copyOf(getExecutionInfo(rule)); + } else { + return ImmutableMap.of(); + } + } + /** * Returns the execution info, obtained from the rule's tags and the execution requirements * provided. Only supported tags are included into the execution info, see {@link diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java index 564dd7e5680e81..306b83e9743bd1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java @@ -352,7 +352,9 @@ public static ConfiguredTarget init(CppSemantics semantics, RuleContext ruleCont semantics, featureConfiguration, ccToolchain, - fdoContext) + fdoContext, + TargetUtils.getExecutionInfo( + ruleContext.getRule(), ruleContext.isAllowTagsPropagation())) .fromCommon(common, /* additionalCopts= */ ImmutableList.of()) .addPrivateHeaders(common.getPrivateHeaders()) .addSources(common.getSources()) @@ -408,7 +410,9 @@ public static ConfiguredTarget init(CppSemantics semantics, RuleContext ruleCont fdoContext, ruleContext.getConfiguration(), cppConfiguration, - ruleContext.getSymbolGenerator()) + ruleContext.getSymbolGenerator(), + TargetUtils.getExecutionInfo( + ruleContext.getRule(), ruleContext.isAllowTagsPropagation())) .fromCommon(ruleContext, common) .setGrepIncludes(CppHelper.getGrepIncludes(ruleContext)) .setIsStampingEnabled(AnalysisUtils.isStampingEnabled(ruleContext)) @@ -714,7 +718,9 @@ public static Pair createTransitiveLinkingActi fdoContext, ruleContext.getConfiguration(), cppConfiguration, - ruleContext.getSymbolGenerator()) + ruleContext.getSymbolGenerator(), + TargetUtils.getExecutionInfo( + ruleContext.getRule(), ruleContext.isAllowTagsPropagation())) .setGrepIncludes(CppHelper.getGrepIncludes(ruleContext)) .setIsStampingEnabled(AnalysisUtils.isStampingEnabled(ruleContext)) .setTestOrTestOnlyTarget(ruleContext.isTestTarget() || ruleContext.isTestOnlyTarget()) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java index c281f6ea9c2f31..c96298c78da752 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java @@ -222,6 +222,7 @@ public CcCompilationContext getCcCompilationContext() { private final CppSemantics semantics; private final BuildConfiguration configuration; + private final ImmutableMap executionInfo; private final CppConfiguration cppConfiguration; private final List publicHeaders = new ArrayList<>(); @@ -285,7 +286,8 @@ public CcCompilationHelper( SourceCategory sourceCategory, CcToolchainProvider ccToolchain, FdoContext fdoContext, - BuildConfiguration buildConfiguration) { + BuildConfiguration buildConfiguration, + ImmutableMap executionInfo) { this.semantics = Preconditions.checkNotNull(semantics); this.featureConfiguration = Preconditions.checkNotNull(featureConfiguration); this.sourceCategory = Preconditions.checkNotNull(sourceCategory); @@ -304,6 +306,7 @@ public CcCompilationHelper( this.actionRegistry = Preconditions.checkNotNull(actionRegistry); this.label = Preconditions.checkNotNull(label); this.grepIncludes = grepIncludes; + this.executionInfo = Preconditions.checkNotNull(executionInfo); } /** Creates a CcCompilationHelper for cpp source files. */ @@ -315,7 +318,8 @@ public CcCompilationHelper( CppSemantics semantics, FeatureConfiguration featureConfiguration, CcToolchainProvider ccToolchain, - FdoContext fdoContext) { + FdoContext fdoContext, + ImmutableMap executionInfo) { this( actionRegistry, actionConstructionContext, @@ -326,7 +330,8 @@ public CcCompilationHelper( SourceCategory.CC, ccToolchain, fdoContext, - actionConstructionContext.getConfiguration()); + actionConstructionContext.getConfiguration(), + executionInfo); } /** Sets fields that overlap for cc_library and cc_binary rules. */ @@ -1548,6 +1553,7 @@ private CppCompileActionBuilder initializeCompileAction(Artifact sourceArtifact) builder.setCcCompilationContext(ccCompilationContext); builder.setCoptsFilter(coptsFilter); builder.setFeatureConfiguration(featureConfiguration); + builder.addExecutionInfo(executionInfo); return builder; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java index 82a549c2651c03..54728b790161d0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; +import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper.CompilationInfo; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; import com.google.devtools.build.lib.rules.cpp.CppConfiguration.HeadersCheckingMode; @@ -160,7 +161,9 @@ public ConfiguredTarget create(RuleContext ruleContext) semantics, featureConfiguration, ccToolchain, - ccToolchain.getFdoContext()) + ccToolchain.getFdoContext(), + TargetUtils.getExecutionInfo( + ruleContext.getRule(), ruleContext.isAllowTagsPropagation())) .addPublicHeaders(common.getHeaders()) .setHeadersCheckingMode(HeadersCheckingMode.STRICT) .setCodeCoverageEnabled(CcCompilationHelper.isCodeCoverageEnabled(ruleContext)) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java index 42d9f9e7cda66e..8adf9c59ee5be8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java @@ -43,6 +43,7 @@ import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.ImplicitOutputsFunction; import com.google.devtools.build.lib.packages.RawAttributeMapper; +import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.rules.cpp.CcCommon.CcFlagsSupplier; import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper.CompilationInfo; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; @@ -157,7 +158,9 @@ public static void init( semantics, featureConfiguration, ccToolchain, - fdoContext) + fdoContext, + TargetUtils.getExecutionInfo( + ruleContext.getRule(), ruleContext.isAllowTagsPropagation())) .fromCommon(common, additionalCopts) .addSources(common.getSources()) .addPrivateHeaders(common.getPrivateHeaders()) @@ -183,7 +186,9 @@ public static void init( fdoContext, ruleContext.getConfiguration(), ruleContext.getFragment(CppConfiguration.class), - ruleContext.getSymbolGenerator()) + ruleContext.getSymbolGenerator(), + TargetUtils.getExecutionInfo( + ruleContext.getRule(), ruleContext.isAllowTagsPropagation())) .fromCommon(ruleContext, common) .setGrepIncludes(CppHelper.getGrepIncludes(ruleContext)) .setTestOrTestOnlyTarget(ruleContext.isTestOnlyTarget()) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java index 65900b0ba7fe22..e13f605d95f0f9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java @@ -18,6 +18,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.ActionRegistry; import com.google.devtools.build.lib.actions.Artifact; @@ -124,6 +125,7 @@ public CcLinkingOutputs getCcLinkingOutputs() { private final ActionRegistry actionRegistry; private final RuleErrorConsumer ruleErrorConsumer; private final SymbolGenerator symbolGenerator; + private final ImmutableMap executionInfo; private Artifact grepIncludes; private boolean isStampingEnabled; @@ -141,6 +143,7 @@ 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 executionInfo the execution info data associated with a rule */ public CcLinkingHelper( RuleErrorConsumer ruleErrorConsumer, @@ -153,7 +156,8 @@ public CcLinkingHelper( FdoContext fdoContext, BuildConfiguration configuration, CppConfiguration cppConfiguration, - SymbolGenerator symbolGenerator) { + SymbolGenerator symbolGenerator, + ImmutableMap executionInfo) { this.semantics = Preconditions.checkNotNull(semantics); this.featureConfiguration = Preconditions.checkNotNull(featureConfiguration); this.ccToolchain = Preconditions.checkNotNull(ccToolchain); @@ -165,6 +169,7 @@ public CcLinkingHelper( this.actionRegistry = actionRegistry; this.actionConstructionContext = actionConstructionContext; this.symbolGenerator = symbolGenerator; + this.executionInfo = executionInfo; } /** Sets fields that overlap for cc_library and cc_binary rules. */ @@ -837,7 +842,8 @@ private CppLinkActionBuilder newLinkActionBuilder( ? ccToolchain.getArFiles() : ccToolchain.getLinkerFiles()) .setLinkArtifactFactory(linkArtifactFactory) - .setUseTestOnlyFlags(useTestOnlyFlags); + .setUseTestOnlyFlags(useTestOnlyFlags) + .addExecutionInfo(executionInfo); } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java index 678133cd661125..15118410ab7758 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java @@ -37,6 +37,7 @@ import com.google.devtools.build.lib.packages.Provider; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; import com.google.devtools.build.lib.packages.SkylarkInfo; +import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper.CompilationInfo; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ActionConfig; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ArtifactNamePattern; @@ -1432,7 +1433,10 @@ public Tuple createLinkingContextFromCompilationOutputs( .getActionConstructionContext() .getConfiguration() .getFragment(CppConfiguration.class), - ((BazelStarlarkContext) starlarkContext).getSymbolGenerator()) + ((BazelStarlarkContext) starlarkContext).getSymbolGenerator(), + TargetUtils.getExecutionInfo( + actions.getRuleContext().getRule(), + actions.getRuleContext().isAllowTagsPropagation())) .setGrepIncludes(convertFromNoneable(grepIncludes, /* defaultValue= */ null)) .addNonCodeLinkerInputs(additionalInputs) .setShouldCreateStaticLibraries(!disallowStaticLibraries) @@ -1527,7 +1531,7 @@ protected Tuple compile( SkylarkList headersForClifDoNotUseThisParam, Location location, @Nullable Environment environment) - throws EvalException { + throws EvalException, InterruptedException { if (environment != null) { CcCommon.checkLocationWhitelisted( environment.getSemantics(), @@ -1572,7 +1576,10 @@ protected Tuple compile( getSemantics(), featureConfiguration.getFeatureConfiguration(), ccToolchainProvider, - fdoContext) + fdoContext, + TargetUtils.getExecutionInfo( + actions.getRuleContext().getRule(), + actions.getRuleContext().isAllowTagsPropagation())) .addPublicHeaders(publicHeaders) .addPrivateHeaders(privateHeaders) .addSources(sources) @@ -1680,7 +1687,10 @@ protected CcLinkingOutputs link( fdoContext, actions.getActionConstructionContext().getConfiguration(), cppConfiguration, - ((BazelStarlarkContext) starlarkContext).getSymbolGenerator()) + ((BazelStarlarkContext) starlarkContext).getSymbolGenerator(), + TargetUtils.getExecutionInfo( + actions.getRuleContext().getRule(), + actions.getRuleContext().isAllowTagsPropagation())) .setGrepIncludes(convertFromNoneable(grepIncludes, /* defaultValue= */ null)) .setLinkingMode(linkDepsStatically ? LinkingMode.STATIC : LinkingMode.DYNAMIC) .addNonCodeLinkerInputs(additionalInputs) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java index 276545d99929f8..d3f53afb179d49 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java @@ -148,6 +148,7 @@ public Artifact create( // of them. private boolean isTestOrTestOnlyTarget; private boolean isStampingEnabled; + private final Map executionInfo = new LinkedHashMap<>(); /** * Creates a builder that builds {@link CppLinkAction}s. @@ -1022,15 +1023,14 @@ 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 executionRequirements = new LinkedHashMap<>(); if (featureConfiguration.actionIsConfigured(getActionName())) { for (String req : featureConfiguration.getToolRequirementsForAction(getActionName())) { - executionRequirements.put(req, ""); + executionInfo.put(req, ""); } } configuration.modifyExecutionInfo( - executionRequirements, CppLinkAction.getMnemonic(mnemonic, isLtoIndexing)); + executionInfo, CppLinkAction.getMnemonic(mnemonic, isLtoIndexing)); if (!isLtoIndexing) { for (Map.Entry linkstampEntry : linkstampMap.entrySet()) { @@ -1092,7 +1092,7 @@ public CppLinkAction build() throws InterruptedException, RuleErrorException { linkCommandLine, configuration.getActionEnvironment(), toolchainEnv, - ImmutableMap.copyOf(executionRequirements), + ImmutableMap.copyOf(executionInfo), toolchain.getToolPathFragment(Tool.LD, ruleErrorConsumer), toolchain.getHostSystemName(), toolchain.getTargetCpu()); @@ -1582,4 +1582,9 @@ public CppLinkActionBuilder addActionOutput(Artifact output) { this.linkActionOutputs.add(output); return this; } + + public CppLinkActionBuilder addExecutionInfo(Map executionInfo) { + this.executionInfo.putAll(executionInfo); + return this; + } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java index 9d0bbd8ac69ac1..9f0ddea8559b7e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java @@ -41,6 +41,7 @@ import com.google.devtools.build.lib.packages.Attribute.LabelLateBoundDefault; import com.google.devtools.build.lib.packages.NativeAspectClass; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; +import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.rules.cpp.AspectLegalCppSemantics; import com.google.devtools.build.lib.rules.cpp.CcCommon; import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper; @@ -300,7 +301,8 @@ private FeatureConfiguration getFeatureConfiguration() { } private CcCompilationHelper initializeCompilationHelper( - FeatureConfiguration featureConfiguration, List deps) { + FeatureConfiguration featureConfiguration, List deps) + throws InterruptedException { CcToolchainProvider toolchain = ccToolchain(ruleContext); CcCompilationHelper helper = new CcCompilationHelper( @@ -311,7 +313,9 @@ private CcCompilationHelper initializeCompilationHelper( cppSemantics, featureConfiguration, toolchain, - toolchain.getFdoContext()) + toolchain.getFdoContext(), + TargetUtils.getExecutionInfo( + ruleContext.getRule(), ruleContext.isAllowTagsPropagation())) .addCcCompilationContexts(CppHelper.getCompilationContextsFromDeps(deps)) .addCcCompilationContexts( ImmutableList.of(CcCompilationHelper.getStlCcCompilationContext(ruleContext))); @@ -344,7 +348,8 @@ private CcCompilationHelper initializeCompilationHelper( } private CcLinkingHelper initializeLinkingHelper( - FeatureConfiguration featureConfiguration, ImmutableList deps) { + FeatureConfiguration featureConfiguration, ImmutableList deps) + throws InterruptedException { CcToolchainProvider toolchain = ccToolchain(ruleContext); CcLinkingHelper helper = new CcLinkingHelper( @@ -358,7 +363,9 @@ private CcLinkingHelper initializeLinkingHelper( toolchain.getFdoContext(), ruleContext.getConfiguration(), ruleContext.getFragment(CppConfiguration.class), - ruleContext.getSymbolGenerator()) + ruleContext.getSymbolGenerator(), + TargetUtils.getExecutionInfo( + ruleContext.getRule(), ruleContext.isAllowTagsPropagation())) .setGrepIncludes(CppHelper.getGrepIncludes(ruleContext)) .setTestOrTestOnlyTarget(ruleContext.isTestOnlyTarget()); helper.addCcLinkingContexts(CppHelper.getLinkingContextsFromDeps(deps)); diff --git a/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java b/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java index 9d8d07533b823f..0e154f3a548111 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; +import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.rules.cpp.CcCommon; import com.google.devtools.build.lib.rules.cpp.CcCompilationOutputs; import com.google.devtools.build.lib.rules.cpp.CcInfo; @@ -247,7 +248,9 @@ public static NativeDepsRunfiles createNativeDepsAction( fdoContext, configuration, ruleContext.getFragment(CppConfiguration.class), - ruleContext.getSymbolGenerator()) + ruleContext.getSymbolGenerator(), + TargetUtils.getExecutionInfo( + ruleContext.getRule(), ruleContext.isAllowTagsPropagation())) .setGrepIncludes(CppHelper.getGrepIncludes(ruleContext)) .setIsStampingEnabled(AnalysisUtils.isStampingEnabled(ruleContext)) .setTestOrTestOnlyTarget(ruleContext.isTestTarget() || ruleContext.isTestOnlyTarget()) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java index c18335e6ee1504..d74fb513d7ac62 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java @@ -85,6 +85,7 @@ import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; +import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions.AppleBitcodeMode; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.XcodeConfig; @@ -292,7 +293,7 @@ private CompilationInfo compile( ObjcCppSemantics semantics, String purpose, boolean generateModuleMap) - throws RuleErrorException { + throws RuleErrorException, InterruptedException { CcCompilationHelper result = new CcCompilationHelper( ruleContext, @@ -304,7 +305,9 @@ private CompilationInfo compile( CcCompilationHelper.SourceCategory.CC_AND_OBJC, ccToolchain, fdoContext, - buildConfiguration) + buildConfiguration, + TargetUtils.getExecutionInfo( + ruleContext.getRule(), ruleContext.isAllowTagsPropagation())) .addSources(sources) .addPrivateHeaders(privateHdrs) .addDefines(objcProvider.get(DEFINE)) @@ -424,7 +427,9 @@ private Pair>> cc fdoContext, buildConfiguration, ruleContext.getFragment(CppConfiguration.class), - ruleContext.getSymbolGenerator()) + ruleContext.getSymbolGenerator(), + TargetUtils.getExecutionInfo( + ruleContext.getRule(), ruleContext.isAllowTagsPropagation())) .setGrepIncludes(CppHelper.getGrepIncludes(ruleContext)) .setIsStampingEnabled(AnalysisUtils.isStampingEnabled(ruleContext)) .setTestOrTestOnlyTarget(ruleContext.isTestTarget() || ruleContext.isTestOnlyTarget()) @@ -791,7 +796,6 @@ public static class Builder { private BuildConfiguration buildConfiguration; private IntermediateArtifacts intermediateArtifacts; private CompilationAttributes compilationAttributes; - private boolean useDeps = true; private Map> outputGroupCollector; private ImmutableList.Builder objectFilesCollector; private CcToolchainProvider toolchain; diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index 796e1fd0564101..d0a8d02948c10e 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -767,6 +767,14 @@ sh_test( tags = ["no_windows"], ) +sh_test( + name = "tags_propagation_native_test", + size = "large", + srcs = ["tags_propagation_native_test.sh"], + data = [":test-deps"], + tags = ["no_windows"], +) + sh_test( name = "disk_cache_test", size = "small", diff --git a/src/test/shell/bazel/tags_propagation_native_test.sh b/src/test/shell/bazel/tags_propagation_native_test.sh new file mode 100755 index 00000000000000..7ffee2fab58800 --- /dev/null +++ b/src/test/shell/bazel/tags_propagation_native_test.sh @@ -0,0 +1,196 @@ +#!/bin/bash +# +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Tests target's tags propagation with rules defined in Skylark. +# Tests for https://github.com/bazelbuild/bazel/issues/7766 + +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + +PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" + +# Test a basic native rule which has tags, that should be propagated +function test_cc_library_tags_propagated() { + mkdir -p test + cat > test/BUILD < test/test.cc < +int main() { std::cout << "Hello test!" << std::endl; return 0; } +EOF + + bazel aquery --experimental_allow_tags_propagation 'mnemonic("CppCompile", //test:test)' > output1 2> $TEST_log \ + || fail "should have generated output successfully" + + assert_contains "ExecutionInfo: {" output1 + assert_contains "local:" output1 + assert_contains "no-cache:" output1 + assert_contains "no-remote:" output1 + + bazel aquery --experimental_allow_tags_propagation 'mnemonic("CppLink", outputs(".*/libtest.a", //test:test))' > output1 2> $TEST_log \ + || fail "should have generated output successfully" + + assert_contains "ExecutionInfo: {" output1 + assert_contains "local:" output1 + assert_contains "no-cache:" output1 + assert_contains "no-remote:" output1 + + bazel aquery --experimental_allow_tags_propagation 'mnemonic("CppLink", outputs(".*/libtest.so", //test:test))' > output1 2> $TEST_log \ + || fail "should have generated output successfully" + + assert_contains "ExecutionInfo: {" output1 + assert_contains "local:" output1 + assert_contains "no-cache:" output1 + assert_contains "no-remote:" output1 +} + +function test_cc_binary_tags_propagated() { + + mkdir -p test + cat > test/BUILD < test/test.cc < +int main() { std::cout << "Hello test!" << std::endl; return 0; } +EOF + + bazel aquery --experimental_allow_tags_propagation 'mnemonic("CppCompile", //test:test)' > output1 2> $TEST_log \ + || fail "should have generated output successfully" + + assert_contains "ExecutionInfo: {" output1 + assert_contains "local:" output1 + assert_contains "no-cache:" output1 + assert_contains "no-remote:" output1 + + bazel aquery --experimental_allow_tags_propagation 'mnemonic("CppLink", //test:test)' > output1 2> $TEST_log \ + || fail "should have generated output successfully" + + assert_contains "ExecutionInfo: {" output1 + assert_contains "local:" output1 + assert_contains "no-cache:" output1 + assert_contains "no-remote:" output1 +} + +function test_genrule_tags_propagated() { + mkdir -p test + cat > test/BUILD < output1 2> $TEST_log \ + || fail "should have generated output successfully" + + assert_contains "ExecutionInfo: {" output1 + assert_contains "local:" output1 + assert_contains "no-cache:" output1 + assert_contains "no-remote:" output1 +} + +# Test a native test rule rule which has tags, that should be propagated (independent of flags) +function test_test_rules_tags_propagated() { + mkdir -p test + cat > test/BUILD < test/test.cc < +int main() { std::cout << "Hello test!" << std::endl; return 0; } +EOF + + bazel aquery --experimental_allow_tags_propagation=false '//test:test' > output1 2> $TEST_log \ + || fail "should have generated output successfully" + + assert_contains "ExecutionInfo: {" output1 + assert_contains "local:" output1 + assert_contains "no-cache:" output1 + assert_contains "no-remote:" output1 +} + +# Test a basic native rule which has tags, that should not be propagated +# as --experimental_allow_tags_propagation flag set to false +function test_cc_library_tags_not_propagated_when_incompatible_flag_off() { + mkdir -p test + cat > test/BUILD < test/test.cc < +int main() { std::cout << "Hello test!" << std::endl; return 0; } +EOF + + bazel aquery --experimental_allow_tags_propagation=false '//test:test' > output1 2> $TEST_log \ + || fail "should have generated output successfully" + + assert_not_contains "local:" output1 + assert_not_contains "no-cache:" output1 + assert_not_contains "no-remote:" output1 +} + +function test_cc_binary_tags_not_propagated_when_incompatible_flag_off() { + + mkdir -p test + cat > test/BUILD < test/test.cc < +int main() { std::cout << "Hello test!" << std::endl; return 0; } +EOF + + bazel aquery --experimental_allow_tags_propagation=false '//test:test' > output1 2> $TEST_log \ + || fail "should have generated output successfully" + + assert_not_contains "local:" output1 + assert_not_contains "no-cache:" output1 + assert_not_contains "no-remote:" output1 +} + +run_suite "tags propagation: skylark rule tests"