From a313dcf550429c9f6d46412956682e9b16bc0c33 Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Thu, 18 Jul 2019 13:37:50 -0400 Subject: [PATCH 1/8] Update blackbox tests to use rules_pkg. We add rules_pkg to the default WORKSPACE and then try to use that. Alas, things fail because starlark is getting rid of the outputs attribute, and the test runs with the incompatible changes on. A better solution may be to figure out why we need tar for the repo tests. If we can eliminate that, a lot of problems go away. --- .../framework/BlackBoxTestEnvironment.java | 13 ++++++++- .../BazelEmbeddedSkylarkBlackBoxTest.java | 28 ------------------- .../RepoWithRuleWritingTextGenerator.java | 16 +++++++++-- .../RepoWithRuleWritingTextGeneratorTest.java | 4 +-- 4 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java index 78a4fa0208a37c..91a2182b911aff 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java @@ -89,6 +89,17 @@ public static String getWorkspaceWithDefaultRepos() { " 'https://github.com/bazelbuild/rules_cc/archive/" + "0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip',", " ],", - ")"); + ")", + "http_archive(", + " name = \"rules_pkg\",", + " sha256 = \"5bdc04987af79bd27bc5b00fe30f59a858f77ffa0bd2d8143d5b31ad8b1bd71c\",", + " urls = [", + " \"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/rules_pkg-0.2.0.tar.gz\",", + " \"https://github.com/bazelbuild/rules_pkg/releases/download/0.2.0/rules_pkg-0.2.0.tar.gz\",", + " ],", + ")", + "load(\"@rules_pkg//:deps.bzl\", \"rules_pkg_dependencies\")", + "rules_pkg_dependencies()" + ); } } diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/BazelEmbeddedSkylarkBlackBoxTest.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/BazelEmbeddedSkylarkBlackBoxTest.java index 6dd37a2079f1fb..cfc9ccd9115a6f 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/BazelEmbeddedSkylarkBlackBoxTest.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/BazelEmbeddedSkylarkBlackBoxTest.java @@ -43,34 +43,6 @@ public class BazelEmbeddedSkylarkBlackBoxTest extends AbstractBlackBoxTest { private static final String HELLO_FROM_EXTERNAL_REPOSITORY = "Hello from external repository!"; private static final String HELLO_FROM_MAIN_REPOSITORY = "Hello from main repository!"; - @Test - public void testPkgTar() throws Exception { - context().write("main/WORKSPACE", BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos()); - context().write("main/foo.txt", "Hello World"); - context().write("main/bar.txt", "Hello World, again"); - context() - .write( - "main/BUILD", - "load(\"@bazel_tools//tools/build_defs/pkg:pkg.bzl\", \"pkg_tar\")", - "pkg_tar(name = \"data\", srcs = ['foo.txt', 'bar.txt'],)"); - - BuilderRunner bazel = bazel(); - bazel.build("..."); - - Path dataTarPath = context().resolveBinPath(bazel, "main/data.tar"); - assertThat(Files.exists(dataTarPath)).isTrue(); - - Path directory = decompress(dataTarPath); - assertThat(directory.toFile().exists()).isTrue(); - - Map map = - Arrays.stream(Objects.requireNonNull(directory.toFile().listFiles())) - .collect(Collectors.toMap(File::getName, file -> Paths.get(file.getAbsolutePath()))); - - WorkspaceTestUtils.assertLinesExactly(map.get("foo.txt"), "Hello World"); - WorkspaceTestUtils.assertLinesExactly(map.get("bar.txt"), "Hello World, again"); - } - @Test public void testHttpArchive() throws Exception { Path repo = context().getTmpDir().resolve("ext_repo"); diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java index 32637c3dbb95e6..ef410c3bb29cb4 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java @@ -124,13 +124,25 @@ RepoWithRuleWritingTextGenerator skipBuildFile() { * @throws IOException if was not able to create or write to files */ Path setupRepository() throws IOException { - Path workspace = PathUtils.writeFileInDir(root, "WORKSPACE"); + Path workspace = PathUtils.writeFileInDir(root, "WORKSPACE", + "load(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")", + "http_archive(", + " name = \"rules_pkg\",", + " sha256 = \"5bdc04987af79bd27bc5b00fe30f59a858f77ffa0bd2d8143d5b31ad8b1bd71c\",", + " urls = [", + " \"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/rules_pkg-0.2.0.tar.gz\",", + " \"https://github.com/bazelbuild/rules_pkg/releases/download/0.2.0/rules_pkg-0.2.0.tar.gz\",", + " ],", + ")", + "load(\"@rules_pkg//:deps.bzl\", \"rules_pkg_dependencies\")", + "rules_pkg_dependencies()" + ); PathUtils.writeFileInDir(root, HELPER_FILE, WRITE_TEXT_TO_FILE); if (generateBuildFile) { PathUtils.writeFileInDir( root, "BUILD", - "load(\"@bazel_tools//tools/build_defs/pkg:pkg.bzl\", \"pkg_tar\")", + "load(\"@rules_pkg//:pkg.bzl\", \"pkg_tar\")", loadRule(""), callRule(target, outFile, outputText), String.format("pkg_tar(name = \"%s\", srcs = glob([\"*\"]),)", getPkgTarTarget())); diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGeneratorTest.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGeneratorTest.java index 6a5cd073d37d9f..55ef9381d706ca 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGeneratorTest.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGeneratorTest.java @@ -29,12 +29,12 @@ @RunWith(JUnit4.class) public class RepoWithRuleWritingTextGeneratorTest { private static final String BUILD_TEXT = - "load(\"@bazel_tools//tools/build_defs/pkg:pkg.bzl\", \"pkg_tar\")\n" + "load(\"@rules_pkg//:pkg.bzl\", \"pkg_tar\")\n" + "load('//:helper.bzl', 'write_to_file')\n" + "write_to_file(name = 'write_text', filename = 'out', text ='HELLO')\n" + "pkg_tar(name = \"pkg_tar_write_text\", srcs = glob([\"*\"]),)"; private static final String BUILD_TEXT_PARAMS = - "load(\"@bazel_tools//tools/build_defs/pkg:pkg.bzl\", \"pkg_tar\")\n" + "load(\"@rules_pkg//:pkg.bzl\", \"pkg_tar\")\n" + "load('//:helper.bzl', 'write_to_file')\n" + "write_to_file(name = 'target', filename = 'file', text ='text')\n" + "pkg_tar(name = \"pkg_tar_target\", srcs = glob([\"*\"]),)"; From d25eb3352a79646ed96155013151aa8d5c9f3e77 Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Wed, 11 Mar 2020 12:23:47 -0400 Subject: [PATCH 2/8] add missing , --- .../build/lib/blackbox/framework/BlackBoxTestEnvironment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java index 8102e76f64343a..f3b3393f88e67e 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java @@ -99,7 +99,7 @@ public static String getWorkspaceWithDefaultRepos() { " ],", ")", "load(\"@rules_pkg//:deps.bzl\", \"rules_pkg_dependencies\")", - "rules_pkg_dependencies()" + "rules_pkg_dependencies()", "http_archive(", " name = 'rules_proto',", " sha256 = '602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208',", From 33444dba095f4eabb82bd7a46fa5f92e7e979b22 Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Thu, 12 Mar 2020 23:45:18 -0400 Subject: [PATCH 3/8] Got it down to two tests failing. //src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace:GitRepositoryBlackBoxTest FAILED in 50.5s //src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace:WorkspaceBlackBoxTest FAILED in 68.7s The entire test scheme is wonky, in that it depends on pkg_tar in the first place. Something is going wrong with the indirect loading of the rules via RepoWithRuleWritingTextGenerator --- .../framework/BlackBoxTestEnvironment.java | 14 +++---- .../RepoWithRuleWritingTextGenerator.java | 40 ++++++++++++------- .../RepoWithRuleWritingTextGeneratorTest.java | 8 ++-- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java index f3b3393f88e67e..7557ce696087e7 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java @@ -91,14 +91,14 @@ public static String getWorkspaceWithDefaultRepos() { " ],", ")", "http_archive(", - " name = \"rules_pkg\",", - " sha256 = \"5bdc04987af79bd27bc5b00fe30f59a858f77ffa0bd2d8143d5b31ad8b1bd71c\",", - " urls = [", - " \"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/rules_pkg-0.2.0.tar.gz\",", - " \"https://github.com/bazelbuild/rules_pkg/releases/download/0.2.0/rules_pkg-0.2.0.tar.gz\",", - " ],", + " name = 'rules_pkg',", + " sha256 = '352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a',", + " urls = [", + " 'https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", + " 'https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", + " ],", ")", - "load(\"@rules_pkg//:deps.bzl\", \"rules_pkg_dependencies\")", + "load('@rules_pkg//:deps.bzl', 'rules_pkg_dependencies')", "rules_pkg_dependencies()", "http_archive(", " name = 'rules_proto',", diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java index ef410c3bb29cb4..a8e127c420ae92 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java @@ -124,32 +124,42 @@ RepoWithRuleWritingTextGenerator skipBuildFile() { * @throws IOException if was not able to create or write to files */ Path setupRepository() throws IOException { - Path workspace = PathUtils.writeFileInDir(root, "WORKSPACE", - "load(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")", - "http_archive(", - " name = \"rules_pkg\",", - " sha256 = \"5bdc04987af79bd27bc5b00fe30f59a858f77ffa0bd2d8143d5b31ad8b1bd71c\",", - " urls = [", - " \"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/rules_pkg-0.2.0.tar.gz\",", - " \"https://github.com/bazelbuild/rules_pkg/releases/download/0.2.0/rules_pkg-0.2.0.tar.gz\",", - " ],", - ")", - "load(\"@rules_pkg//:deps.bzl\", \"rules_pkg_dependencies\")", - "rules_pkg_dependencies()" - ); + Path workspace = generateWorkspaceFile(); PathUtils.writeFileInDir(root, HELPER_FILE, WRITE_TEXT_TO_FILE); if (generateBuildFile) { PathUtils.writeFileInDir( root, "BUILD", - "load(\"@rules_pkg//:pkg.bzl\", \"pkg_tar\")", + "load('@rules_pkg//:pkg.bzl', 'pkg_tar')", loadRule(""), callRule(target, outFile, outputText), - String.format("pkg_tar(name = \"%s\", srcs = glob([\"*\"]),)", getPkgTarTarget())); + String.format("pkg_tar(name = '%s', srcs = glob(['*']),)", getPkgTarTarget())); } return workspace.getParent(); } + /** + * Generates the minimal WORKSPACE file for the associated BUILD file. + */ + Path generateWorkspaceFile() throws IOException { + if (generateBuildFile) { + return PathUtils.writeFileInDir(root, "WORKSPACE", + "load('@bazel_tools//tools/build_defs/repo:http.bzl', 'http_archive')", + "http_archive(", + " name = 'rules_pkg',", + " sha256 = '352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a',", + " urls = [", + " 'https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", + " 'https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", + " ],", + ")", + "load('@rules_pkg//:deps.bzl', 'rules_pkg_dependencies')", + "rules_pkg_dependencies()" + ); + } + return PathUtils.writeFileInDir(root, "WORKSPACE"); + } + /** * Returns the text to be put into a header of Starlark file, which is going to use write_to_file * rule from the @repoName repository diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGeneratorTest.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGeneratorTest.java index 55ef9381d706ca..c016c93ccb4471 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGeneratorTest.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGeneratorTest.java @@ -29,15 +29,15 @@ @RunWith(JUnit4.class) public class RepoWithRuleWritingTextGeneratorTest { private static final String BUILD_TEXT = - "load(\"@rules_pkg//:pkg.bzl\", \"pkg_tar\")\n" + "load('@rules_pkg//:pkg.bzl', 'pkg_tar')\n" + "load('//:helper.bzl', 'write_to_file')\n" + "write_to_file(name = 'write_text', filename = 'out', text ='HELLO')\n" - + "pkg_tar(name = \"pkg_tar_write_text\", srcs = glob([\"*\"]),)"; + + "pkg_tar(name = 'pkg_tar_write_text', srcs = glob(['*']),)"; private static final String BUILD_TEXT_PARAMS = - "load(\"@rules_pkg//:pkg.bzl\", \"pkg_tar\")\n" + "load('@rules_pkg//:pkg.bzl', 'pkg_tar')\n" + "load('//:helper.bzl', 'write_to_file')\n" + "write_to_file(name = 'target', filename = 'file', text ='text')\n" - + "pkg_tar(name = \"pkg_tar_target\", srcs = glob([\"*\"]),)"; + + "pkg_tar(name = 'pkg_tar_target', srcs = glob(['*']),)"; @Test public void testOutput() throws IOException { From 404f585e5b903ff5d10dfc50446ad8c8ec264796 Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Tue, 17 Mar 2020 12:46:34 -0400 Subject: [PATCH 4/8] add marker for next bit of work --- .../lib/blackbox/tests/workspace/WorkspaceBlackBoxTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/WorkspaceBlackBoxTest.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/WorkspaceBlackBoxTest.java index 8be762cdfd2b72..af1c5e46abc5b0 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/WorkspaceBlackBoxTest.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/WorkspaceBlackBoxTest.java @@ -167,6 +167,7 @@ public void testWorkspaceChanges() throws Exception { String.format( "local_repository(name = 'x', path = '%s',)", PathUtils.pathForStarlarkFile(repoA))); + // TODO: What we need in WORKSPACE is the deps setup for repoA ...!!!! BuilderRunner bazel = WorkspaceTestUtils.bazel(context()); bazel.build("@x//:" + RepoWithRuleWritingTextGenerator.TARGET); From e9290c2e9a2db35d53df33345c57ffc815d023b4 Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Tue, 21 Apr 2020 23:10:44 -0400 Subject: [PATCH 5/8] After a lot of pain, I got the tests working again. Suggestions for the framework in #11184 --- .../build/lib/blackbox/framework/BUILD | 21 ++++++++++++--- .../framework/BlackBoxTestEnvironment.java | 23 ++++++++-------- .../workspace/GitRepositoryBlackBoxTest.java | 3 +++ .../RepoWithRuleWritingTextGenerator.java | 26 +++---------------- .../workspace/WorkspaceBlackBoxTest.java | 5 +++- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BUILD b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BUILD index 6d4890a871ade0..4a8d244da19bef 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BUILD +++ b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BUILD @@ -12,7 +12,16 @@ java_library( java_library( name = "framework", testonly = 1, - srcs = glob(["*.java"]), + srcs = [ + "BlackBoxTestContext.java", + "BlackBoxTestEnvironment.java", + "BuilderRunner.java", + "PathUtils.java", + "ProcessParameters.java", + "ProcessResult.java", + "ProcessRunner.java", + "ToolsSetup.java", + ], visibility = ["//src/test/java/com/google/devtools/build/lib/blackbox:__subpackages__"], deps = [":deps"], ) @@ -20,11 +29,17 @@ java_library( java_test( name = "framework_tests", testonly = 1, - srcs = glob(["*.java"]), + srcs = [ + "PathUtilsTest.java", + "ProcessRunnerTest.java", + ], tags = ["black_box_test"], test_class = "com.google.devtools.build.lib.AllTests", visibility = ["//src/test/java/com/google/devtools/build/lib/blackbox/tests:__pkg__"], - deps = [":deps"], + deps = [ + ":deps", + ":framework", + ], ) filegroup( diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java index 7557ce696087e7..d4d6351a678a72 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java @@ -91,16 +91,6 @@ public static String getWorkspaceWithDefaultRepos() { " ],", ")", "http_archive(", - " name = 'rules_pkg',", - " sha256 = '352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a',", - " urls = [", - " 'https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", - " 'https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", - " ],", - ")", - "load('@rules_pkg//:deps.bzl', 'rules_pkg_dependencies')", - "rules_pkg_dependencies()", - "http_archive(", " name = 'rules_proto',", " sha256 = '602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208',", " strip_prefix = 'rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313',", @@ -110,6 +100,17 @@ public static String getWorkspaceWithDefaultRepos() { " 'https://github.com/bazelbuild/rules_proto/archive/" + "97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz',", " ],", - ")"); + ")", + "http_archive(", + " name = 'rules_pkg',", + " sha256 = '352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a',", + " urls = [", + " 'https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", + " 'https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", + " ],", + ")", + "load('@rules_pkg//:deps.bzl', 'rules_pkg_dependencies')", + "rules_pkg_dependencies()" + ); } } diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/GitRepositoryBlackBoxTest.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/GitRepositoryBlackBoxTest.java index 27b0754f6ca5a3..de0182cef95205 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/GitRepositoryBlackBoxTest.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/GitRepositoryBlackBoxTest.java @@ -19,6 +19,7 @@ import static com.google.devtools.build.lib.blackbox.tests.workspace.RepoWithRuleWritingTextGenerator.loadRule; import com.google.devtools.build.lib.blackbox.framework.BlackBoxTestContext; +import com.google.devtools.build.lib.blackbox.framework.BlackBoxTestEnvironment; import com.google.devtools.build.lib.blackbox.framework.BuilderRunner; import com.google.devtools.build.lib.blackbox.framework.PathUtils; import com.google.devtools.build.lib.blackbox.junit.AbstractBlackBoxTest; @@ -177,6 +178,7 @@ public void testCheckoutOfCommitFromBranch() throws Exception { context() .write( "WORKSPACE", + BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos(), "load(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")", "git_repository(", " name='ext',", @@ -227,6 +229,7 @@ public void testCheckoutOfCommitFromTag() throws Exception { context() .write( "WORKSPACE", + BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos(), "load(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")", "git_repository(", " name='ext',", diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java index a8e127c420ae92..fa04cf64b21a10 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.blackbox.tests.workspace; +import com.google.devtools.build.lib.blackbox.framework.BlackBoxTestEnvironment; import com.google.devtools.build.lib.blackbox.framework.PathUtils; import java.io.IOException; import java.nio.file.Path; @@ -124,7 +125,8 @@ RepoWithRuleWritingTextGenerator skipBuildFile() { * @throws IOException if was not able to create or write to files */ Path setupRepository() throws IOException { - Path workspace = generateWorkspaceFile(); + Path workspace = PathUtils.writeFileInDir(root, "WORKSPACE", + BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos()); PathUtils.writeFileInDir(root, HELPER_FILE, WRITE_TEXT_TO_FILE); if (generateBuildFile) { PathUtils.writeFileInDir( @@ -138,28 +140,6 @@ Path setupRepository() throws IOException { return workspace.getParent(); } - /** - * Generates the minimal WORKSPACE file for the associated BUILD file. - */ - Path generateWorkspaceFile() throws IOException { - if (generateBuildFile) { - return PathUtils.writeFileInDir(root, "WORKSPACE", - "load('@bazel_tools//tools/build_defs/repo:http.bzl', 'http_archive')", - "http_archive(", - " name = 'rules_pkg',", - " sha256 = '352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a',", - " urls = [", - " 'https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", - " 'https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", - " ],", - ")", - "load('@rules_pkg//:deps.bzl', 'rules_pkg_dependencies')", - "rules_pkg_dependencies()" - ); - } - return PathUtils.writeFileInDir(root, "WORKSPACE"); - } - /** * Returns the text to be put into a header of Starlark file, which is going to use write_to_file * rule from the @repoName repository diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/WorkspaceBlackBoxTest.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/WorkspaceBlackBoxTest.java index af1c5e46abc5b0..b4475e8b31fd7b 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/WorkspaceBlackBoxTest.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/WorkspaceBlackBoxTest.java @@ -123,6 +123,7 @@ public void testExecuteInWorkingDirectory() throws Exception { .write( WORKSPACE, "workspace(name = 'main')", + BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos(), "load(':repo_rule.bzl', 'check_wd')", "check_wd(name = 'relative', working_directory = 'relative')", "check_wd(name = 'relative2', working_directory = '../relative2')", @@ -164,10 +165,10 @@ public void testWorkspaceChanges() throws Exception { context() .write( WORKSPACE, + BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos(), String.format( "local_repository(name = 'x', path = '%s',)", PathUtils.pathForStarlarkFile(repoA))); - // TODO: What we need in WORKSPACE is the deps setup for repoA ...!!!! BuilderRunner bazel = WorkspaceTestUtils.bazel(context()); bazel.build("@x//:" + RepoWithRuleWritingTextGenerator.TARGET); @@ -177,6 +178,7 @@ public void testWorkspaceChanges() throws Exception { context() .write( WORKSPACE, + BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos(), String.format( "local_repository(name = 'x', path = '%s',)", PathUtils.pathForStarlarkFile(repoB))); @@ -193,6 +195,7 @@ public void testNoPackageLoadingOnBenignWorkspaceChanges() throws Exception { context() .write( WORKSPACE, + BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos(), String.format( "local_repository(name = 'ext', path = '%s',)", PathUtils.pathForStarlarkFile(repo))); From 6ef01bf9823f21b5617002a3885bcdbef6f1fdbe Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Tue, 21 Apr 2020 23:31:31 -0400 Subject: [PATCH 6/8] run the java formatter over things --- .../build/lib/blackbox/bazel/DefaultToolsSetup.java | 7 ++++++- .../lib/blackbox/framework/BlackBoxTestEnvironment.java | 9 +++++---- .../workspace/BazelEmbeddedSkylarkBlackBoxTest.java | 5 ----- .../workspace/RepoWithRuleWritingTextGenerator.java | 5 +++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java b/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java index c549ef6733c41e..0a9ab16e234891 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java @@ -27,7 +27,12 @@ public class DefaultToolsSetup implements ToolsSetup { private static ImmutableList repos = - ImmutableList.builder().add("rules_cc").add("rules_proto").add("rules_java").build(); + ImmutableList.builder() + .add("rules_cc") + .add("rules_proto") + .add("rules_java") + .add("rules_pkg") + .build(); private ImmutableList getRepositoryOverrides() { String sharedRepoHome = System.getenv("TEST_REPOSITORY_HOME"); diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java index d4d6351a678a72..f02019a7bbad5d 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java @@ -105,12 +105,13 @@ public static String getWorkspaceWithDefaultRepos() { " name = 'rules_pkg',", " sha256 = '352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a',", " urls = [", - " 'https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", - " 'https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", + " " + + " 'https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", + " " + + " 'https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz',", " ],", ")", "load('@rules_pkg//:deps.bzl', 'rules_pkg_dependencies')", - "rules_pkg_dependencies()" - ); + "rules_pkg_dependencies()"); } } diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/BazelEmbeddedSkylarkBlackBoxTest.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/BazelEmbeddedSkylarkBlackBoxTest.java index cfc9ccd9115a6f..8f2747b37ad5e2 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/BazelEmbeddedSkylarkBlackBoxTest.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/BazelEmbeddedSkylarkBlackBoxTest.java @@ -24,14 +24,9 @@ import com.google.devtools.build.lib.blackbox.junit.AbstractBlackBoxTest; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.util.FileSystems; -import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; import org.junit.Test; /** diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java index fa04cf64b21a10..494ccc6f42ca05 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/RepoWithRuleWritingTextGenerator.java @@ -125,8 +125,9 @@ RepoWithRuleWritingTextGenerator skipBuildFile() { * @throws IOException if was not able to create or write to files */ Path setupRepository() throws IOException { - Path workspace = PathUtils.writeFileInDir(root, "WORKSPACE", - BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos()); + Path workspace = + PathUtils.writeFileInDir( + root, "WORKSPACE", BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos()); PathUtils.writeFileInDir(root, HELPER_FILE, WRITE_TEXT_TO_FILE); if (generateBuildFile) { PathUtils.writeFileInDir( From 5284153740bf319b5b5d4a665c4cababadb4ba31 Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Wed, 22 Apr 2020 00:20:16 -0400 Subject: [PATCH 7/8] needed to update WORKSPACE to rules_pkg 0.2.5 to get new python usage --- WORKSPACE | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index f24f7a8eed43d5..307136b8f3da33 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -165,7 +165,7 @@ distdir_tar( # bazelbuild/bazel-toolchains "2.1.0.tar.gz", # bazelbuild/rules_pkg - "rules_pkg-0.2.4.tar.gz", + "rules_pkg-0.2.5.tar.gz", # bazelbuild/rules_proto "97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz", # protocolbuffers/protobuf @@ -195,7 +195,7 @@ distdir_tar( # bazelbuild/bazel-toolchains "2.1.0.tar.gz": "4d348abfaddbcee0c077fc51bb1177065c3663191588ab3d958f027cbfe1818b", # bazelbuild/rules_pkg - "rules_pkg-0.2.4.tar.gz": "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a", + "rules_pkg-0.2.5.tar.gz": "352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a", # bazelbuild/rules_proto "97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz": "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208", # protocolbuffers/protobuf @@ -259,9 +259,9 @@ distdir_tar( "https://github.com/bazelbuild/bazel-toolchains/releases/download/2.1.0/bazel-toolchains-2.1.0.tar.gz", ], # bazelbuild/rules_pkg - "rules_pkg-0.2.4.tar.gz": [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", - "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", + "rules_pkg-0.2.5.tar.gz": [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz", + "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz", ], # bazelbuild/rules_proto "97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz": [ @@ -882,10 +882,10 @@ http_archive( name = "rules_pkg", patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE, patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN, - sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a", + sha256 = "352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", - "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz", + "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz", ], ) From bce8f809d7b439dc0989882fe500a370e7b49cd6 Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Wed, 22 Apr 2020 00:33:47 -0400 Subject: [PATCH 8/8] get rules_python into the default test cache --- .../devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java b/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java index 0a9ab16e234891..71bc40dfc06154 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java @@ -29,9 +29,10 @@ public class DefaultToolsSetup implements ToolsSetup { private static ImmutableList repos = ImmutableList.builder() .add("rules_cc") - .add("rules_proto") .add("rules_java") .add("rules_pkg") + .add("rules_proto") + .add("rules_python") .build(); private ImmutableList getRepositoryOverrides() {