Skip to content

Commit

Permalink
Make MockPlatformSupport more flexible, and clean up uses of @bazel_t…
Browse files Browse the repository at this point in the history
…ools//platforms in tests.

PiperOrigin-RevId: 359280438
  • Loading branch information
katre authored and copybara-github committed Feb 24, 2021
1 parent 0b1e612 commit 37ea3d5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ cc_toolchain_config(
toolchain(
name = "%toolchainName%_toolchain",
target_compatible_with = [
"@bazel_tools//platforms:android",
"@bazel_tools//platforms:%platform_cpu%",
"@platforms//os:android",
"@platforms//cpu:%platform_cpu%",
],
toolchain = "@androidndk//:%toolchainName%",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
<p>Each <code>constraint_value</code> in this list must be for a different
<code>constraint_setting</code>. For example, you cannot define a platform that requires the
cpu architecture to be both <code>@platforms//cpu:x86_64</code> and
<code>@bazel_tools//platforms:arm</code>.
<code>@platforms//cpu:arm</code>.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
attr(CONSTRAINT_VALUES_ATTR, BuildType.LABEL_LIST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,28 @@ public class MockPlatformSupport {

/** Adds mocks for basic host and target platform. */
public static void setup(MockToolsConfig mockToolsConfig) throws IOException {
setup(
mockToolsConfig,
TestConstants.PLATFORM_PACKAGE_ROOT,
TestConstants.PLATFORMS_PATH,
TestConstants.CONSTRAINTS_PACKAGE_ROOT,
TestConstants.CONSTRAINTS_PATH);
}

/** Adds mocks for basic host and target platform. */
public static void setup(
MockToolsConfig mockToolsConfig,
String platformPackageRoot,
String platformsPath,
String constraintsPackageRoot,
String constraintsPath)
throws IOException {
mockToolsConfig.create(
TestConstants.CONSTRAINTS_PATH + "/BUILD",
constraintsPath + "/BUILD",
"package(default_visibility=['//visibility:public'])",
"licenses(['notice'])");
mockToolsConfig.create(
TestConstants.CONSTRAINTS_PATH + "/cpu/BUILD",
constraintsPath + "/cpu/BUILD",
"package(default_visibility=['//visibility:public'])",
"licenses(['notice'])",
"constraint_setting(name = 'cpu')",
Expand Down Expand Up @@ -57,7 +73,7 @@ public static void setup(MockToolsConfig mockToolsConfig) throws IOException {
" constraint_setting = ':cpu',",
")");
mockToolsConfig.create(
TestConstants.CONSTRAINTS_PATH + "/os/BUILD",
constraintsPath + "/os/BUILD",
"package(default_visibility=['//visibility:public'])",
"licenses(['notice'])",
"constraint_setting(name = 'os')",
Expand Down Expand Up @@ -90,32 +106,30 @@ public static void setup(MockToolsConfig mockToolsConfig) throws IOException {
" constraint_setting = ':os',",
")");
mockToolsConfig.create(
TestConstants.PLATFORMS_PATH + "/BUILD",
platformsPath + "/BUILD",
"package(default_visibility=['//visibility:public'])",
"constraint_setting(name = 'os')",
"constraint_value(name = 'android', constraint_setting = ':os')",
"platform(",
" name = 'default_target',",
" constraint_values = [",
// Regardless of the actual machine the tests are run on, hardcode everything to a single
// default value for simplicity.
" '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "cpu:x86_64',",
" '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "os:linux',",
" '" + TestConstants.PLATFORM_PACKAGE_ROOT + "/java/constraints:jdk11',",
" '" + TestConstants.PLATFORM_PACKAGE_ROOT + "/java/constraints:java8',",
" '" + constraintsPackageRoot + "cpu:x86_64',",
" '" + constraintsPackageRoot + "os:linux',",
" '" + platformPackageRoot + "/java/constraints:jdk11',",
" '" + platformPackageRoot + "/java/constraints:java8',",
" ],",
")",
"platform(",
" name = 'default_host',",
" constraint_values = [",
" '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "cpu:x86_64',",
" '" + TestConstants.CONSTRAINTS_PACKAGE_ROOT + "os:linux',",
" '" + TestConstants.PLATFORM_PACKAGE_ROOT + "/java/constraints:jdk11',",
" '" + TestConstants.PLATFORM_PACKAGE_ROOT + "/java/constraints:java8',",
" '" + constraintsPackageRoot + "cpu:x86_64',",
" '" + constraintsPackageRoot + "os:linux',",
" '" + platformPackageRoot + "/java/constraints:jdk11',",
" '" + platformPackageRoot + "/java/constraints:java8',",
" ],",
")");
mockToolsConfig.create(
TestConstants.PLATFORMS_PATH + "/java/constraints/BUILD",
platformsPath + "/java/constraints/BUILD",
"package(default_visibility = ['//visibility:public'])",
"constraint_setting(name = 'runtime')",
"constraint_value(",
Expand Down
2 changes: 1 addition & 1 deletion tools/android/android_sdk_repository_template.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def create_android_sdk_rules(
toolchain_type = "@bazel_tools//tools/android:sdk_toolchain_type",
exec_compatible_with = HOST_CONSTRAINTS,
target_compatible_with = [
"@bazel_tools//platforms:android",
"@platforms//os:android",
],
toolchain = ":sdk-%d" % api_level,
)
Expand Down

0 comments on commit 37ea3d5

Please sign in to comment.