Skip to content

Commit

Permalink
Replace --cpu usages with --platforms in tests
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 616992341
Change-Id: I6bbc763e85f5b2e6376179098e359a2361f18c6b
  • Loading branch information
mai93 authored and Wyverald committed Apr 25, 2024
1 parent 2328206 commit df2b9df
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.rules.java.JavaInfo;
import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.build.lib.testutil.TestConstants.InternalTestExecutionMode;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.common.options.Option;
Expand Down Expand Up @@ -192,7 +193,7 @@ public void testActionConflictInDependencyImpliesTopLevelTargetFailure() throws
// TODO(b/67529176): conflicts not detected.
return;
}
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
scratch.file(
"conflict_non_top_level/BUILD",
"cc_library(name='x', srcs=['foo.cc'])",
Expand All @@ -215,7 +216,7 @@ public void testActionConflictInDependencyImpliesTopLevelTargetFailure() throws
*/
@Test
public void testNoActionConflictWithInvalidatedTarget() throws Exception {
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
scratch.file(
"conflict/BUILD",
"cc_library(name='x', srcs=['foo.cc'])",
Expand All @@ -241,7 +242,7 @@ public void testActionConflictCausesError() throws Exception {
// TODO(b/67529176): conflicts not detected.
return;
}
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
scratch.file(
"conflict/BUILD",
"cc_library(name='x', srcs=['foo.cc'])",
Expand All @@ -257,7 +258,7 @@ public void testNoActionConflictErrorAfterClearedAnalysis() throws Exception {
// TODO(b/67529176): conflicts not detected.
return;
}
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
scratch.file(
"conflict/BUILD",
"cc_library(name='x', srcs=['foo.cc'])",
Expand Down Expand Up @@ -287,7 +288,7 @@ public void testConflictingArtifactsErrorWithNoListDetail() throws Exception {
// TODO(b/67529176): conflicts not detected.
return;
}
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
scratch.file(
"conflict/BUILD",
"cc_library(name='x', srcs=['foo.cc'])",
Expand All @@ -310,7 +311,7 @@ public void testConflictingArtifactsWithListDetail() throws Exception {
// TODO(b/67529176): conflicts not detected.
return;
}
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
scratch.file(
"conflict/BUILD",
"cc_library(name='x', srcs=['foo1.cc'])",
Expand Down Expand Up @@ -347,7 +348,7 @@ public void testActionConflictMarksTargetInvalid() throws Exception {
// TODO(b/67529176): conflicts not detected.
return;
}
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
scratch.file(
"conflict/BUILD",
"cc_library(name='x', srcs=['foo.cc'])",
Expand Down Expand Up @@ -988,16 +989,19 @@ public void noCacheClearMessageAfterIrrelevantOptionChangesWithDiffDisabled() th
}

@Test
public void cacheClearMessageAfterChangingCpu() throws Exception {
public void cacheClearMessageAfterChangingPlatform() throws Exception {
setupDiffResetTesting();
scratch.file("test/BUILD", "load(':lib.bzl', 'normal_lib')", "normal_lib(name='top')");
useConfiguration("--max_config_changes_to_show=-1", "--cpu=k8");
useConfiguration(
"--max_config_changes_to_show=-1", "--platforms=" + TestConstants.PLATFORM_LABEL);
update("//test:top");
useConfiguration("--max_config_changes_to_show=-1", "--cpu=armeabi-v7a");
useConfiguration(
"--max_config_changes_to_show=-1",
"--platforms=" + TestConstants.LOCAL_CONFIG_PLATFORM_PACKAGE_ROOT + ":piii");
eventCollector.clear();
update("//test:top");
assertDoesNotContainEvent("--discard_analysis_cache");
assertContainsEvent("Build option --cpu has changed, " + CACHE_DISCARD_WARNING);
assertContainsEvent("Build option --platforms has changed, " + CACHE_DISCARD_WARNING);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.google.devtools.build.lib.pkgcache.LoadingFailureEvent;
import com.google.devtools.build.lib.skyframe.ActionLookupConflictFindingFunction;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.build.lib.testutil.TestConstants.InternalTestExecutionMode;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.Path;
Expand Down Expand Up @@ -964,7 +965,7 @@ public void testPostProcessedConfigurableAttributes() throws Exception {
// TODO(b/67651960): fix or justify disabling.
return;
}
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
reporter.removeHandler(failFastHandler); // Expect errors from action conflicts.
scratch.file(
"conflict/BUILD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ public static void setup(
" '" + constraintsPackageRoot + "cpu:x86_64',",
" '" + constraintsPackageRoot + "os:linux',",
" ],",
")",
"platform(",
" name = 'piii',",
" constraint_values = [",
" '" + constraintsPackageRoot + "cpu:x86_32',",
" '" + constraintsPackageRoot + "os:linux',",
" ],",
")");

mockToolsConfig.create(
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/test/java/com/google/devtools/build/lib/analysis/util",
"//src/test/java/com/google/devtools/build/lib/packages:testutil",
"//src/test/java/com/google/devtools/build/lib/testutil:TestConstants",
"//third_party:guava",
"//third_party:junit4",
"//third_party:truth",
Expand Down Expand Up @@ -214,6 +215,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/test/java/com/google/devtools/build/lib/analysis/util",
"//src/test/java/com/google/devtools/build/lib/packages:testutil",
"//src/test/java/com/google/devtools/build/lib/testutil:TestConstants",
"//third_party:junit4",
"//third_party:truth",
],
Expand Down Expand Up @@ -512,6 +514,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/test/java/com/google/devtools/build/lib/analysis/util",
"//src/test/java/com/google/devtools/build/lib/packages:testutil",
"//src/test/java/com/google/devtools/build/lib/testutil:TestConstants",
"//third_party:guava",
"//third_party:junit4",
"//third_party:truth",
Expand Down Expand Up @@ -545,6 +548,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/test/java/com/google/devtools/build/lib/analysis/util",
"//src/test/java/com/google/devtools/build/lib/packages:testutil",
"//src/test/java/com/google/devtools/build/lib/testutil:TestConstants",
"//third_party:guava",
"//third_party:junit4",
"//third_party:truth",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void testArchiveInCcLibrarySrcs() throws Exception {
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_DYNAMIC_LINKER));
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
ConfiguredTarget archiveInSrcsTest =
scratchConfiguredTarget(
"archive_in_srcs",
Expand Down Expand Up @@ -359,7 +359,7 @@ public void testTempsWithDifferentExtensions() throws Exception {
.setupCcToolchainConfig(
mockToolsConfig, CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_PIC));
invalidatePackages();
useConfiguration("--cpu=k8", "--save_temps");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL, "--save_temps");
scratch.file(
"ananas/BUILD",
"cc_library(name='ananas',",
Expand Down Expand Up @@ -447,7 +447,7 @@ public void testPicModeAssembly() throws Exception {
CcToolchainConfig.builder()
.withFeatures(CppRuleClasses.SUPPORTS_PIC, CppRuleClasses.PIC));
invalidatePackages();
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
scratch.file("a/BUILD", "cc_library(name='preprocess', srcs=['preprocess.S'])");
List<String> argv = getCppCompileAction("//a:preprocess").getArguments();
assertThat(argv).contains("-fPIC");
Expand Down Expand Up @@ -561,7 +561,11 @@ public void testCcTestBuiltWithFissionHasDwp() throws Exception {
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder().withFeatures(CppRuleClasses.PER_OBJECT_DEBUG_INFO));
useConfiguration("--cpu=k8", "--build_test_dwp", "--dynamic_mode=off", "--fission=yes");
useConfiguration(
"--platforms=" + TestConstants.PLATFORM_LABEL,
"--build_test_dwp",
"--dynamic_mode=off",
"--fission=yes");
ConfiguredTarget target =
scratchConfiguredTarget(
"mypackage", "mytest", "cc_test(name = 'mytest', srcs = ['mytest.cc'])");
Expand Down Expand Up @@ -1004,7 +1008,7 @@ public void testSupportsPicFeatureResultsInPICObjectGenerated() throws Exception
CppActionNames.CPP_LINK_STATIC_LIBRARY,
CppActionNames.CPP_COMPILE,
CppActionNames.CPP_LINK_NODEPS_DYNAMIC_LIBRARY));
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);

scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])");
scratch.file("x/a.cc");
Expand Down Expand Up @@ -1058,7 +1062,7 @@ public void testWhenSupportsPicDisabledButForcePicSetPICAreGenerated() throws Ex
CppActionNames.CPP_LINK_STATIC_LIBRARY,
CppActionNames.CPP_COMPILE,
CppActionNames.CPP_LINK_NODEPS_DYNAMIC_LIBRARY));
useConfiguration("--force_pic", "--cpu=k8");
useConfiguration("--force_pic", "--platforms=" + TestConstants.PLATFORM_LABEL);

scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])");
scratch.file("x/a.cc");
Expand Down Expand Up @@ -1088,7 +1092,7 @@ public void testPreferPicForOptBinaryFeature() throws Exception {
CppActionNames.CPP_LINK_STATIC_LIBRARY,
CppActionNames.CPP_COMPILE,
CppActionNames.CPP_LINK_NODEPS_DYNAMIC_LIBRARY));
useConfiguration("--cpu=k8", "--compilation_mode=opt");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL, "--compilation_mode=opt");

scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])");
scratch.file("x/a.cc");
Expand Down Expand Up @@ -1117,7 +1121,7 @@ public void testPreferPicForOptBinaryFeatureNeedsPicSupport() throws Exception {
CppActionNames.CPP_LINK_STATIC_LIBRARY,
CppActionNames.CPP_COMPILE,
CppActionNames.CPP_LINK_NODEPS_DYNAMIC_LIBRARY));
useConfiguration("--cpu=k8", "--compilation_mode=opt");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL, "--compilation_mode=opt");

scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])");
scratch.file("x/a.cc");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.util.CompileOnlyTestCase;
import com.google.devtools.build.lib.packages.util.Crosstool.CcToolchainConfig;
import com.google.devtools.build.lib.testutil.TestConstants;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -34,7 +35,7 @@ public void testCcCompileOnly() throws Exception {
.ccSupport()
.setupCcToolchainConfig(
mockToolsConfig, CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_PIC));
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
scratch.file("package/BUILD",
"cc_binary(name='foo', srcs=['foo.cc', ':bar'], deps = [':foolib'])",
"cc_library(name='foolib', srcs=['foolib.cc'])",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.packages.util.Crosstool.CcToolchainConfig;
import com.google.devtools.build.lib.testutil.TestConstants;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -165,7 +166,9 @@ public void testCcImportWithStaticLibrary() throws Exception {

@Test
public void testCcImportWithSharedLibrary() throws Exception {
useConfiguration("--cpu=k8", "--noincompatible_enable_cc_toolchain_resolution");
useConfiguration(
"--platforms=" + TestConstants.PLATFORM_LABEL,
"--noincompatible_enable_cc_toolchain_resolution");
ConfiguredTarget target =
scratchConfiguredTarget(
"a",
Expand All @@ -192,7 +195,9 @@ public void testCcImportWithSharedLibrary() throws Exception {

@Test
public void testCcImportWithVersionedSharedLibrary() throws Exception {
useConfiguration("--cpu=k8", "--noincompatible_enable_cc_toolchain_resolution");
useConfiguration(
"--platforms=" + TestConstants.PLATFORM_LABEL,
"--noincompatible_enable_cc_toolchain_resolution");
ConfiguredTarget target =
scratchConfiguredTarget(
"a",
Expand All @@ -219,7 +224,9 @@ public void testCcImportWithVersionedSharedLibrary() throws Exception {

@Test
public void testCcImportWithVersionedSharedLibraryWithDotInTheName() throws Exception {
useConfiguration("--cpu=k8", "--noincompatible_enable_cc_toolchain_resolution");
useConfiguration(
"--platforms=" + TestConstants.PLATFORM_LABEL,
"--noincompatible_enable_cc_toolchain_resolution");

ConfiguredTarget target =
scratchConfiguredTarget(
Expand Down Expand Up @@ -274,7 +281,9 @@ public void testCcImportWithInvalidSharedLibraryNoExtension() throws Exception {

@Test
public void testCcImportWithInterfaceSharedLibrary() throws Exception {
useConfiguration("--cpu=k8", "--noincompatible_enable_cc_toolchain_resolution");
useConfiguration(
"--platforms=" + TestConstants.PLATFORM_LABEL,
"--noincompatible_enable_cc_toolchain_resolution");
ConfiguredTarget target =
scratchConfiguredTarget(
"b",
Expand Down Expand Up @@ -302,7 +311,9 @@ public void testCcImportWithInterfaceSharedLibrary() throws Exception {

@Test
public void testCcImportWithBothStaticAndSharedLibraries() throws Exception {
useConfiguration("--cpu=k8", "--noincompatible_enable_cc_toolchain_resolution");
useConfiguration(
"--platforms=" + TestConstants.PLATFORM_LABEL,
"--noincompatible_enable_cc_toolchain_resolution");
ConfiguredTarget target =
scratchConfiguredTarget(
"a",
Expand Down Expand Up @@ -414,7 +425,7 @@ public void testCcImportWithSharedLibraryAddsRpathEntry() throws Exception {
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_DYNAMIC_LINKER));
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
ConfiguredTarget target =
scratchConfiguredTarget(
"a",
Expand Down Expand Up @@ -456,7 +467,7 @@ public void testCcImportWithSharedLibraryWithTransitionAddsRpathEntry() throws E
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_DYNAMIC_LINKER));
useConfiguration("--cpu=k8");
useConfiguration("--platforms=" + TestConstants.PLATFORM_LABEL);
ConfiguredTarget target =
scratchConfiguredTarget(
"a",
Expand Down
Loading

0 comments on commit df2b9df

Please sign in to comment.