diff options
author | 2018-03-05 09:56:08 -0800 | |
---|---|---|
committer | 2018-03-05 09:58:13 -0800 | |
commit | 07f872923f19bd3bf3325287fb98b471a3fb9933 (patch) | |
tree | 6387001b21769ca95473042e62ed7624d1f696c9 | |
parent | 7633ab05f14ab93589a62e64ff7d5c3641c4ed14 (diff) |
Fix CppToolchainProvider to get unfiltered compiler flags from the
actual toolchain, not the CppConfiguration.
Change-Id: I9cb74a883d3041ee2c31d294c0a1a36df578f738
PiperOrigin-RevId: 187880704
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java | 12 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java | 43 |
2 files changed, 38 insertions, 17 deletions
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 935dfb8d50..1b6ae1aa6e 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 @@ -630,17 +630,17 @@ public final class CcToolchainProvider extends ToolchainInfo { } @SkylarkCallable( - name = "unfiltered_compiler_options_do_not_use", - doc = - "Returns the default list of options which cannot be filtered by BUILD " - + "rules. These should be appended to the command line after filtering." + name = "unfiltered_compiler_options", + doc = + "Returns the default list of options which cannot be filtered by BUILD " + + "rules. These should be appended to the command line after filtering." ) public ImmutableList<String> getUnfilteredCompilerOptionsWithSysroot(Iterable<String> features) { - return cppConfiguration.getUnfilteredCompilerOptionsDoNotUse(features, sysroot); + return toolchainInfo.getUnfilteredCompilerOptions(features, sysroot); } public ImmutableList<String> getUnfilteredCompilerOptions(Iterable<String> features) { - return cppConfiguration.getUnfilteredCompilerOptionsDoNotUse(features, /* sysroot= */ null); + return toolchainInfo.getUnfilteredCompilerOptions(features, /* sysroot= */ null); } @SkylarkCallable( diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java index 4eb49ed6af..52bbd59450 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java @@ -28,7 +28,6 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.rules.cpp.CppActionConfigs.CppPlatform; -import com.google.devtools.build.lib.rules.cpp.CppConfiguration.Tool; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; @@ -48,6 +47,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import javax.annotation.Nullable; /** * Information describing the C++ compiler derived from the CToolchain proto. @@ -103,6 +103,8 @@ public final class CppToolchainInfo { private final ImmutableListMultimap<LipoMode, String> lipoCFlags; private final ImmutableListMultimap<LipoMode, String> lipoCxxFlags; + private final FlagList unfilteredCompilerFlags; + private final boolean supportsFission; private final boolean supportsStartEndLib; private final boolean supportsEmbeddedRuntimes; @@ -211,6 +213,10 @@ public final class CppToolchainInfo { cxxFlagsBuilder.build(), lipoCFlagsBuilder.build(), lipoCxxFlagsBuilder.build(), + new FlagList( + ImmutableList.copyOf(toolchain.getUnfilteredCxxFlagList()), + FlagList.convertOptionalOptions(toolchain.getOptionalUnfilteredCxxFlagList()), + ImmutableList.<String>of()), toolchain.getSupportsFission(), toolchain.getSupportsStartEndLib(), toolchain.getSupportsEmbeddedRuntimes(), @@ -264,6 +270,7 @@ public final class CppToolchainInfo { ImmutableListMultimap<CompilationMode, String> cxxFlagsByCompilationMode, ImmutableListMultimap<LipoMode, String> lipoCFlags, ImmutableListMultimap<LipoMode, String> lipoCxxFlags, + FlagList unfilteredCompilerFlags, boolean supportsFission, boolean supportsStartEndLib, boolean supportsEmbeddedRuntimes, @@ -309,6 +316,7 @@ public final class CppToolchainInfo { this.cxxFlagsByCompilationMode = cxxFlagsByCompilationMode; this.lipoCFlags = lipoCFlags; this.lipoCxxFlags = lipoCxxFlags; + this.unfilteredCompilerFlags = unfilteredCompilerFlags; this.supportsFission = supportsFission; this.supportsStartEndLib = supportsStartEndLib; this.supportsEmbeddedRuntimes = supportsEmbeddedRuntimes; @@ -362,17 +370,17 @@ public final class CppToolchainInfo { String arToolPath = "DUMMY_AR_TOOL"; String stripToolPath = "DUMMY_STRIP_TOOL"; for (ToolPath tool : toolchain.getToolPathList()) { - if (tool.getName().equals(Tool.GCC.getNamePart())) { + if (tool.getName().equals(CppConfiguration.Tool.GCC.getNamePart())) { gccToolPath = tool.getPath(); linkerToolPath = crosstoolTopPathFragment .getRelative(PathFragment.create(tool.getPath())) .getPathString(); } - if (tool.getName().equals(Tool.AR.getNamePart())) { + if (tool.getName().equals(CppConfiguration.Tool.AR.getNamePart())) { arToolPath = tool.getPath(); } - if (tool.getName().equals(Tool.STRIP.getNamePart())) { + if (tool.getName().equals(CppConfiguration.Tool.STRIP.getNamePart())) { stripToolPath = tool.getPath(); } } @@ -749,6 +757,18 @@ public final class CppToolchainInfo { return crosstoolOptionalCxxFlags; } + /** Returns unfiltered compiler options for C++ from this toolchain. */ + public ImmutableList<String> getUnfilteredCompilerOptions( + Iterable<String> features, @Nullable PathFragment sysroot) { + if (sysroot == null) { + return unfilteredCompilerFlags.evaluate(features); + } + return ImmutableList.<String>builder() + .add("--sysroot=" + sysroot) + .addAll(unfilteredCompilerFlags.evaluate(features)) + .build(); + } + private static ImmutableMap<String, String> computeAdditionalMakeVariables(CToolchain toolchain) { Map<String, String> makeVariablesBuilder = new HashMap<>(); // The following are to be used to allow some build rules to avoid the limits on stack frame @@ -801,30 +821,31 @@ public final class CppToolchainInfo { if (toolPathsCollector.isEmpty()) { // If no paths are specified, we just use the names of the tools as the path. - for (Tool tool : Tool.values()) { + for (CppConfiguration.Tool tool : CppConfiguration.Tool.values()) { toolPathsCollector.put( tool.getNamePart(), crosstoolTopPathFragment.getRelative(tool.getNamePart())); } } else { - Iterable<Tool> neededTools = + Iterable<CppConfiguration.Tool> neededTools = Iterables.filter( - EnumSet.allOf(Tool.class), + EnumSet.allOf(CppConfiguration.Tool.class), tool -> { - if (tool == Tool.DWP) { + if (tool == CppConfiguration.Tool.DWP) { // When fission is unsupported, don't check for the dwp tool. return toolchain.getSupportsFission(); - } else if (tool == Tool.LLVM_PROFDATA) { + } else if (tool == CppConfiguration.Tool.LLVM_PROFDATA) { // TODO(tmsriram): Fix this to check if this is a llvm crosstool // and return true. This needs changes to crosstool_config.proto. return false; - } else if (tool == Tool.GCOVTOOL || tool == Tool.OBJCOPY) { + } else if (tool == CppConfiguration.Tool.GCOVTOOL + || tool == CppConfiguration.Tool.OBJCOPY) { // gcov-tool and objcopy are optional, don't check whether they're present return false; } else { return true; } }); - for (Tool tool : neededTools) { + for (CppConfiguration.Tool tool : neededTools) { if (!toolPathsCollector.containsKey(tool.getNamePart())) { throw new IllegalArgumentException( "Tool path for '" + tool.getNamePart() + "' is missing"); |