diff options
3 files changed, 85 insertions, 11 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockCcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockCcSupport.java index 75192ab4c6..927a5fec43 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockCcSupport.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockCcSupport.java @@ -13,14 +13,10 @@ // limitations under the License. package com.google.devtools.build.lib.packages.util; -import static java.nio.charset.StandardCharsets.UTF_8; - import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; -import com.google.common.io.ByteStreams; import com.google.devtools.build.lib.cmdline.Label; import java.io.IOException; -import java.io.InputStream; /** * Bazel implementation of {@link MockCcSupport} @@ -126,7 +122,8 @@ public final class BazelMockCcSupport extends MockCcSupport { ")"); config.create( - "/bazel_tools_workspace/tools/cpp/CROSSTOOL", readFromResources(MOCK_CROSSTOOL_PATH)); + "/bazel_tools_workspace/tools/cpp/CROSSTOOL", + readCrosstoolFile()); config.create( "/bazel_tools_workspace/tools/objc/BUILD", "xcode_config(name = 'host_xcodes')"); @@ -144,12 +141,12 @@ public final class BazelMockCcSupport extends MockCcSupport { @Override public String readCrosstoolFile() throws IOException { - return readFromResources(MOCK_CROSSTOOL_PATH); + return ResourceLoader.readFromResources(MOCK_CROSSTOOL_PATH); } - public static String readFromResources(String filename) throws IOException { - InputStream in = BazelMockCcSupport.class.getClassLoader().getResourceAsStream(filename); - return new String(ByteStreams.toByteArray(in), UTF_8); + @Override + public String getMockLibcPath() { + return "tools/cpp/libc"; } @Override 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 b2eb70f0b0..2c5dc2ae32 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 @@ -343,6 +343,49 @@ public abstract class MockCcSupport { return TextFormat.printToString(builder.build()); } + public static String addOptionalDefaultCoptsToCrosstool(String original) + throws TextFormat.ParseException { + CrosstoolConfig.CrosstoolRelease.Builder builder = + CrosstoolConfig.CrosstoolRelease.newBuilder(); + TextFormat.merge(original, builder); + for (CrosstoolConfig.CToolchain.Builder toolchain : builder.getToolchainBuilderList()) { + CrosstoolConfig.CToolchain.OptionalFlag.Builder defaultTrue = + CrosstoolConfig.CToolchain.OptionalFlag.newBuilder(); + defaultTrue.setDefaultSettingName("crosstool_default_true"); + defaultTrue.addFlag("-DDEFAULT_TRUE"); + toolchain.addOptionalCompilerFlag(defaultTrue.build()); + CrosstoolConfig.CToolchain.OptionalFlag.Builder defaultFalse = + CrosstoolConfig.CToolchain.OptionalFlag.newBuilder(); + defaultFalse.setDefaultSettingName("crosstool_default_false"); + defaultFalse.addFlag("-DDEFAULT_FALSE"); + toolchain.addOptionalCompilerFlag(defaultFalse.build()); + } + + CrosstoolConfig.CrosstoolRelease.DefaultSetting.Builder defaultTrue = + CrosstoolConfig.CrosstoolRelease.DefaultSetting.newBuilder(); + defaultTrue.setName("crosstool_default_true"); + defaultTrue.setDefaultValue(true); + builder.addDefaultSetting(defaultTrue.build()); + CrosstoolConfig.CrosstoolRelease.DefaultSetting.Builder defaultFalse = + CrosstoolConfig.CrosstoolRelease.DefaultSetting.newBuilder(); + defaultFalse.setName("crosstool_default_false"); + defaultFalse.setDefaultValue(false); + builder.addDefaultSetting(defaultFalse.build()); + + return TextFormat.printToString(builder.build()); + } + + public static String addLibcLabelToCrosstool(String original, String label) + throws TextFormat.ParseException { + CrosstoolConfig.CrosstoolRelease.Builder builder = + CrosstoolConfig.CrosstoolRelease.newBuilder(); + TextFormat.merge(original, builder); + for (CrosstoolConfig.CToolchain.Builder toolchain : builder.getToolchainBuilderList()) { + toolchain.setDefaultGrteTop(label); + } + return TextFormat.printToString(builder.build()); + } + public abstract Predicate<String> labelNameFilter(); /** @@ -382,8 +425,7 @@ public abstract class MockCcSupport { /** * 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. The code - * here matches the declarations in {@link CrosstoolTestHelper}. + * for all other tests, it only creates a dummy package, with a working CROSSTOOL file. * * <p>If <code>addEmbeddedRuntimes</code> is true, it also adds filegroups for the embedded * runtimes. @@ -506,6 +548,8 @@ public abstract class MockCcSupport { public abstract String readCrosstoolFile() throws IOException; + public abstract String getMockLibcPath(); + protected abstract ImmutableList<String> getCrosstoolArchs(); protected abstract String[] getRealFilesystemTools(String crosstoolTop); diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/ResourceLoader.java b/src/test/java/com/google/devtools/build/lib/packages/util/ResourceLoader.java new file mode 100644 index 0000000000..3303f73cf5 --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/packages/util/ResourceLoader.java @@ -0,0 +1,33 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.packages.util; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import com.google.common.io.ByteStreams; +import java.io.IOException; +import java.io.InputStream; + +/** + * Reads a file from the resources and returns its contents as a string. + */ +public final class ResourceLoader { + /** + * Reads a file from the resources and returns its contents as a string. + */ + public static String readFromResources(String filename) throws IOException { + InputStream in = ResourceLoader.class.getClassLoader().getResourceAsStream(filename); + return new String(ByteStreams.toByteArray(in), UTF_8); + } +} |