Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update blackbox tests to use rules_pkg instead of built-ins for pkg_tar #9046

Closed
wants to merge 13 commits into from
16 changes: 8 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
public class DefaultToolsSetup implements ToolsSetup {

private static ImmutableList<String> repos =
ImmutableList.<String>builder().add("rules_cc").add("rules_proto").add("rules_java").build();
ImmutableList.<String>builder()
.add("rules_cc")
.add("rules_java")
.add("rules_pkg")
.add("rules_proto")
.add("rules_python")
.build();

private ImmutableList<String> getRepositoryOverrides() {
String sharedRepoHome = System.getenv("TEST_REPOSITORY_HOME");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,34 @@ 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"],
)

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ 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()");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -43,34 +38,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<String, Path> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',",
Expand Down Expand Up @@ -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',",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,16 +125,18 @@ 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", BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos());
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()));
String.format("pkg_tar(name = '%s', srcs = glob(['*']),)", getPkgTarTarget()));
}
return workspace.getParent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
@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([\"*\"]),)";
+ "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([\"*\"]),)";
+ "pkg_tar(name = 'pkg_tar_target', srcs = glob(['*']),)";

@Test
public void testOutput() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')",
Expand Down Expand Up @@ -164,6 +165,7 @@ public void testWorkspaceChanges() throws Exception {
context()
.write(
WORKSPACE,
BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos(),
String.format(
"local_repository(name = 'x', path = '%s',)",
PathUtils.pathForStarlarkFile(repoA)));
Expand All @@ -176,6 +178,7 @@ public void testWorkspaceChanges() throws Exception {
context()
.write(
WORKSPACE,
BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos(),
String.format(
"local_repository(name = 'x', path = '%s',)",
PathUtils.pathForStarlarkFile(repoB)));
Expand All @@ -192,6 +195,7 @@ public void testNoPackageLoadingOnBenignWorkspaceChanges() throws Exception {
context()
.write(
WORKSPACE,
BlackBoxTestEnvironment.getWorkspaceWithDefaultRepos(),
String.format(
"local_repository(name = 'ext', path = '%s',)",
PathUtils.pathForStarlarkFile(repo)));
Expand Down