From 74b3c9fd004bf9bd26e5b31a8ff93993563ecc67 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Thu, 26 Jan 2023 13:03:08 +0100 Subject: [PATCH] Revert change to Java implementation --- .../lib/rules/cpp/CcToolchainAliasRule.java | 11 +---- .../build/lib/rules/cpp/CppHelper.java | 43 ++++++------------- .../build/lib/rules/objc/J2ObjcAspect.java | 2 +- 3 files changed, 15 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainAliasRule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainAliasRule.java index 96dbb3edfaddf5..5fb5f9bd794fd9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainAliasRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainAliasRule.java @@ -32,8 +32,6 @@ import com.google.devtools.build.lib.analysis.RunfilesProvider; import com.google.devtools.build.lib.analysis.TemplateVariableInfo; import com.google.devtools.build.lib.analysis.platform.ToolchainInfo; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.Type; import javax.annotation.Nullable; @@ -76,14 +74,7 @@ public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException, ActionConflictException { CcToolchainProvider ccToolchainProvider = - CppHelper.getToolchainUsingDefaultCcToolchainAttribute(ruleContext, - ruleContext.attributes().get("mandatory", Type.BOOLEAN)); - if (ccToolchainProvider == null) { - return new RuleConfiguredTargetBuilder(ruleContext) - .addProvider(RunfilesProvider.simple(Runfiles.EMPTY)) - .setFilesToBuild(NestedSetBuilder.emptySet(Order.STABLE_ORDER)) - .build(); - } + CppHelper.getToolchainUsingDefaultCcToolchainAttribute(ruleContext); TemplateVariableInfo templateVariableInfo = CcToolchain.createMakeVariableProvider( diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java index 330bf0202e3267..403237ce4a044c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java @@ -243,19 +243,13 @@ public static NestedSet getGcovFilesIfNeeded( @Nullable public static CcToolchainProvider getToolchainUsingDefaultCcToolchainAttribute( RuleContext ruleContext) throws RuleErrorException { - return getToolchainUsingDefaultCcToolchainAttribute(ruleContext, true); - } - - @Nullable - public static CcToolchainProvider getToolchainUsingDefaultCcToolchainAttribute( - RuleContext ruleContext, boolean mandatory) throws RuleErrorException { if (ruleContext.attributes().has(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME)) { - return getToolchain(ruleContext, CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, mandatory); + return getToolchain(ruleContext, CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME); } else if (ruleContext .attributes() .has(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME_FOR_STARLARK)) { return getToolchain( - ruleContext, CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME_FOR_STARLARK, mandatory); + ruleContext, CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME_FOR_STARLARK); } return null; } @@ -320,12 +314,10 @@ public static NestedSet getDefaultCcToolchainStaticRuntimeInputs( /** * Makes sure that the given info collection has a {@link CcToolchainProvider} (gives an error - * otherwise), and returns a reference to that {@link CcToolchainProvider}. May return - * {@code null} if {@code mandatory} is {@code false}. + * otherwise), and returns a reference to that {@link CcToolchainProvider}. */ - @Nullable - public static CcToolchainProvider getToolchain(RuleContext ruleContext, String toolchainAttribute, - boolean mandatory) throws RuleErrorException { + public static CcToolchainProvider getToolchain(RuleContext ruleContext, String toolchainAttribute) + throws RuleErrorException { if (!ruleContext.isAttrDefined(toolchainAttribute, LABEL)) { throw ruleContext.throwWithRuleError( String.format( @@ -334,7 +326,7 @@ public static CcToolchainProvider getToolchain(RuleContext ruleContext, String t toolchainAttribute)); } TransitiveInfoCollection dep = ruleContext.getPrerequisite(toolchainAttribute); - return getToolchain(ruleContext, dep, mandatory); + return getToolchain(ruleContext, dep); } /** @@ -344,21 +336,15 @@ public static CcToolchainProvider getToolchain(RuleContext ruleContext, String t */ public static CcToolchainProvider getToolchain( RuleContext ruleContext, TransitiveInfoCollection dep) throws RuleErrorException { - return getToolchain(ruleContext, dep, true); - } - - public static CcToolchainProvider getToolchain( - RuleContext ruleContext, TransitiveInfoCollection dep, boolean mandatory) - throws RuleErrorException { Label toolchainType = getToolchainTypeFromRuleClass(ruleContext); - return getToolchain(ruleContext, dep, toolchainType, mandatory); + return getToolchain(ruleContext, dep, toolchainType); } public static CcToolchainProvider getToolchain( - RuleContext ruleContext, TransitiveInfoCollection dep, Label toolchainType, boolean mandatory) + RuleContext ruleContext, TransitiveInfoCollection dep, Label toolchainType) throws RuleErrorException { if (toolchainType != null && useToolchainResolution(ruleContext)) { - return getToolchainFromPlatformConstraints(ruleContext, toolchainType, mandatory); + return getToolchainFromPlatformConstraints(ruleContext, toolchainType); } return getToolchainFromLegacyToolchain(ruleContext, dep); } @@ -380,15 +366,12 @@ public static Label getToolchainTypeFromRuleClass(RuleContext ruleContext) { } private static CcToolchainProvider getToolchainFromPlatformConstraints( - RuleContext ruleContext, Label toolchainType, boolean mandatory) throws RuleErrorException { + RuleContext ruleContext, Label toolchainType) throws RuleErrorException { ToolchainInfo toolchainInfo = ruleContext.getToolchainInfo(toolchainType); if (toolchainInfo == null) { - if (mandatory) { - throw ruleContext.throwWithRuleError( - "Unable to find a CC toolchain using toolchain resolution. Did you properly set" - + " --platforms?"); - } - return null; + throw ruleContext.throwWithRuleError( + "Unable to find a CC toolchain using toolchain resolution. Did you properly set" + + " --platforms?"); } try { return (CcToolchainProvider) toolchainInfo.getValue("cc"); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java index 3a1376b8d60477..e8a838804ae87c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java @@ -303,7 +303,7 @@ private ConfiguredAspect buildAspect( try { CcToolchainProvider ccToolchain = - CppHelper.getToolchain(ruleContext, ":j2objc_cc_toolchain", /*mandatory*/true); + CppHelper.getToolchain(ruleContext, ":j2objc_cc_toolchain"); ImmutableList extraCompileArgs = j2objcCompileWithARC(ruleContext) ? ImmutableList.of("-fno-strict-overflow", "-fobjc-arc-exceptions")