MockToolsConfig now enforces relative path args.
In MockToolsConfig, all rootDirectory.getRelative
calls except the one in the ctor (and in getPath)
are replaced with a call to getPath, because this
standardizes all path lookups.
The ctor's call is legitimate and remains, because
it converts an absolute path string to a Path
object and there's no other way to do that.
Also, MockToolsConfig.getPath now validates that
its argument is a relative path, because that's
what the function expects (according to the
variable name) and because that's how we can
support real (not in-memory) filesystems.
Finally, fix call sites that passed absolute paths
(e.g. create("/local_config_xcode/WORKSPACE")) to
pass a relative path instead, again because that's
how we can use a real filesystem. (All paths will
be made relative to the FileSystem's root
directory.)
RELNOTES: none
PiperOrigin-RevId: 294155732
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 022066a..de5643e 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
@@ -67,18 +67,20 @@
@Override
public List<String> getWorkspaceContents(MockToolsConfig config) {
- String bazelToolWorkspace = config.getPath("/bazel_tools_workspace").getPathString();
- String bazelPlatformsWorkspace = config.getPath("/platforms").getPathString();
- String rulesJavaWorkspace = config.getPath("/rules_java_workspace").getPathString();
+ String xcodeWorkspace = config.getPath("local_config_xcode_workspace").getPathString();
+ String protobufWorkspace = config.getPath("protobuf_workspace").getPathString();
+ String bazelToolWorkspace = config.getPath("bazel_tools_workspace").getPathString();
+ String bazelPlatformsWorkspace = config.getPath("platforms_workspace").getPathString();
+ String rulesJavaWorkspace = config.getPath("rules_java_workspace").getPathString();
String localConfigPlatformWorkspace =
- config.getPath("/local_config_platform_workspace").getPathString();
+ config.getPath("local_config_platform_workspace").getPathString();
return new ArrayList<>(
ImmutableList.of(
"local_repository(name = 'bazel_tools', path = '" + bazelToolWorkspace + "')",
"local_repository(name = 'platforms', path = '" + bazelPlatformsWorkspace + "')",
- "local_repository(name = 'local_config_xcode', path = '/local_config_xcode')",
- "local_repository(name = 'com_google_protobuf', path = '/protobuf')",
+ "local_repository(name = 'local_config_xcode', path = '" + xcodeWorkspace + "')",
+ "local_repository(name = 'com_google_protobuf', path = '" + protobufWorkspace + "')",
"local_repository(name = 'rules_java', path = '" + rulesJavaWorkspace + "')",
"register_toolchains('@rules_java//java/toolchains/runtime:all')",
"register_toolchains('@rules_java//java/toolchains/javac:all')",
@@ -100,15 +102,17 @@
@Override
public void setupMockClient(MockToolsConfig config, List<String> workspaceContents)
throws IOException {
- config.create("/local_config_xcode/BUILD", "xcode_config(name = 'host_xcodes')");
+ config.create("local_config_xcode_workspace/BUILD", "xcode_config(name = 'host_xcodes')");
config.create(
- "/protobuf/BUILD", "licenses(['notice'])", "exports_files(['protoc', 'cc_toolchain'])");
- config.create("/local_config_xcode/WORKSPACE");
- config.create("/protobuf/WORKSPACE");
- config.overwrite("WORKSPACE", workspaceContents.toArray(new String[workspaceContents.size()]));
+ "protobuf_workspace/BUILD",
+ "licenses(['notice'])",
+ "exports_files(['protoc', 'cc_toolchain'])");
+ config.create("local_config_xcode_workspace/WORKSPACE");
+ config.create("protobuf_workspace/WORKSPACE");
+ config.overwrite("WORKSPACE", workspaceContents.toArray(new String[0]));
/** The rest of platforms is initialized in {@link MockPlatformSupport}. */
- config.create("/platforms/WORKSPACE", "workspace(name = 'platforms')");
- config.create("/bazel_tools_workspace/WORKSPACE", "workspace(name = 'bazel_tools')");
+ config.create("platforms_workspace/WORKSPACE", "workspace(name = 'platforms')");
+ config.create("bazel_tools_workspace/WORKSPACE", "workspace(name = 'bazel_tools')");
Runfiles runfiles = Runfiles.create();
for (String filename : Arrays.asList("tools/jdk/java_toolchain_alias.bzl")) {
java.nio.file.Path path = Paths.get(runfiles.rlocation("io_bazel/" + filename));
@@ -116,10 +120,10 @@
continue; // the io_bazel workspace root only exists for Bazel
}
config.create(
- "/bazel_tools_workspace/" + filename, MoreFiles.asCharSource(path, UTF_8).read());
+ "bazel_tools_workspace/" + filename, MoreFiles.asCharSource(path, UTF_8).read());
}
config.create(
- "/bazel_tools_workspace/tools/jdk/BUILD",
+ "bazel_tools_workspace/tools/jdk/BUILD",
"load(",
" ':java_toolchain_alias.bzl',",
" 'java_toolchain_alias',",
@@ -208,17 +212,16 @@
ImmutableList<String> androidBuildContents = createAndroidBuildContents();
config.create(
- "/bazel_tools_workspace/tools/android/BUILD",
- androidBuildContents.toArray(new String[androidBuildContents.size()]));
+ "bazel_tools_workspace/tools/android/BUILD", androidBuildContents.toArray(new String[0]));
config.create(
- "/bazel_tools_workspace/tools/android/emulator/BUILD",
+ "bazel_tools_workspace/tools/android/emulator/BUILD",
Iterables.toArray(createToolsAndroidEmulatorContents(), String.class));
config.create(
- "/bazel_tools_workspace/tools/genrule/BUILD", "exports_files(['genrule-setup.sh'])");
+ "bazel_tools_workspace/tools/genrule/BUILD", "exports_files(['genrule-setup.sh'])");
config.create(
- "/bazel_tools_workspace/tools/test/BUILD",
+ "bazel_tools_workspace/tools/test/BUILD",
"filegroup(name = 'runtime', srcs = ['test-setup.sh', 'test-xml-generator.sh'])",
"filegroup(name = 'test_wrapper', srcs = ['test_wrapper_bin'])",
"filegroup(name = 'xml_writer', srcs = ['xml_writer_bin'])",
@@ -232,7 +235,7 @@
// Use an alias package group to allow for modification at the simpler path
config.create(
- "/bazel_tools_workspace/tools/whitelists/config_feature_flag/BUILD",
+ "bazel_tools_workspace/tools/whitelists/config_feature_flag/BUILD",
"package_group(",
" name='config_feature_flag',",
" includes=['@//tools/whitelists/config_feature_flag'],",
@@ -247,24 +250,24 @@
"package_group(name='config_feature_flag', packages=['//...'])");
config.create(
- "/bazel_tools_workspace/tools/zip/BUILD",
+ "bazel_tools_workspace/tools/zip/BUILD",
"package(default_visibility=['//visibility:public'])",
"exports_files(['precompile.py'])",
"cc_binary(name='zipper', srcs=['zip_main.cc'])");
config.create(
- "/bazel_tools_workspace/tools/launcher/BUILD",
+ "bazel_tools_workspace/tools/launcher/BUILD",
"package(default_visibility=['//visibility:public'])",
"load('@bazel_tools//third_party/cc_rules/macros:defs.bzl', 'cc_binary')",
"cc_binary(name='launcher', srcs=['launcher_main.cc'])");
config.create(
- "/bazel_tools_workspace/tools/def_parser/BUILD",
+ "bazel_tools_workspace/tools/def_parser/BUILD",
"package(default_visibility=['//visibility:public'])",
"filegroup(name='def_parser', srcs=['def_parser.exe'])");
config.create(
- "/bazel_tools_workspace/objcproto/BUILD",
+ "bazel_tools_workspace/objcproto/BUILD",
"package(default_visibility=['//visibility:public'])",
"objc_library(",
" name = 'protobuf_lib',",
@@ -277,14 +280,14 @@
" name = 'well_known_type_proto',",
" srcs = ['well_known_type.proto'],",
")");
- config.create("/bazel_tools_workspace/objcproto/empty.m");
- config.create("/bazel_tools_workspace/objcproto/empty.cc");
- config.create("/bazel_tools_workspace/objcproto/well_known_type.proto");
+ config.create("bazel_tools_workspace/objcproto/empty.m");
+ config.create("bazel_tools_workspace/objcproto/empty.cc");
+ config.create("bazel_tools_workspace/objcproto/well_known_type.proto");
- config.create("/rules_java_workspace/WORKSPACE", "workspace(name = 'rules_java')");
- config.create("/rules_java_workspace/java/BUILD");
+ config.create("rules_java_workspace/WORKSPACE", "workspace(name = 'rules_java')");
+ config.create("rules_java_workspace/java/BUILD");
config.create(
- "/rules_java_workspace/java/defs.bzl",
+ "rules_java_workspace/java/defs.bzl",
"def java_binary(**attrs):",
" native.java_binary(**attrs)",
"def java_library(**attrs):",
@@ -292,14 +295,14 @@
"def java_import(**attrs):",
" native.java_import(**attrs)");
config.create(
- "/rules_java_workspace/java/repositories.bzl",
+ "rules_java_workspace/java/repositories.bzl",
"def rules_java_dependencies():",
" pass",
"def rules_java_toolchains():",
" pass");
config.create(
- "/rules_java_workspace/java/toolchains/runtime/BUILD",
+ "rules_java_workspace/java/toolchains/runtime/BUILD",
"toolchain_type(name = 'toolchain_type')",
"toolchain(",
" name = 'local_jdk',",
@@ -307,7 +310,7 @@
" toolchain_type = '@rules_java//java/toolchains/runtime:toolchain_type',",
" )");
config.create(
- "/rules_java_workspace/java/toolchains/javac/BUILD",
+ "rules_java_workspace/java/toolchains/javac/BUILD",
"toolchain_type(name = 'toolchain_type')",
"toolchain(",
" name = 'javac_toolchain',",
@@ -419,15 +422,15 @@
@Override
public void setupMockToolsRepository(MockToolsConfig config) throws IOException {
- config.create("/bazel_tools_workspace/WORKSPACE", "workspace(name = 'bazel_tools')");
- config.create("/bazel_tools_workspace/tools/build_defs/repo/BUILD");
+ config.create("bazel_tools_workspace/WORKSPACE", "workspace(name = 'bazel_tools')");
+ config.create("bazel_tools_workspace/tools/build_defs/repo/BUILD");
config.create(
- "/bazel_tools_workspace/tools/build_defs/repo/utils.bzl",
+ "bazel_tools_workspace/tools/build_defs/repo/utils.bzl",
"def maybe(repo_rule, name, **kwargs):",
" if name not in native.existing_rules():",
" repo_rule(name = name, **kwargs)");
config.create(
- "/bazel_tools_workspace/tools/build_defs/repo/http.bzl",
+ "bazel_tools_workspace/tools/build_defs/repo/http.bzl",
"def http_archive(**kwargs):",
" pass",
"",
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
index c8d503a..18fe94c 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
@@ -234,15 +234,15 @@
actionKeyContext = new ActionKeyContext();
mockToolsConfig = new MockToolsConfig(rootDirectory, false);
- mockToolsConfig.create("/bazel_tools_workspace/WORKSPACE", "workspace(name = 'bazel_tools')");
- mockToolsConfig.create("/bazel_tools_workspace/tools/build_defs/repo/BUILD");
+ mockToolsConfig.create("bazel_tools_workspace/WORKSPACE", "workspace(name = 'bazel_tools')");
+ mockToolsConfig.create("bazel_tools_workspace/tools/build_defs/repo/BUILD");
mockToolsConfig.create(
- "/bazel_tools_workspace/tools/build_defs/repo/utils.bzl",
+ "bazel_tools_workspace/tools/build_defs/repo/utils.bzl",
"def maybe(repo_rule, name, **kwargs):",
" if name not in native.existing_rules():",
" repo_rule(name = name, **kwargs)");
mockToolsConfig.create(
- "/bazel_tools_workspace/tools/build_defs/repo/http.bzl",
+ "bazel_tools_workspace/tools/build_defs/repo/http.bzl",
"def http_archive(**kwargs):",
" pass",
"",
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java
index 3ed7d1a..1956036 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java
@@ -111,15 +111,15 @@
analysisMock.getProductName());
mockToolsConfig = new MockToolsConfig(rootDirectory);
- mockToolsConfig.create("/bazel_tools_workspace/WORKSPACE", "workspace(name = 'bazel_tools')");
- mockToolsConfig.create("/bazel_tools_workspace/tools/build_defs/repo/BUILD");
+ mockToolsConfig.create("bazel_tools_workspace/WORKSPACE", "workspace(name = 'bazel_tools')");
+ mockToolsConfig.create("bazel_tools_workspace/tools/build_defs/repo/BUILD");
mockToolsConfig.create(
- "/bazel_tools_workspace/tools/build_defs/repo/utils.bzl",
+ "bazel_tools_workspace/tools/build_defs/repo/utils.bzl",
"def maybe(repo_rule, name, **kwargs):",
" if name not in native.existing_rules():",
" repo_rule(name = name, **kwargs)");
mockToolsConfig.create(
- "/bazel_tools_workspace/tools/build_defs/repo/http.bzl",
+ "bazel_tools_workspace/tools/build_defs/repo/http.bzl",
"def http_archive(**kwargs):",
" pass",
"",
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryTest.java
index c07889f..1884484 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryTest.java
@@ -48,14 +48,14 @@
@Before
public void setup() throws Exception {
BazelMockCcSupport.INSTANCE.setup(mockToolsConfig);
- scratch.overwriteFile("/bazel_tools_workspace/tools/build_defs/cc/BUILD");
+ scratch.overwriteFile("bazel_tools_workspace/tools/build_defs/cc/BUILD");
scratch.overwriteFile(
- "/bazel_tools_workspace/tools/build_defs/cc/action_names.bzl",
+ "bazel_tools_workspace/tools/build_defs/cc/action_names.bzl",
ResourceLoader.readFromResources(
TestConstants.RULES_CC_REPOSITORY_EXECROOT + "cc/action_names.bzl"));
scratch.overwriteFile(
- "/bazel_tools_workspace/tools/cpp/cc_toolchain_config_lib.bzl",
+ "bazel_tools_workspace/tools/cpp/cc_toolchain_config_lib.bzl",
ResourceLoader.readFromResources(
TestConstants.RULES_CC_REPOSITORY_EXECROOT + "cc/cc_toolchain_config_lib.bzl"));
scratch.file("/ndk/source.properties", "Pkg.Desc = Android NDK", "Pkg.Revision = 13.1.3345770");
@@ -72,9 +72,10 @@
@Test
public void testApiLevelHighestVersionDetection() throws Exception {
scratchPlatformsDirectories("arch-x86", 19, 20, 22, 24);
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_ndk_repository(",
" name = 'androidndk',",
" path = '/ndk',",
@@ -96,9 +97,10 @@
@Test
public void testInvalidNdkReleaseTxt() throws Exception {
scratchPlatformsDirectories("arch-x86", 24);
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_ndk_repository(",
" name = 'androidndk',",
" path = '/ndk',",
@@ -121,9 +123,10 @@
@Test
public void testInvalidNdkSourceProperties() throws Exception {
scratchPlatformsDirectories("arch-x86", 24);
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_ndk_repository(",
" name = 'androidndk',",
" path = '/ndk',",
@@ -148,9 +151,10 @@
@Test
public void testUnsupportedNdkVersion() throws Exception {
scratchPlatformsDirectories("arch-x86", 24);
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_ndk_repository(",
" name = 'androidndk',",
" path = '/ndk',",
@@ -175,9 +179,10 @@
scratchPlatformsDirectories("arch-x86", 19, 20, 22, 24);
scratch.file(String.format("/ndk/sources/android/cpufeatures/cpu-features.c"));
scratch.file(String.format("/ndk/sources/android/cpufeatures/cpu-features.h"));
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_ndk_repository(",
" name = 'androidndk',",
" path = '/ndk',",
@@ -198,9 +203,10 @@
@Test
public void testMissingPlatformsDirectory() throws Exception {
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_ndk_repository(",
" name = 'androidndk',",
" path = '/ndk',",
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java
index cdce62a..f044336 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java
@@ -36,7 +36,7 @@
@Before
public void setup() throws Exception {
scratch.file(
- "/bazel_tools_workspace/tools/android/android_sdk_repository_template.bzl",
+ "bazel_tools_workspace/tools/android/android_sdk_repository_template.bzl",
ResourceLoader.readFromResources("tools/android/android_sdk_repository_template.bzl"));
}
@@ -84,8 +84,10 @@
scratchPlatformsDirectories(25);
scratchBuildToolsDirectories("26.0.1");
scratchExtrasLibrary("extras/google/m2repository", "com.google.android", "foo", "1.0.0", "aar");
- FileSystemUtils.appendIsoLatin1(scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
+ FileSystemUtils.appendIsoLatin1(
+ scratch.resolve("WORKSPACE"),
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
@@ -104,8 +106,10 @@
scratchPlatformsDirectories(25);
scratchBuildToolsDirectories("26.0.1");
scratchExtrasLibrary("extras/google/m2repository", "com.google.android", "foo", "1.0.0", "aar");
- FileSystemUtils.appendIsoLatin1(scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
+ FileSystemUtils.appendIsoLatin1(
+ scratch.resolve("WORKSPACE"),
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
@@ -124,8 +128,10 @@
scratchExtrasLibrary("extras/google/m2repository", "com.google.android", "a", "1.0.0", "jar");
scratchExtrasLibrary("extras/android/m2repository", "com.android.support", "b", "1.0.0", "aar");
scratchExtrasLibrary("extras/m2repository", "com.android.support", "c", "1.0.1", "aar");
- FileSystemUtils.appendIsoLatin1(scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
+ FileSystemUtils.appendIsoLatin1(
+ scratch.resolve("WORKSPACE"),
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
@@ -150,8 +156,10 @@
public void testSystemImageDirectoriesAreFound() throws Exception {
scratchPlatformsDirectories(25);
scratchBuildToolsDirectories("26.0.1");
- FileSystemUtils.appendIsoLatin1(scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
+ FileSystemUtils.appendIsoLatin1(
+ scratch.resolve("WORKSPACE"),
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
@@ -184,8 +192,10 @@
scratchPlatformsDirectories(25, 26);
scratchBuildToolsDirectories("26.0.1");
scratchSystemImagesDirectories("android-25/default/armeabi-v7a", "android-O/google_apis/x86");
- FileSystemUtils.appendIsoLatin1(scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
+ FileSystemUtils.appendIsoLatin1(
+ scratch.resolve("WORKSPACE"),
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
@@ -198,9 +208,10 @@
public void testBuildToolsHighestVersionDetection() throws Exception {
scratchPlatformsDirectories(25);
scratchBuildToolsDirectories("26.0.1", "26.0.2");
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
@@ -218,9 +229,10 @@
public void testApiLevelHighestVersionDetection() throws Exception {
scratchPlatformsDirectories(24, 25, 23);
scratchBuildToolsDirectories("26.0.1");
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
@@ -239,9 +251,10 @@
int[] apiLevels = {23, 24, 25};
scratchPlatformsDirectories(apiLevels);
scratchBuildToolsDirectories("26.0.1");
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
@@ -263,9 +276,10 @@
public void testMissingApiLevel() throws Exception {
scratchPlatformsDirectories(24);
scratchBuildToolsDirectories("26.0.1");
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
@@ -292,8 +306,10 @@
scratchPlatformsDirectories(24);
scratchBuildToolsDirectories("26.0.1");
scratch.file("/sdk/system-images/.DS_Store");
- FileSystemUtils.appendIsoLatin1(scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
+ FileSystemUtils.appendIsoLatin1(
+ scratch.resolve("WORKSPACE"),
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
@@ -306,9 +322,10 @@
@Test
public void testMissingPlatformsDirectory() throws Exception {
scratchBuildToolsDirectories("26.0.1");
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
@@ -328,9 +345,10 @@
@Test
public void testMissingBuildToolsDirectory() throws Exception {
scratchPlatformsDirectories(24);
+ String bazelToolsWorkspace = scratch.dir("bazel_tools_workspace").getPathString();
FileSystemUtils.appendIsoLatin1(
scratch.resolve("WORKSPACE"),
- "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')",
+ "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')",
"android_sdk_repository(",
" name = 'androidsdk',",
" path = '/sdk',",
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 f02c256..033ef7c 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
@@ -82,7 +82,7 @@
@Override
public String getMockCrosstoolPath() {
- return "/bazel_tools_workspace/tools/cpp/";
+ return "bazel_tools_workspace/tools/cpp/";
}
@Override
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 255a1b9..146fc86 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
@@ -51,6 +51,7 @@
if (!realFileSystem) {
this.runfilesDirectory = null;
} else if (runfilesDirectoryOpt == null) {
+ // Turning the absolute path string from runfilesDir into a Path object.
this.runfilesDirectory = rootDirectory.getRelative(BlazeTestUtils.runfilesDir());
} else {
this.runfilesDirectory = runfilesDirectoryOpt;
@@ -62,11 +63,12 @@
}
public Path getPath(String relativePath) {
+ Preconditions.checkState(!relativePath.startsWith("/"), relativePath);
return rootDirectory.getRelative(relativePath);
}
public Path create(String relativePath, String... lines) throws IOException {
- Path path = rootDirectory.getRelative(relativePath);
+ Path path = getPath(relativePath);
if (!path.exists()) {
FileSystemUtils.writeIsoLatin1(path, lines);
} else if (lines.length > 0) {
@@ -93,7 +95,7 @@
}
public Path overwrite(String relativePath, String... lines) throws IOException {
- Path path = rootDirectory.getRelative(relativePath);
+ Path path = getPath(relativePath);
if (path.exists()) {
path.deleteTree();
}
@@ -101,7 +103,7 @@
}
public Path append(String relativePath, String... lines) throws IOException {
- Path path = rootDirectory.getRelative(relativePath);
+ Path path = getPath(relativePath);
if (!path.exists()) {
return create(relativePath, lines);
}
@@ -144,15 +146,14 @@
// In some cases we run tests in a special client with a ../READONLY/ path where we may also
// find the runfiles. Try that, too.
Path readOnlyClientPath =
- rootDirectory.getRelative(
- "../READONLY/" + TestConstants.WORKSPACE_NAME + "/" + relativePath);
+ getPath("../READONLY/" + TestConstants.WORKSPACE_NAME + "/" + relativePath);
if (!readOnlyClientPath.exists()) {
throw new IOException("target does not exist " + target);
} else {
target = readOnlyClientPath;
}
}
- Path path = rootDirectory.getRelative(dest);
+ Path path = getPath(dest);
FileSystemUtils.createDirectoryAndParents(path.getParentDirectory());
path.delete();
path.createSymbolicLink(target);
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProviderTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProviderTest.java
index 071fffb..7daf7f3 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProviderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProviderTest.java
@@ -70,9 +70,9 @@
return;
}
- mockToolsConfig.create("/protobuf/WORKSPACE");
+ mockToolsConfig.create("protobuf_workspace/WORKSPACE");
mockToolsConfig.overwrite(
- "/protobuf/BUILD",
+ "protobuf_workspace/BUILD",
TestConstants.LOAD_PROTO_LANG_TOOLCHAIN,
"package(default_visibility=['//visibility:public'])",
"exports_files(['protoc'])",
@@ -86,7 +86,7 @@
new String(FileSystemUtils.readContentAsLatin1(rootDirectory.getRelative("WORKSPACE")));
mockToolsConfig.overwrite(
"WORKSPACE",
- "local_repository(name = 'com_google_protobuf', path = '/protobuf/')",
+ "local_repository(name = 'com_google_protobuf', path = 'protobuf_workspace/')",
existingWorkspace);
invalidatePackages(); // A dash of magic to re-evaluate the WORKSPACE file.
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 6b64869..e972cad 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
@@ -104,7 +104,7 @@
/** The workspace repository label under which built-in tools reside. */
public static final String TOOLS_REPOSITORY = "@bazel_tools";
/** The file path in which to create files so that they end up under {@link #TOOLS_REPOSITORY}. */
- public static final String TOOLS_REPOSITORY_SCRATCH = "/bazel_tools_workspace/";
+ public static final String TOOLS_REPOSITORY_SCRATCH = "bazel_tools_workspace/";
/** The output file path prefix for tool file dependencies. */
public static final String TOOLS_REPOSITORY_PATH_PREFIX = "external/bazel_tools/";
@@ -114,7 +114,7 @@
/**
* The file path in which to create files so that they end up under {@link #RULES_CC_REPOSITORY}.
*/
- public static final String RULES_CC_REPOSITORY_SCRATCH = "/rules_cc_workspace/";
+ public static final String RULES_CC_REPOSITORY_SCRATCH = "rules_cc_workspace/";
/** The directory in which rules_cc repo resides in execroot. */
public static final String RULES_CC_REPOSITORY_EXECROOT = "external/rules_cc/";
@@ -158,9 +158,9 @@
public static final String PLATFORM_PACKAGE_ROOT = "@bazel_tools//platforms";
public static final String CONSTRAINTS_PACKAGE_ROOT = "@platforms//";
- public static final String PLATFORMS_PATH = "/bazel_tools_workspace/platforms";
- public static final String CONSTRAINTS_PATH = "/platforms";
- public static final String LOCAL_CONFIG_PLATFORM_PATH = "/local_config_platform_workspace";
+ public static final String PLATFORMS_PATH = "bazel_tools_workspace/platforms";
+ public static final String CONSTRAINTS_PATH = "platforms_workspace";
+ public static final String LOCAL_CONFIG_PLATFORM_PATH = "local_config_platform_workspace";
public static final String PLATFORM_LABEL =
PLATFORM_PACKAGE_ROOT + ":default_host + " + PLATFORM_PACKAGE_ROOT + ":default_target";