Skip to content

Commit

Permalink
Revert change to Java implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jan 26, 2023
1 parent beaa799 commit 74b3c9f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,13 @@ public static NestedSet<Artifact> 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;
}
Expand Down Expand Up @@ -320,12 +314,10 @@ public static NestedSet<Artifact> 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(
Expand All @@ -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);
}

/**
Expand All @@ -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);
}
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> extraCompileArgs =
j2objcCompileWithARC(ruleContext)
? ImmutableList.of("-fno-strict-overflow", "-fobjc-arc-exceptions")
Expand Down

0 comments on commit 74b3c9f

Please sign in to comment.