diff options
author | 2017-11-03 21:48:19 +0100 | |
---|---|---|
committer | 2017-11-06 20:20:18 +0100 | |
commit | bb65790003572d2b75147ee36e5afb5211bfdf8a (patch) | |
tree | baab48eccb0fd75c0663d6715ac9a1df3d100974 /src/main/java | |
parent | 8a49b156c4edf710e3e1e0acfde5a8d27cc3a086 (diff) |
Move CppConfiguration#getHostSystemName, #getTestOnlyLinkOptions, #getObjCopyOptionsForEmbedding, #getLdOptionsForEmbedding and #getDefaultSysroot to CcToolchainProvider.
PiperOrigin-RevId: 174508128
Diffstat (limited to 'src/main/java')
5 files changed, 51 insertions, 49 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java index 3fcf418d56..c22ee3eb66 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java @@ -381,7 +381,7 @@ public class CcToolchain implements RuleConfiguredTargetFactory { coverage = crosstool; } - PathFragment sysroot = calculateSysroot(ruleContext); + PathFragment sysroot = calculateSysroot(ruleContext, toolchainInfo.getDefaultSysroot()); ImmutableList<PathFragment> builtInIncludeDirectories = null; try { @@ -432,7 +432,7 @@ public class CcToolchain implements RuleConfiguredTargetFactory { context, supportsParamFiles, supportsHeaderParsing, - getBuildVariables(ruleContext), + getBuildVariables(ruleContext, toolchainInfo.getDefaultSysroot()), getBuiltinIncludes(ruleContext), coverageEnvironment.build(), cppConfiguration.supportsInterfaceSharedObjects() @@ -642,13 +642,15 @@ public class CcToolchain implements RuleConfiguredTargetFactory { * Returns {@link Variables} instance with build variables that only depend on the toolchain. * * @param ruleContext the rule context + * @param defaultSysroot the default sysroot * @throws RuleErrorException if there are configuration errors making it impossible to resolve * certain build variables of this toolchain */ - private final Variables getBuildVariables(RuleContext ruleContext) throws RuleErrorException { + private final Variables getBuildVariables(RuleContext ruleContext, PathFragment defaultSysroot) + throws RuleErrorException { Variables.Builder variables = new Variables.Builder(); - PathFragment sysroot = calculateSysroot(ruleContext); + PathFragment sysroot = calculateSysroot(ruleContext, defaultSysroot); if (sysroot != null) { variables.addStringVariable(CppModel.SYSROOT_VARIABLE_NAME, sysroot.getPathString()); } @@ -660,7 +662,7 @@ public class CcToolchain implements RuleConfiguredTargetFactory { /** * Add local build variables from subclasses into {@link Variables} returned from {@link - * #getBuildVariables(RuleContext)}. + * #getBuildVariables(RuleContext, PathFragment)}. * * <p>This method is meant to be overridden by subclasses of CcToolchain. */ @@ -679,13 +681,11 @@ public class CcToolchain implements RuleConfiguredTargetFactory { return ImmutableMap.<String, String>of(); } - private PathFragment calculateSysroot(RuleContext ruleContext) { + private PathFragment calculateSysroot(RuleContext ruleContext, PathFragment defaultSysroot) { TransitiveInfoCollection sysrootTarget = ruleContext.getPrerequisite(":libc_top", Mode.TARGET); if (sysrootTarget == null) { - CppConfiguration cppConfiguration = - Preconditions.checkNotNull(ruleContext.getFragment(CppConfiguration.class)); - return cppConfiguration.getDefaultSysroot(); + return defaultSysroot; } return sysrootTarget.getLabel().getPackageFragment(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java index 30ef49edb0..31bfbd4e69 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java @@ -506,6 +506,44 @@ public final class CcToolchainProvider extends ToolchainInfo { return cppConfiguration.getLinkOptionsDoNotUse(/* sysroot= */ null); } + /** + * Returns test-only link options such that certain test-specific features can be configured + * separately (e.g. lazy binding). + */ + public ImmutableList<String> getTestOnlyLinkOptions() { + return toolchainInfo.getTestOnlyLinkOptions(); + } + + /** Returns the system name which is required by the toolchain to run. */ + public String getHostSystemName() { + return toolchainInfo.getHostSystemName(); + } + + /** + * Returns the list of options to be used with 'objcopy' when converting binary files to object + * files, or {@code null} if this operation is not supported. + */ + public ImmutableList<String> getObjCopyOptionsForEmbedding() { + return toolchainInfo.getObjCopyOptionsForEmbedding(); + } + + /** + * Returns the list of options to be used with 'ld' when converting binary files to object files, + * or {@code null} if this operation is not supported. + */ + public ImmutableList<String> getLdOptionsForEmbedding() { + return toolchainInfo.getLdOptionsForEmbedding(); + } + + /** Returns the GNU System Name */ + @SkylarkCallable( + name = "target_gnu_system_name", + structField = true, + doc = "The GNU System Name." + ) + public String getTargetGnuSystemName() { + return toolchainInfo.getTargetGnuSystemName(); + } // Not all of CcToolchainProvider is exposed to Skylark, which makes implementing deep equality // impossible: if Java-only parts are considered, the behavior is surprising in Skylark, if they diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index 187d0fc552..32fb111fc4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -552,13 +552,6 @@ public class CppConfiguration extends BuildConfiguration.Fragment { return cppToolchainInfo.getCrosstoolTopPathFragment(); } - /** - * Returns the system name which is required by the toolchain to run. - */ - public String getHostSystemName() { - return cppToolchainInfo.getHostSystemName(); - } - @Override public String toString() { return cppToolchainInfo.toString(); @@ -936,33 +929,6 @@ public class CppConfiguration extends BuildConfiguration.Fragment { } /** - * Returns test-only link options such that certain test-specific features can be configured - * separately (e.g. lazy binding). - */ - public ImmutableList<String> getTestOnlyLinkOptions() { - return cppToolchainInfo.getTestOnlyLinkOptions(); - } - - - /** - * Returns the list of options to be used with 'objcopy' when converting - * binary files to object files, or {@code null} if this operation is not - * supported. - */ - public ImmutableList<String> getObjCopyOptionsForEmbedding() { - return cppToolchainInfo.getObjCopyOptionsForEmbedding(); - } - - /** - * Returns the list of options to be used with 'ld' when converting - * binary files to object files, or {@code null} if this operation is not - * supported. - */ - public ImmutableList<String> getLdOptionsForEmbedding() { - return cppToolchainInfo.getLdOptionsForEmbedding(); - } - - /** * Returns a map of additional make variables for use by {@link * BuildConfiguration}. These are to used to allow some build rules to * avoid the limits on stack frame sizes and variable-length arrays. @@ -1599,10 +1565,6 @@ public class CppConfiguration extends BuildConfiguration.Fragment { return defaultSysroot; } - public PathFragment getDefaultSysroot() { - return cppToolchainInfo.getDefaultSysroot(); - } - @Override public PatchTransition getArtifactOwnerTransition() { return isLipoContextCollector() ? ContextCollectorOwnerTransition.INSTANCE : null; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java index 74522c5239..d02867f28c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java @@ -117,6 +117,7 @@ public final class CppLinkAction extends AbstractAction private final boolean isLtoIndexing; private final PathFragment ldExecutable; + private final String hostSystemName; private final Iterable<Artifact> mandatoryInputs; @@ -180,6 +181,7 @@ public final class CppLinkAction extends AbstractAction this.toolchainEnv = toolchainEnv; this.executionRequirements = executionRequirements; this.ldExecutable = toolchain.getToolPathFragment(Tool.LD); + this.hostSystemName = toolchain.getHostSystemName(); } private CppConfiguration getCppConfiguration() { @@ -192,7 +194,7 @@ public final class CppLinkAction extends AbstractAction } public String getHostSystemName() { - return getCppConfiguration().getHostSystemName(); + return hostSystemName; } @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java index cad71852a3..febb98d4c0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java @@ -349,7 +349,7 @@ public final class LinkCommandLine extends CommandLine { // Extra test-specific link options. if (useTestOnlyFlags) { - toolchainFlags.addAll(cppConfiguration.getTestOnlyLinkOptions()); + toolchainFlags.addAll(ccProvider.getTestOnlyLinkOptions()); } toolchainFlags.addAll(ccProvider.getLinkOptions()); |