aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java3
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/util/BazelMockCcSupport.java121
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java14
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java60
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java10
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSelectionTest.java16
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/DefaultToolchainTest.java49
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java12
8 files changed, 197 insertions, 88 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
index a9960b0ecd..9d89a89da7 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
@@ -58,7 +58,8 @@ public final class BazelAnalysisMock extends AnalysisMock {
"local_repository(name = 'local_config_xcode', path = '/local_config_xcode')",
"local_repository(name = 'com_google_protobuf', path = '/protobuf')",
"bind(name = 'android/sdk', actual='@bazel_tools//tools/android:sdk')",
- "bind(name = 'tools/python', actual='//tools/python')"));
+ "bind(name = 'tools/python', actual='//tools/python')",
+ "register_toolchains('@bazel_tools//tools/cpp:all')"));
}
@Override
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 f9b07d209d..ecd0814de1 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
@@ -102,6 +102,16 @@ public final class BazelMockCcSupport extends MockCcSupport {
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-k8',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:linux',",
+ " ],",
+ " toolchain = ':cc-compiler-k8',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-no-dyn-linker-k8', all_files = ':empty', ",
" compiler_files = ':empty', cpu = 'k8', compiler = 'compiler_no_dyn_linker', ",
" libc = 'local', dwp_files = ':empty', dynamic_runtime_libs = [':empty'], ",
@@ -109,6 +119,16 @@ public final class BazelMockCcSupport extends MockCcSupport {
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-no-dyn-linker-k8',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:linux',",
+ " ],",
+ " toolchain = ':cc-no-dyn-linker-k8',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-ppc', all_files = ':empty', compiler_files = ':empty',",
" cpu = 'ppc', compiler = 'compiler', libc = 'local', dwp_files = ':empty',",
" dynamic_runtime_libs = [':empty'], ",
@@ -116,6 +136,16 @@ public final class BazelMockCcSupport extends MockCcSupport {
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-ppc',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:ppc',",
+ " '@bazel_tools//platforms:linux',",
+ " ],",
+ " toolchain = ':cc-compiler-ppc',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-piii', all_files = ':all-files-piii',",
" compiler_files = ':compiler-files-piii',",
" cpu = 'piii', compiler = 'compiler', libc = 'local', dwp_files = ':empty',",
@@ -124,6 +154,16 @@ public final class BazelMockCcSupport extends MockCcSupport {
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-piii',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_32',",
+ " '@bazel_tools//platforms:linux',",
+ " ],",
+ " toolchain = ':cc-compiler-piii',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-darwin', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'darwin', compiler = 'compiler', libc = 'macosx', dwp_files = ':empty',",
@@ -132,6 +172,16 @@ public final class BazelMockCcSupport extends MockCcSupport {
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-darwin',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:osx',",
+ " ],",
+ " toolchain = ':cc-compiler-darwin',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-no-dyn-linker-darwin', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'darwin', compiler = 'compiler_no_dyn_linker', libc = 'macosx', " ,
@@ -140,6 +190,16 @@ public final class BazelMockCcSupport extends MockCcSupport {
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-no-dyn-linker-darwin',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:osx',",
+ " ],",
+ " toolchain = ':cc-no-dyn-linker-darwin',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-ios_x86_64', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'ios_x86_64', compiler = 'compiler', libc = 'local', dwp_files = ':empty',",
@@ -148,6 +208,16 @@ public final class BazelMockCcSupport extends MockCcSupport {
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-ios_x86_64',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:ios',",
+ " ],",
+ " toolchain = ':cc-compiler-ios_x86_64',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-armeabi-v7a', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'armeabi-v7a', compiler = 'compiler', libc = 'armeabi-v7a', ",
@@ -157,6 +227,16 @@ public final class BazelMockCcSupport extends MockCcSupport {
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-armeabi-v7a',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:arm',",
+ " '@bazel_tools//platforms:android',",
+ " ],",
+ " toolchain = ':cc-compiler-armeabi-v7a',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-x64_windows', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'x64_windows', compiler = 'windows_msys64', libc = 'local', ",
@@ -166,6 +246,16 @@ public final class BazelMockCcSupport extends MockCcSupport {
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-x64_windows',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:windows',",
+ " ],",
+ " toolchain = ':cc-compiler-x64_windows',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-no-dyn-linker-x64_windows', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'x64_windows', compiler = 'compiler_no_dyn_linker', libc = 'local', ",
@@ -175,6 +265,16 @@ public final class BazelMockCcSupport extends MockCcSupport {
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-no-dyn-linker-x64_windows',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:windows',",
+ " ],",
+ " toolchain = ':cc-no-dyn-linker-x64_windows',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"filegroup(",
" name = 'interface_library_builder',",
" srcs = ['build_interface_so'],",
@@ -182,26 +282,7 @@ public final class BazelMockCcSupport extends MockCcSupport {
"filegroup(",
" name = 'link_dynamic_library',",
" srcs = ['link_dynamic_library.sh'],",
- ")",
- "toolchain(",
- " name = 'toolchain_cc-compiler-piii',",
- " toolchain_type = ':toolchain_type',",
- " toolchain = '//third_party/crosstool/mock:cc-compiler-piii',",
- " target_compatible_with = [':mock_value'],",
- ")",
- "toolchain(",
- " name = 'dummy_cc_toolchain',",
- " toolchain_type = ':toolchain_type',",
- " toolchain = ':dummy_cc_toolchain_impl',",
- ")",
- "load(':dummy_toolchain.bzl', 'dummy_toolchain')",
- "dummy_toolchain(name = 'dummy_cc_toolchain_impl')");
- config.create(
- "/bazel_tools_workspace/tools/cpp/dummy_toolchain.bzl",
- "def _dummy_toolchain_impl(ctx):",
- " toolchain = platform_common.ToolchainInfo()",
- " return [toolchain]",
- "dummy_toolchain = rule(_dummy_toolchain_impl, attrs = {})");
+ ")");
config.create(
"/bazel_tools_workspace/tools/cpp/CROSSTOOL",
readCrosstoolFile());
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java
index 0c4ac80e78..be5778e256 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java
@@ -244,6 +244,7 @@ public final class MockObjcSupport {
Builder<String> crosstoolBuild =
ImmutableList.<String>builder()
.add(
+ "package(default_visibility=['//visibility:public'])",
"exports_files(glob(['**']))",
"cc_toolchain_suite(",
" name = 'crosstool',",
@@ -303,7 +304,20 @@ public final class MockObjcSupport {
" static_runtime_libs = [':empty'],",
" strip_files = ':empty',",
" supports_param_files = 0,",
+ ")",
+ "toolchain(name = 'cc-toolchain-" + arch + "',",
+ " exec_compatible_with = [],",
+ " target_compatible_with = [],",
+ " toolchain = ':cc-compiler-" + arch + "',",
+ " toolchain_type = '"
+ + TestConstants.TOOLS_REPOSITORY
+ + "//tools/cpp:toolchain_type'",
")");
+
+ // Add the newly-created toolchain to the WORKSPACE.
+ config.append(
+ "WORKSPACE",
+ "register_toolchains('//" + DEFAULT_OSX_CROSSTOOL_DIR + ":cc-toolchain-" + arch + "')");
}
config.create(DEFAULT_OSX_CROSSTOOL_DIR + "/BUILD",
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java
index c10bb59e59..91f525f0b2 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java
@@ -26,13 +26,73 @@ public class MockPlatformSupport {
mockToolsConfig.create(
platformsPath + "/BUILD",
"package(default_visibility=['//visibility:public'])",
+ "constraint_setting(name = 'cpu')",
+ "constraint_value(",
+ " name = 'x86_32',",
+ " constraint_setting = ':cpu',",
+ ")",
+ "constraint_value(",
+ " name = 'x86_64',",
+ " constraint_setting = ':cpu',",
+ ")",
+ "constraint_value(",
+ " name = 'ppc',",
+ " constraint_setting = ':cpu',",
+ ")",
+ "constraint_value(",
+ " name = 'arm',",
+ " constraint_setting = ':cpu',",
+ ")",
+ "constraint_setting(name = 'os')",
+ "constraint_value(",
+ " name = 'osx',",
+ " constraint_setting = ':os',",
+ ")",
+ "constraint_value(",
+ " name = 'ios',",
+ " constraint_setting = ':os',",
+ ")",
+ "constraint_value(",
+ " name = 'android',",
+ " constraint_setting = ':os',",
+ ")",
+ "constraint_value(",
+ " name = 'linux',",
+ " constraint_setting = ':os',",
+ ")",
+ "constraint_value(",
+ " name = 'windows',",
+ " constraint_setting = ':os',",
+ ")",
"platform(",
" name = 'target_platform',",
" target_platform = True,",
+ " cpu_constraints = [",
+ " ':x86_32',",
+ " ':x86_64',",
+ " ':ppc',",
+ " ':arm',",
+ " ],",
+ " os_constraints = [",
+ " ':osx',",
+ " ':linux',",
+ " ':windows',",
+ " ],",
")",
"platform(",
" name = 'host_platform',",
" host_platform = True,",
+ " cpu_constraints = [",
+ " ':x86_32',",
+ " ':x86_64',",
+ " ':ppc',",
+ " ':arm',",
+ " ],",
+ " os_constraints = [",
+ " ':osx',",
+ " ':linux',",
+ " ':windows',",
+ " ],",
")");
}
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java
index c5f6b312e3..c4af0c604b 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java
@@ -98,6 +98,16 @@ public final class MockToolsConfig {
return create(relativePath, lines);
}
+ public Path append(String relativePath, String... lines) throws IOException {
+ Path path = rootDirectory.getRelative(relativePath);
+ if (!path.exists()) {
+ return create(relativePath, lines);
+ }
+
+ FileSystemUtils.appendIsoLatin1(path, lines);
+ return path;
+ }
+
/**
* Links a tool into the workspace by creating a symbolic link to a real file. The target location
* in the workspace uses the same relative path as the given path to the tool in the runfiles
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSelectionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSelectionTest.java
index 2a67f8c005..09ed5e403e 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSelectionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSelectionTest.java
@@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.ToolchainContext.ResolvedToolchainProviders;
-import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.analysis.util.ScratchAttributeWriter;
import com.google.devtools.build.lib.cmdline.Label;
@@ -113,21 +112,6 @@ public class CcToolchainSelectionTest extends BuildViewTestCase {
}
@Test
- public void testToolchainSelectionWithoutPlatforms() throws Exception {
- useConfiguration("--experimental_platforms=//mock_platform:mock-piii-platform");
- ConfiguredTarget target =
- ScratchAttributeWriter.fromLabelString(this, "cc_library", "//lib")
- .setList("srcs", "a.cc")
- .write();
- ResolvedToolchainProviders providers =
- (ResolvedToolchainProviders)
- getRuleContext(target).getToolchainContext().getResolvedToolchainProviders();
- ToolchainInfo toolchain =
- providers.getForToolchainType(Label.parseAbsolute(CPP_TOOLCHAIN_TYPE));
- assertThat(toolchain.getFieldNames()).isEmpty();
- }
-
- @Test
public void testCToolchainSelectionFromCcToolchainAttrs() throws Exception {
useConfiguration(
"--enabled_toolchain_types=" + CPP_TOOLCHAIN_TYPE,
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/DefaultToolchainTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/DefaultToolchainTest.java
deleted file mode 100644
index 324ec10f2e..0000000000
--- a/src/test/java/com/google/devtools/build/lib/skyframe/DefaultToolchainTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2017 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.skyframe;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.rules.platform.ToolchainTestCase;
-import com.google.devtools.build.skyframe.EvaluationResult;
-import com.google.devtools.build.skyframe.SkyKey;
-import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests for default toolchains. */
-@RunWith(JUnit4.class)
-public class DefaultToolchainTest extends ToolchainTestCase {
- @Test
- public void testDefaultCcToolchainIsPresent() throws Exception {
- SkyKey toolchainKey = RegisteredToolchainsValue.key(targetConfigKey);
- EvaluationResult<RegisteredToolchainsValue> result =
- requestToolchainsFromSkyframe(toolchainKey);
- ImmutableList<DeclaredToolchainInfo> declaredToolchains =
- result.get(toolchainKey).registeredToolchains();
- List<Label> labels = collectToolchainLabels(declaredToolchains);
- assertThat(
- labels
- .stream()
- .anyMatch(
- toolchainLabel ->
- toolchainLabel.toString().contains("//tools/cpp:dummy_cc_toolchain_impl")))
- .isTrue();
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
index 311cd5ad0a..7626ce5b0e 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
@@ -23,6 +23,7 @@ import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo;
import com.google.devtools.build.lib.rules.platform.ToolchainTestCase;
import com.google.devtools.build.skyframe.EvaluationResult;
import com.google.devtools.build.skyframe.SkyKey;
+import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -41,8 +42,15 @@ public class RegisteredToolchainsFunctionTest extends ToolchainTestCase {
assertThatEvaluationResult(result).hasEntryThat(toolchainsKey).isNotNull();
RegisteredToolchainsValue value = result.get(toolchainsKey);
- // We have two registered toolchains, and a default toolchain for C++.
- assertThat(value.registeredToolchains()).hasSize(3);
+
+ // Check that the number of toolchains created for this test is correct.
+ assertThat(
+ value
+ .registeredToolchains()
+ .stream()
+ .filter(toolchain -> toolchain.toolchainType().equals(testToolchainType))
+ .collect(Collectors.toList()))
+ .hasSize(2);
assertThat(
value