Skip to content

Commit

Permalink
Migrate CcCommonTest to use Starlark cc_toolchain configuration.
Browse files Browse the repository at this point in the history
Issue #5380
RELNOTES: None.
PiperOrigin-RevId: 238980912
  • Loading branch information
scentini authored and copybara-github committed Mar 18, 2019
1 parent 4a5e1b7 commit 8b8be2e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/test/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ java_library(
],
resources = [
"analysis/mock/MOCK_CROSSTOOL",
"analysis/mock/cc_toolchain_config.bzl",
],
tags = ["analysis"],
exports = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain;
import com.google.protobuf.TextFormat;
Expand Down Expand Up @@ -397,6 +398,15 @@ public void write() throws IOException {
crosstoolTop + "/cc_toolchain_config.bzl",
ResourceLoader.readFromResources(
"com/google/devtools/build/lib/analysis/mock/cc_toolchain_config.bzl"));
config.overwrite(
TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/cpp/cc_toolchain_config_lib.bzl",
ResourceLoader.readFromResources(
TestConstants.BAZEL_REPO_PATH + "tools/cpp/cc_toolchain_config_lib.bzl"));
config.overwrite(
TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/build_defs/cc/action_names.bzl",
ResourceLoader.readFromResources(
TestConstants.BAZEL_REPO_PATH + "tools/build_defs/cc/action_names.bzl"));
config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/build_defs/cc/BUILD");
} else {
config.overwrite(crosstoolTop + "/CROSSTOOL", crosstoolFileContents);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.packages.util.MockCcSupport;
import com.google.devtools.build.lib.packages.util.Crosstool.CcToolchainConfig;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.ModifiedFileSet;
Expand Down Expand Up @@ -250,7 +250,9 @@ public void testIsolatedDefines() throws Exception {
public void testStartEndLib() throws Exception {
getAnalysisMock()
.ccSupport()
.setupCrosstool(mockToolsConfig, MockCcSupport.SUPPORTS_START_END_LIB_FEATURE);
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_START_END_LIB));
useConfiguration(
// Prevent Android from trying to setup ARM crosstool by forcing it on system cpu.
"--fat_apk_cpu=k8", "--start_end_lib");
Expand All @@ -274,7 +276,9 @@ public void testStartEndLib() throws Exception {
public void testStartEndLibThroughFeature() throws Exception {
AnalysisMock.get()
.ccSupport()
.setupCrosstool(mockToolsConfig, MockCcSupport.SUPPORTS_START_END_LIB_FEATURE);
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_START_END_LIB));
useConfiguration("--start_end_lib");
scratch.file(
"test/BUILD",
Expand All @@ -294,7 +298,8 @@ public void testStartEndLibThroughFeature() throws Exception {
public void testTempsWithDifferentExtensions() throws Exception {
AnalysisMock.get()
.ccSupport()
.setupCrosstool(mockToolsConfig, MockCcSupport.SUPPORTS_PIC_FEATURE);
.setupCcToolchainConfig(
mockToolsConfig, CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_PIC));
invalidatePackages();
useConfiguration("--cpu=k8", "--save_temps");
scratch.file(
Expand Down Expand Up @@ -332,7 +337,8 @@ private IterableSubject assertTempsForTarget(String testTarget) throws Exception
public void testTempsForCcWithPic() throws Exception {
AnalysisMock.get()
.ccSupport()
.setupCrosstool(mockToolsConfig, MockCcSupport.SUPPORTS_PIC_FEATURE);
.setupCcToolchainConfig(
mockToolsConfig, CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_PIC));
invalidatePackages();
assertTempsForTarget("//foo:foo").containsExactly("foo.pic.ii", "foo.pic.s");
}
Expand All @@ -346,7 +352,8 @@ public void testTempsForCcWithoutPic() throws Exception {
public void testTempsForCWithPic() throws Exception {
AnalysisMock.get()
.ccSupport()
.setupCrosstool(mockToolsConfig, MockCcSupport.SUPPORTS_PIC_FEATURE);
.setupCcToolchainConfig(
mockToolsConfig, CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_PIC));
invalidatePackages();
useConfiguration();

Expand Down Expand Up @@ -381,8 +388,10 @@ public void testAlwaysLinkYieldsLo() throws Exception {
public void testNoCoptfPicOverride() throws Exception {
getAnalysisMock()
.ccSupport()
.setupCrosstool(
mockToolsConfig, MockCcSupport.SUPPORTS_PIC_FEATURE, MockCcSupport.PIC_FEATURE);
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder()
.withFeatures(CppRuleClasses.SUPPORTS_PIC, CppRuleClasses.PIC));
// Prevent Android from trying to setup ARM crosstool by forcing it on system cpu.
useConfiguration("--fat_apk_cpu=k8");

Expand Down Expand Up @@ -423,8 +432,10 @@ public void testNoCoptfPicOverride() throws Exception {
public void testPicModeAssembly() throws Exception {
AnalysisMock.get()
.ccSupport()
.setupCrosstool(
mockToolsConfig, MockCcSupport.SUPPORTS_PIC_FEATURE, MockCcSupport.PIC_FEATURE);
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder()
.withFeatures(CppRuleClasses.SUPPORTS_PIC, CppRuleClasses.PIC));
invalidatePackages();
useConfiguration("--cpu=k8");
scratch.file("a/BUILD", "cc_library(name='preprocess', srcs=['preprocess.S'])");
Expand Down Expand Up @@ -536,7 +547,9 @@ public void testCcTestBuiltWithFissionHasDwp() throws Exception {
// in their runfiles.
getAnalysisMock()
.ccSupport()
.setupCrosstool(mockToolsConfig, MockCcSupport.PER_OBJECT_DEBUG_INFO_CONFIGURATION);
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder().withFeatures(CppRuleClasses.PER_OBJECT_DEBUG_INFO));
useConfiguration("--cpu=k8", "--build_test_dwp", "--dynamic_mode=off", "--fission=yes");
ConfiguredTarget target =
scratchConfiguredTarget(
Expand Down Expand Up @@ -717,12 +730,7 @@ public void testCcLibraryWithDashStatic() throws Exception {

@Test
public void testCcLibraryWithDashStaticOnDarwin() throws Exception {
getAnalysisMock()
.ccSupport()
.setupCrosstool(
mockToolsConfig,
/* appendToCurrentToolchain= */ false,
MockCcSupport.emptyToolchainForCpu("darwin"));
getAnalysisMock().ccSupport().setupCcToolchainConfigForCpu(mockToolsConfig, "darwin");
useConfiguration("--cpu=darwin");
checkError(
"badlib",
Expand Down Expand Up @@ -974,13 +982,14 @@ public void testSymlinkActionIsNotRegisteredWhenIncludePrefixDoesntChangePath()
public void testSupportsPicFeatureResultsInPICObjectGenerated() throws Exception {
getAnalysisMock()
.ccSupport()
.setupCrosstool(
.setupCcToolchainConfig(
mockToolsConfig,
MockCcSupport.NO_LEGACY_FEATURES_FEATURE,
MockCcSupport.EMPTY_STATIC_LIBRARY_ACTION_CONFIG,
MockCcSupport.EMPTY_COMPILE_ACTION_CONFIG,
MockCcSupport.EMPTY_DYNAMIC_LIBRARY_ACTION_CONFIG,
MockCcSupport.SUPPORTS_PIC_FEATURE);
CcToolchainConfig.builder()
.withFeatures(CppRuleClasses.NO_LEGACY_FEATURES, CppRuleClasses.SUPPORTS_PIC)
.withActionConfigs(
CppActionNames.CPP_LINK_STATIC_LIBRARY,
CppActionNames.CPP_COMPILE,
CppActionNames.CPP_LINK_NODEPS_DYNAMIC_LIBRARY));
useConfiguration("--cpu=k8");

scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])");
Expand All @@ -1000,12 +1009,14 @@ public void testSupportsPicFeatureResultsInPICObjectGenerated() throws Exception
public void testWhenSupportsPicDisabledPICObjectAreNotGenerated() throws Exception {
getAnalysisMock()
.ccSupport()
.setupCrosstool(
.setupCcToolchainConfig(
mockToolsConfig,
MockCcSupport.NO_LEGACY_FEATURES_FEATURE,
MockCcSupport.EMPTY_STATIC_LIBRARY_ACTION_CONFIG,
MockCcSupport.EMPTY_COMPILE_ACTION_CONFIG,
MockCcSupport.EMPTY_DYNAMIC_LIBRARY_ACTION_CONFIG);
CcToolchainConfig.builder()
.withFeatures(CppRuleClasses.NO_LEGACY_FEATURES)
.withActionConfigs(
CppActionNames.CPP_LINK_STATIC_LIBRARY,
CppActionNames.CPP_COMPILE,
CppActionNames.CPP_LINK_NODEPS_DYNAMIC_LIBRARY));
useConfiguration("--features=-supports_pic");

scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])");
Expand All @@ -1025,13 +1036,14 @@ public void testWhenSupportsPicDisabledPICObjectAreNotGenerated() throws Excepti
public void testWhenSupportsPicDisabledButForcePicSetPICAreGenerated() throws Exception {
getAnalysisMock()
.ccSupport()
.setupCrosstool(
.setupCcToolchainConfig(
mockToolsConfig,
MockCcSupport.NO_LEGACY_FEATURES_FEATURE,
MockCcSupport.EMPTY_STATIC_LIBRARY_ACTION_CONFIG,
MockCcSupport.EMPTY_COMPILE_ACTION_CONFIG,
MockCcSupport.EMPTY_DYNAMIC_LIBRARY_ACTION_CONFIG,
MockCcSupport.SUPPORTS_PIC_FEATURE);
CcToolchainConfig.builder()
.withFeatures(CppRuleClasses.NO_LEGACY_FEATURES, CppRuleClasses.SUPPORTS_PIC)
.withActionConfigs(
CppActionNames.CPP_LINK_STATIC_LIBRARY,
CppActionNames.CPP_COMPILE,
CppActionNames.CPP_LINK_NODEPS_DYNAMIC_LIBRARY));
useConfiguration("--force_pic", "--cpu=k8");

scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])");
Expand All @@ -1052,12 +1064,14 @@ public void testWhenSupportsPicNotPresentAndForcePicPassedIsError() throws Excep
reporter.removeHandler(failFastHandler);
getAnalysisMock()
.ccSupport()
.setupCrosstool(
.setupCcToolchainConfig(
mockToolsConfig,
MockCcSupport.NO_LEGACY_FEATURES_FEATURE,
MockCcSupport.EMPTY_STATIC_LIBRARY_ACTION_CONFIG,
MockCcSupport.EMPTY_DYNAMIC_LIBRARY_ACTION_CONFIG,
MockCcSupport.EMPTY_COMPILE_ACTION_CONFIG);
CcToolchainConfig.builder()
.withFeatures(CppRuleClasses.NO_LEGACY_FEATURES)
.withActionConfigs(
CppActionNames.CPP_LINK_STATIC_LIBRARY,
CppActionNames.CPP_LINK_NODEPS_DYNAMIC_LIBRARY,
CppActionNames.CPP_COMPILE));
useConfiguration("--force_pic", "--features=-supports_pic");

scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])");
Expand All @@ -1073,7 +1087,9 @@ public void testWhenSupportsPicNotPresentAndForcePicPassedIsError() throws Excep
public void testCompilationParameterFile() throws Exception {
AnalysisMock.get()
.ccSupport()
.setupCrosstool(mockToolsConfig, MockCcSupport.COMPILER_PARAM_FILE);
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder().withFeatures(CppRuleClasses.COMPIILER_PARAM_FILE));
scratch.file("a/BUILD", "cc_library(name='foo', srcs=['foo.cc'])");
CppCompileAction cppCompileAction = getCppCompileAction("//a:foo");
assertThat(
Expand Down

0 comments on commit 8b8be2e

Please sign in to comment.