Skip to content

Commit

Permalink
Make the Starlark executable paths explicitly part of the CcToolchain…
Browse files Browse the repository at this point in the history
…Provider API.

They were previously added by the ToolchainInfo machinery, but that is being removed.

Bazel CI: Downstream tests pass https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/1898 (all failures are the same as the previous nightly).

PiperOrigin-RevId: 355837590
  • Loading branch information
katre authored and copybara-github committed Feb 5, 2021
1 parent d202bd5 commit 540623f
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import net.starlark.java.eval.EvalException;
import net.starlark.java.eval.Starlark;
import net.starlark.java.eval.StarlarkThread;
import net.starlark.java.syntax.Location;

/** Information about a C++ compiler used by the <code>cc_*</code> rules. */
@Immutable
Expand Down Expand Up @@ -109,7 +108,16 @@ public final class CcToolchainProvider extends ToolchainInfo
/* additionalMakeVariables= */ ImmutableMap.of(),
/* legacyCcFlagsMakeVariable= */ "",
/* allowlistForLayeringCheck= */ null,
/* allowListForLooseHeaderCheck= */ null);
/* allowListForLooseHeaderCheck= */ null,
/* objcopyExecutable= */ "",
/* compilerExecutable= */ "",
/* preprocessorExecutable= */ "",
/* nmExecutable= */ "",
/* objdumpExecutable= */ "",
/* arExecutable= */ "",
/* stripExecutable= */ "",
/* ldExecutable= */ "",
/* gcovExecutable= */ "");

@Nullable private final CppConfiguration cppConfiguration;
private final PathFragment crosstoolTopPathFragment;
Expand Down Expand Up @@ -174,6 +182,16 @@ public final class CcToolchainProvider extends ToolchainInfo
private final PackageSpecificationProvider allowlistForLayeringCheck;
private final PackageSpecificationProvider allowListForLooseHeaderCheck;

private final String objcopyExecutable;
private final String compilerExecutable;
private final String preprocessorExecutable;
private final String nmExecutable;
private final String objdumpExecutable;
private final String arExecutable;
private final String stripExecutable;
private final String ldExecutable;
private final String gcovExecutable;

public CcToolchainProvider(
ImmutableMap<String, Object> values,
@Nullable CppConfiguration cppConfiguration,
Expand Down Expand Up @@ -229,8 +247,17 @@ public CcToolchainProvider(
ImmutableMap<String, String> additionalMakeVariables,
String legacyCcFlagsMakeVariable,
PackageSpecificationProvider allowlistForLayeringCheck,
PackageSpecificationProvider allowListForLooseHeaderCheck) {
super(values, Location.BUILTIN);
PackageSpecificationProvider allowListForLooseHeaderCheck,
String objcopyExecutable,
String compilerExecutable,
String preprocessorExecutable,
String nmExecutable,
String objdumpExecutable,
String arExecutable,
String stripExecutable,
String ldExecutable,
String gcovExecutable) {
super(values);
this.cppConfiguration = cppConfiguration;
this.crosstoolTopPathFragment = crosstoolTopPathFragment;
this.allFiles = Preconditions.checkNotNull(allFiles);
Expand Down Expand Up @@ -288,6 +315,16 @@ public CcToolchainProvider(
this.legacyCcFlagsMakeVariable = legacyCcFlagsMakeVariable;
this.allowlistForLayeringCheck = allowlistForLayeringCheck;
this.allowListForLooseHeaderCheck = allowListForLooseHeaderCheck;

this.objcopyExecutable = objcopyExecutable;
this.compilerExecutable = compilerExecutable;
this.preprocessorExecutable = preprocessorExecutable;
this.nmExecutable = nmExecutable;
this.objdumpExecutable = objdumpExecutable;
this.arExecutable = arExecutable;
this.stripExecutable = stripExecutable;
this.ldExecutable = ldExecutable;
this.gcovExecutable = gcovExecutable;
}

/**
Expand Down Expand Up @@ -901,6 +938,51 @@ public FdoContext getFdoContextForStarlark(StarlarkThread thread) throws EvalExc
return fdoContext;
}

@Override
public String objcopyExecutable() {
return objcopyExecutable;
}

@Override
public String compilerExecutable() {
return compilerExecutable;
}

@Override
public String preprocessorExecutable() {
return preprocessorExecutable;
}

@Override
public String nmExecutable() {
return nmExecutable;
}

@Override
public String objdumpExecutable() {
return objdumpExecutable;
}

@Override
public String arExecutable() {
return arExecutable;
}

@Override
public String stripExecutable() {
return stripExecutable;
}

@Override
public String ldExecutable() {
return ldExecutable;
}

@Override
public String gcovExecutable() {
return gcovExecutable;
}

/**
* Unused, for compatibility with things internal to Google.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static CcToolchainProvider getCcToolchainProvider(
attributes.getAllowlistForLooseHeaderCheck();

return new CcToolchainProvider(
getToolchainForStarlark(toolPaths),
/* values= */ ImmutableMap.of(),
cppConfiguration,
toolchainFeatures,
toolsDirectory,
Expand Down Expand Up @@ -251,7 +251,16 @@ public static CcToolchainProvider getCcToolchainProvider(
computeAdditionalMakeVariables(toolchainConfigInfo),
computeLegacyCcFlagsMakeVariable(toolchainConfigInfo),
allowlistForLayeringCheck,
allowlistForLooseHeaderCheck);
allowlistForLooseHeaderCheck,
getStarlarkValueForTool(Tool.OBJCOPY, toolPaths),
getStarlarkValueForTool(Tool.GCC, toolPaths),
getStarlarkValueForTool(Tool.CPP, toolPaths),
getStarlarkValueForTool(Tool.NM, toolPaths),
getStarlarkValueForTool(Tool.OBJDUMP, toolPaths),
getStarlarkValueForTool(Tool.AR, toolPaths),
getStarlarkValueForTool(Tool.STRIP, toolPaths),
getStarlarkValueForTool(Tool.LD, toolPaths),
getStarlarkValueForTool(Tool.GCOV, toolPaths));
}

@Nullable
Expand Down Expand Up @@ -383,21 +392,6 @@ private static String getStarlarkValueForTool(
return toolPath != null ? toolPath.getPathString() : "";
}

private static ImmutableMap<String, Object> getToolchainForStarlark(
ImmutableMap<String, PathFragment> toolPaths) {
return ImmutableMap.<String, Object>builder()
.put("objcopy_executable", getStarlarkValueForTool(Tool.OBJCOPY, toolPaths))
.put("compiler_executable", getStarlarkValueForTool(Tool.GCC, toolPaths))
.put("preprocessor_executable", getStarlarkValueForTool(Tool.CPP, toolPaths))
.put("nm_executable", getStarlarkValueForTool(Tool.NM, toolPaths))
.put("objdump_executable", getStarlarkValueForTool(Tool.OBJDUMP, toolPaths))
.put("ar_executable", getStarlarkValueForTool(Tool.AR, toolPaths))
.put("strip_executable", getStarlarkValueForTool(Tool.STRIP, toolPaths))
.put("ld_executable", getStarlarkValueForTool(Tool.LD, toolPaths))
.put("gcov_executable", getStarlarkValueForTool(Tool.GCOV, toolPaths))
.build();
}

private static PathFragment calculateSysroot(Label libcTopLabel, PathFragment defaultSysroot) {
if (libcTopLabel == null) {
return defaultSysroot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,49 @@ String getToolPathStringOrNoneForStarlark(String tool, StarlarkThread thread)

@StarlarkMethod(name = "fdo_context", documented = false, useStarlarkThread = true)
FdoContextT getFdoContextForStarlark(StarlarkThread thread) throws EvalException;

@StarlarkMethod(
name = "objcopy_executable",
structField = true,
doc = "The path to the objcopy binary.")
String objcopyExecutable();

@StarlarkMethod(
name = "compiler_executable",
structField = true,
doc = "The path to the compiler binary.")
String compilerExecutable();

@StarlarkMethod(
name = "preprocessor_executable",
structField = true,
doc = "The path to the preprocessor binary.")
String preprocessorExecutable();

@StarlarkMethod(name = "nm_executable", structField = true, doc = "The path to the nm binary.")
String nmExecutable();

@StarlarkMethod(
name = "objdump_executable",
structField = true,
doc = "The path to the objdump binary.")
String objdumpExecutable();

@StarlarkMethod(name = "ar_executable", structField = true, doc = "The path to the ar binary.")
String arExecutable();

@StarlarkMethod(
name = "strip_executable",
structField = true,
doc = "The path to the strip binary.")
String stripExecutable();

@StarlarkMethod(name = "ld_executable", structField = true, doc = "The path to the ld binary.")
String ldExecutable();

@StarlarkMethod(
name = "gcov_executable",
structField = true,
doc = "The path to the gcov binary.")
String gcovExecutable();
}

0 comments on commit 540623f

Please sign in to comment.