diff options
author | 2017-08-01 14:56:53 +0200 | |
---|---|---|
committer | 2017-08-01 17:45:10 +0200 | |
commit | b05ed43283b9f5d69c4a1b27aa8319daed27e0be (patch) | |
tree | 9a0f098de3c1886dbca21a416ba6c4d86b6108cf /src/test/java/com/google/devtools/build | |
parent | 8db4454dbe103343d522a05bdd9f083b4cc13ff8 (diff) |
Implement user experience for LIPO / ThinLTO users.
Add flag --convert_lipo_to_thinlto, which allows builds with LLVM to use
ThinLTO when the user specifies LIPO + FDO flags; if that flag is not set, and
the user requests a build with LLVM, the compile will now fail.
Add an attribute supports_lipo to the DefaultCpuToolchain crosstool proto and
skip default toolchains that do not support LIPO when the user has specified
LIPO flags in the toolchain selection; this enables CROSSTOOL files to cause
an implicit fallback to a hybrid / LIPO toolchain when using an LLVM toolchain
as the default.
Add a CrosstoolBuilder to MockCcSupport and add a new method
setupCrosstoolFromScratch that allows unit tests to fully control the setup.
The other methods available in MockCcSupport will always load in a default
CROSSTOOL file and may show different unit test results depending on the
content of that file.
RELNOTES: None.
PiperOrigin-RevId: 163819246
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java index fae4347df9..f3e368a7bd 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java @@ -36,6 +36,76 @@ import java.io.IOException; */ public abstract class MockCcSupport { + /** + * Builder to build crosstool files for unit testing. + */ + public static final class CrosstoolBuilder { + public static final String DEFAULT_TARGET_CPU = "k8"; + public static final String MAJOR_VERSION = "13"; + public static final String MINOR_VERSION = "0"; + + private final CrosstoolConfig.CrosstoolRelease.Builder builder = + CrosstoolConfig.CrosstoolRelease.newBuilder() + .setMajorVersion(MAJOR_VERSION) + .setMinorVersion(MINOR_VERSION) + .setDefaultTargetCpu(DEFAULT_TARGET_CPU); + + /** Adds a default toolchain in the order of the calls. */ + public CrosstoolBuilder addDefaultToolchain(String cpu, String toolchainIdentifier) { + builder.addDefaultToolchainBuilder().setCpu(cpu).setToolchainIdentifier(toolchainIdentifier); + return this; + } + + /** Adds a default toolchain in the order of the calls. */ + public CrosstoolBuilder addDefaultToolchain( + String cpu, String toolchainIdentifier, boolean supportsLipo) { + builder + .addDefaultToolchainBuilder() + .setCpu(cpu) + .setToolchainIdentifier(toolchainIdentifier) + .setSupportsLipo(supportsLipo); + return this; + } + + /** Adds a toolchain where all required fields are set. */ + public CrosstoolBuilder addToolchain(String cpu, String toolchainIdentifier, String compiler) { + builder + .addToolchainBuilder() + .setTargetCpu(cpu) + .setToolchainIdentifier(toolchainIdentifier) + .setHostSystemName("host-system-name") + .setTargetSystemName("target-system-name") + .setTargetLibc("target-libc") + .setCompiler(compiler) + .setAbiVersion("abi-version") + .setAbiLibcVersion("abi-libc-version") + // TODO(klimek): Move to features. + .setSupportsStartEndLib(true); + return this; + } + + /** Appends the snippet {@code configuration} to all previously added toolchains. */ + public CrosstoolBuilder appendToAllToolchains(CToolchain configuration) { + for (CToolchain.Builder toolchainBuilder : builder.getToolchainBuilderList()) { + toolchainBuilder.mergeFrom(configuration); + } + return this; + } + + /** Appends the snippet {@code configuration} to all previously added toolchains. */ + public CrosstoolBuilder appendToAllToolchains(String... configuration) throws IOException { + CToolchain.Builder toolchainBuilder = CToolchain.newBuilder(); + TextFormat.merge(Joiner.on("\n").join(configuration), toolchainBuilder); + appendToAllToolchains(toolchainBuilder.buildPartial()); + return this; + } + + /** Returns the text proto containing the crosstool. */ + public String build() { + return TextFormat.printToString(builder.build()); + } + } + /** Filter to remove implicit crosstool artifact and module map inputs of C/C++ rules. */ public static final Predicate<Artifact> CC_ARTIFACT_FILTER = new Predicate<Artifact>() { @@ -617,6 +687,31 @@ public abstract class MockCcSupport { } /** + * Create a new crosstool configuration specified by {@code builder}. + * + * <p>If used from a {@code BuildViewTestCase}, make sure to call {@code + * BuildViewTestCase.invalidatePackages} after calling this method to force re-loading of the + * crosstool's BUILD files. + */ + public void setupCrosstoolFromScratch(MockToolsConfig config, CrosstoolBuilder builder) + throws IOException { + if (config.isRealFileSystem()) { + throw new RuntimeException( + "Cannot use setupCrosstoolFromScratch when config.isRealFileSystem() is true; " + + "use this function only for unit tests."); + } + // TODO(klimek): Get the version information from the crosstool builder and set up the + // crosstool with that information. + createCrosstoolPackage( + config, + /*addEmbeddedRuntimes=*/ false, + /*addModuleMap=*/ true, + null, + null, + builder.build()); + } + + /** * Create a crosstool package. For integration tests, it actually links in a working crosstool, * for all other tests, it only creates a dummy package, with a working CROSSTOOL file. * |