Add platforms to apple crosstool transition
This is needed to enable C++ toolchainisation in Bazel.
PiperOrigin-RevId: 558140728
Change-Id: Id0b532de76c9e403790107f6916e8a3a8be23d95
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 876146a..65d8fcf 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
@@ -63,6 +63,7 @@
String androidGmavenR8Workspace = config.getPath("android_gmaven_r8").getPathString();
String localConfigPlatformWorkspace =
config.getPath("local_config_platform_workspace").getPathString();
+ String appleSupport = config.getPath("build_bazel_apple_support").getPathString();
return ImmutableList.of(
"# __SKIP_WORKSPACE_PREFIX__",
@@ -85,6 +86,7 @@
"local_repository(name = 'rules_java', path = '" + rulesJavaWorkspace + "')",
"local_repository(name = 'rules_java_builtin', path = '" + rulesJavaWorkspace + "')",
"local_repository(name = 'android_gmaven_r8', path = '" + androidGmavenR8Workspace + "')",
+ "local_repository(name = 'build_bazel_apple_support', path = '" + appleSupport + "')",
"register_toolchains('@rules_java//java/toolchains/runtime:all')",
"register_toolchains('@rules_java//java/toolchains/javac:all')",
"bind(name = 'android/sdk', actual='@bazel_tools//tools/android:sdk')",
@@ -111,7 +113,8 @@
"local_config_xcode",
"platforms",
"rules_java",
- "rules_java_builtin");
+ "rules_java_builtin",
+ "build_bazel_apple_support");
}
@Override
@@ -138,6 +141,7 @@
"local_config_platform_workspace/WORKSPACE", "workspace(name = 'local_config_platform')");
config.create(
"local_config_platform_workspace/MODULE.bazel", "module(name = 'local_config_platform')");
+ config.create("build_bazel_apple_support/WORKSPACE", "workspace(name = 'apple_support')");
config.create("embedded_tools/WORKSPACE", "workspace(name = 'bazel_tools')");
Runfiles runfiles = Runfiles.create();
for (String filename :
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 03a5ae7..6b3ee08 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
@@ -141,7 +141,7 @@
// Any device, simulator or maccatalyst platforms created by Apple tests should consider
// building on one of these targets as parents, to ensure that the proper constraints are set.
config.create(
- TestConstants.CONSTRAINTS_PATH + "/apple/BUILD",
+ TestConstants.APPLE_PLATFORM_PATH + "/BUILD",
"package(default_visibility=['//visibility:public'])",
"licenses(['notice'])",
"platform(",
@@ -157,22 +157,31 @@
" '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "os:ios',",
" '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "cpu:arm64',",
" ],",
- ")",
- "platform(",
- " name = 'ios_x86_64',",
- " constraint_values = [",
- " '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "os:ios',",
- " '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "cpu:x86_64',",
- " ],",
- ")",
- "platform(",
- " name = 'watchos_x86_64',",
- " constraint_values = [",
- " '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "os:watchos',",
- " '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "cpu:x86_64',",
- " ],",
")");
+ String[] simulatorPlatforms = {
+ "platform(",
+ " name = 'ios_x86_64',",
+ " constraint_values = [",
+ " '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "os:ios',",
+ " '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "cpu:x86_64',",
+ " ],",
+ ")",
+ "platform(",
+ " name = 'watchos_x86_64',",
+ " constraint_values = [",
+ " '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "os:watchos',",
+ " '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "cpu:x86_64',",
+ " ],",
+ ")"
+ };
+
+ if (TestConstants.PRODUCT_NAME.equals("bazel")) {
+ config.append(TestConstants.APPLE_PLATFORM_PATH + "/BUILD", simulatorPlatforms);
+ } else {
+ config.create(TestConstants.APPLE_PLATFORM_PATH + "/simulator/BUILD", simulatorPlatforms);
+ }
+
for (String tool : ImmutableSet.of("objc_dummy.mm", "gcov", "testrunner", "mcov", "libtool")) {
config.create(TestConstants.TOOLS_REPOSITORY_SCRATCH + "tools/objc/" + tool);
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ApplePlatformsToolchainSelectionTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ApplePlatformsToolchainSelectionTest.java
index f479cc3..d08b7ba 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/ApplePlatformsToolchainSelectionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ApplePlatformsToolchainSelectionTest.java
@@ -59,7 +59,7 @@
// Verify the macOS platform.
ConfiguredTarget darwinPlatform =
- getConfiguredTarget(TestConstants.CONSTRAINTS_PACKAGE_ROOT + "apple:darwin_x86_64");
+ getConfiguredTarget(TestConstants.APPLE_PLATFORM_PACKAGE_ROOT + ":darwin_x86_64");
PlatformInfo darwinPlatformInfo = PlatformProviderUtils.platform(darwinPlatform);
assertThat(darwinPlatformInfo).isNotNull();
}
@@ -81,7 +81,7 @@
// Verify the iOS 64 bit device platform.
ConfiguredTarget iosDevicePlatform =
- getConfiguredTarget(TestConstants.CONSTRAINTS_PACKAGE_ROOT + "apple:ios_arm64");
+ getConfiguredTarget(TestConstants.APPLE_PLATFORM_PACKAGE_ROOT + ":ios_arm64");
PlatformInfo iosDevicePlatformInfo = PlatformProviderUtils.platform(iosDevicePlatform);
assertThat(iosDevicePlatformInfo).isNotNull();
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryTest.java
index d071df3..192bff4 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryTest.java
@@ -20,7 +20,6 @@
import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.packages.util.MockJ2ObjcSupport;
-import com.google.devtools.build.lib.packages.util.MockObjcSupport;
import com.google.devtools.build.lib.packages.util.MockProtoSupport;
import com.google.devtools.build.lib.testutil.TestConstants;
import java.util.Collection;
@@ -74,7 +73,6 @@
" name = 'transpile',",
" tags = ['__J2OBJC_LIBRARY_MIGRATION_DO_NOT_USE_WILL_BREAK__'],",
" deps = ['test'])");
- MockObjcSupport.setup(mockToolsConfig);
MockJ2ObjcSupport.setup(mockToolsConfig);
MockProtoSupport.setup(mockToolsConfig);
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBuildVariablesTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBuildVariablesTest.java
index a0b7003..f752f01 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBuildVariablesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBuildVariablesTest.java
@@ -74,7 +74,6 @@
@Test
public void testAppleBuildVariablesIos() throws Exception {
- MockObjcSupport.setup(mockToolsConfig);
useConfiguration(
"--crosstool_top=//tools/osx/crosstool", "--xcode_version=5.8",
"--ios_minimum_os=12.345", "--watchos_minimum_os=11.111",
@@ -145,7 +144,6 @@
@Test
public void testDefaultBuildVariablesIos() throws Exception {
- MockObjcSupport.setup(mockToolsConfig);
useConfiguration(
"--apple_platform_type=ios", "--crosstool_top=//tools/osx/crosstool", "--cpu=ios_x86_64");
scratch.file(
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java
index 20a3b80..8e74338 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java
@@ -136,29 +136,6 @@
+ "bin/";
}
- /**
- * Returns the genfiles dir for artifacts built for a given Apple architecture and minimum OS
- * version (as set by a configuration transition) and configuration distinguisher but the global
- * default for {@code --cpu}.
- *
- * @param arch the given Apple architecture which artifacts are built under this configuration.
- * Note this will likely be different than the value of {@code --cpu}.
- * @param configurationDistinguisher the configuration distinguisher used to describe the a
- * configuration transition
- * @param minOsVersion the minimum os version for which to compile artifacts in the configuration
- */
- protected String configurationGenfiles(
- String arch,
- ConfigurationDistinguisher configurationDistinguisher,
- DottedVersion minOsVersion) {
- return configurationDir(
- arch, configurationDistinguisher, minOsVersion, CompilationMode.FASTBUILD)
- + getTargetConfiguration()
- .getGenfilesDirectory(RepositoryName.MAIN)
- .getExecPath()
- .getBaseName();
- }
-
@SuppressWarnings("MissingCasesInEnumSwitch")
private String configurationDir(
String arch,
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
index 4a6659c..f89e204 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
@@ -140,7 +140,8 @@
+ " - deps(" + TOOLS_REPOSITORY + "//tools/cpp:current_cc_toolchain)"
+ " - deps(" + TOOLS_REPOSITORY + "//tools/cpp:grep-includes)";
- public static final String PLATFORM_PACKAGE_ROOT = "@bazel_tools//platforms";
+ public static final String APPLE_PLATFORM_PATH = "build_bazel_apple_support/platforms";
+ public static final String APPLE_PLATFORM_PACKAGE_ROOT = "@build_bazel_apple_support//platforms";
public static final String CONSTRAINTS_PACKAGE_ROOT = "@platforms//";
public static final String LOCAL_CONFIG_PLATFORM_PACKAGE_ROOT =
"@local_config_platform//";