Set default of --incompatible_remove_native_{http_archive,git_repository} to true
...and switch tests to test the skylark implementation rather than the (deprecated,
by default disabled) native implementation.
(Rollforward with remaining calls to the native funcitons in the WORKSPACE
adapted as well, tus fixing bazel_determinism_test.)
Change-Id: I3b604a27615f36463e62112dd02319fcf24f90f0
PiperOrigin-RevId: 218309750
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
index 07de157..13610e5 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
@@ -267,6 +267,12 @@
return this;
}
+ @VisibleForTesting
+ public Builder clearWorkspaceFileSuffixForTesting() {
+ defaultWorkspaceFileSuffix.delete(0, defaultWorkspaceFileSuffix.length());
+ return this;
+ }
+
public Builder setPrelude(String preludeLabelString) {
try {
this.preludeLabel = Label.parseAbsolute(preludeLabelString, ImmutableMap.of());
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE
index 8c8879e..bead2bd 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE
@@ -1,4 +1,5 @@
# External dependencies for the java_* rules.
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
new_local_repository(
name = "local_jdk",
@@ -88,89 +89,89 @@
# This will allow us to stop bundling the full JDK with Bazel.
# Note that while these are currently the same as the openjdk_* rules in
# Bazel's WORKSPACE file, but they don't have to be the same.
-new_http_archive(
+http_archive(
name = "remotejdk_linux",
sha256 = "f27cb933de4f9e7fe9a703486cf44c84bc8e9f138be0c270c9e5716a32367e87",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-linux_x64-allmodules.tar.gz",
],
- build_file = __embedded_dir__ + "/jdk.BUILD",
+ build_file = "@local_jdk//:BUILD.bazel",
strip_prefix = "zulu9.0.7.1-jdk9.0.7-linux_x64-allmodules",
)
-new_http_archive(
+http_archive(
name = "remotejdk_macos",
sha256 = "404e7058ff91f956612f47705efbee8e175a38b505fb1b52d8c1ea98718683de",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-macosx_x64-allmodules.tar.gz",
],
- build_file = __embedded_dir__ + "/jdk.BUILD",
+ build_file = "@local_jdk//:BUILD.bazel",
strip_prefix = "zulu9.0.7.1-jdk9.0.7-macosx_x64-allmodules",
)
-new_http_archive(
+http_archive(
name = "remotejdk_win",
sha256 = "e738829017f107e7a7cd5069db979398ec3c3f03ef56122f89ba38e7374f63ed",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-win_x64-allmodules.zip",
],
- build_file = __embedded_dir__ + "/jdk.BUILD",
+ build_file = "@local_jdk//:BUILD.bazel",
strip_prefix = "zulu9.0.7.1-jdk9.0.7-win_x64-allmodules",
)
# The source-code for this OpenJDK can be found at:
# https://openjdk.linaro.org/releases/jdk9-src-1708.tar.xz
-new_http_archive(
+http_archive(
name = "remotejdk_linux_aarch64",
sha256 = "72e7843902b0395e2d30e1e9ad2a5f05f36a4bc62529828bcbc698d54aec6022",
urls = [
# When you update this, also update the link to the source-code above.
"http://openjdk.linaro.org/releases/jdk9-server-release-1708.tar.xz",
],
- build_file = __embedded_dir__ + "/jdk.BUILD",
+ build_file = "@local_jdk//:BUILD.bazel",
strip_prefix = "jdk9-server-release-1708",
)
-new_http_archive(
+http_archive(
name = "remotejdk10_linux",
sha256 = "57fad3602e74c79587901d6966d3b54ef32cb811829a2552163185d5064fe9b5",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-linux_x64-allmodules.tar.gz",
],
- build_file = __embedded_dir__ + "/jdk.BUILD",
+ build_file = "@local_jdk//:BUILD.bazel",
strip_prefix = "zulu10.2+3-jdk10.0.1-linux_x64-allmodules",
)
-new_http_archive(
+http_archive(
name = "remotejdk10_macos",
sha256 = "e669c9a897413d855b550b4e39d79614392e6fb96f494e8ef99a34297d9d85d3",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-macosx_x64-allmodules.tar.gz",
],
- build_file = __embedded_dir__ + "/jdk.BUILD",
+ build_file = "@local_jdk//:BUILD.bazel",
strip_prefix = "zulu10.2+3-jdk10.0.1-macosx_x64-allmodules"
)
-new_http_archive(
+http_archive(
name = "remotejdk10_win",
sha256 = "c39e7700a8d41794d60985df5a20352435196e78ecbc6a2b30df7be8637bffd5",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-win_x64-allmodules.zip",
],
- build_file = __embedded_dir__ + "/jdk.BUILD",
+ build_file = "@local_jdk//:BUILD.bazel",
strip_prefix = "zulu10.2+3-jdk10.0.1-win_x64-allmodules",
)
# The source-code for this OpenJDK can be found at:
# https://openjdk.linaro.org/releases/jdk10-src-1804.tar.xz
-new_http_archive(
+http_archive(
name = "remotejdk10_linux_aarch64",
sha256 = "b7098b7aaf6ee1ffd4a2d0371a0be26c5a5c87f6aebbe46fe9a92c90583a84be",
urls = [
# When you update this, also update the link to the source-code above.
"http://openjdk.linaro.org/releases/jdk10-server-release-1804.tar.xz",
],
- build_file = __embedded_dir__ + "/jdk.BUILD",
+ build_file = "@local_jdk//:BUILD.bazel",
strip_prefix = "jdk10-server-release-1804",
)
diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java
index 3ff7dff..ac602c6 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java
@@ -445,7 +445,7 @@
@Option(
name = "incompatible_remove_native_git_repository",
- defaultValue = "false",
+ defaultValue = "true",
documentationCategory = OptionDocumentationCategory.SKYLARK_SEMANTICS,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {
@@ -454,13 +454,12 @@
},
help =
"If set to true, the native git_repository rules are disabled; only the skylark version "
- + "will be available"
- )
+ + "will be available")
public boolean incompatibleRemoveNativeGitRepository;
@Option(
name = "incompatible_remove_native_http_archive",
- defaultValue = "false",
+ defaultValue = "true",
documentationCategory = OptionDocumentationCategory.SKYLARK_SEMANTICS,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {
@@ -469,8 +468,7 @@
},
help =
"If set to true, the native http_archive rules are disabled; only the skylark version "
- + "will be available"
- )
+ + "will be available")
public boolean incompatibleRemoveNativeHttpArchive;
@Option(
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
index df6e9f9..cb3886d 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
@@ -219,8 +219,8 @@
.incompatibleNoTransitiveLoads(false)
.incompatiblePackageNameIsAFunction(false)
.incompatibleRangeType(false)
- .incompatibleRemoveNativeGitRepository(false)
- .incompatibleRemoveNativeHttpArchive(false)
+ .incompatibleRemoveNativeGitRepository(true)
+ .incompatibleRemoveNativeHttpArchive(true)
.incompatibleStaticNameResolution(false)
.incompatibleStringIsNotIterable(false)
.internalSkylarkFlagTestCanary(false)
diff --git a/src/main/tools/jdk.BUILD b/src/main/tools/jdk.BUILD
index ce757ac..31fbb64 100644
--- a/src/main/tools/jdk.BUILD
+++ b/src/main/tools/jdk.BUILD
@@ -1,5 +1,7 @@
package(default_visibility = ["//visibility:public"])
+exports_files(["BUILD.bazel"])
+
DEPRECATION_MESSAGE = ("Don't depend on targets in the JDK workspace;" +
" use @bazel_tools//tools/jdk:current_java_runtime instead" +
" (see https://github.com/bazelbuild/bazel/issues/5594)")
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 52011ac..a1e7f35 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
@@ -323,7 +323,7 @@
@Override
public ConfiguredRuleClassProvider createRuleClassProvider() {
- return TestRuleClassProvider.getRuleClassProvider();
+ return TestRuleClassProvider.getRuleClassProvider(true);
}
@Override
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
index 6de0780..4c98772 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
@@ -164,6 +164,16 @@
new AnalysisTestUtil.DummyWorkspaceStatusActionFactory(directories);
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/tools/build_defs/repo/http.bzl",
+ "def http_archive(**kwargs):",
+ " pass",
+ "",
+ "def http_file(**kwargs):",
+ " pass");
+
analysisMock.setupMockClient(mockToolsConfig);
analysisMock.setupMockWorkspaceFiles(directories.getEmbeddedBinariesRoot());
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 5cdcfb2..3e37583 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
@@ -228,6 +228,15 @@
analysisMock.getProductName());
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/tools/build_defs/repo/http.bzl",
+ "def http_archive(**kwargs):",
+ " pass",
+ "",
+ "def http_file(**kwargs):",
+ " pass");
initializeMockClient();
packageCacheOptions = parsePackageCacheOptions();
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 d2b636b..24a5504 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
@@ -98,6 +98,7 @@
public final void initializeSkyframeExecutor() throws Exception {
workspace = rootDirectory;
analysisMock = getAnalysisMock();
+
ConfiguredRuleClassProvider ruleClassProvider = analysisMock.createRuleClassProvider();
PathPackageLocator pkgLocator =
new PathPackageLocator(
@@ -111,6 +112,21 @@
rootDirectory,
/* defaultSystemJavabase= */ null,
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/tools/build_defs/repo/http.bzl",
+ "def http_archive(**kwargs):",
+ " pass",
+ "",
+ "def http_file(**kwargs):",
+ " pass");
+
+ analysisMock.setupMockClient(mockToolsConfig);
+ analysisMock.setupMockWorkspaceFiles(directories.getEmbeddedBinariesRoot());
+
pkgFactory =
analysisMock
.getPackageFactoryBuilderForTesting(directories)
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoaderTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoaderTest.java
index a31a590..ddd250c 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoaderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoaderTest.java
@@ -76,6 +76,14 @@
tools.getRelative("tools/sh/sh_configure.bzl"),
"def sh_configure(*args, **kwargs):",
" pass");
+ FileSystemUtils.writeIsoLatin1(tools.getRelative("tools/build_defs/repo/BUILD"));
+ FileSystemUtils.writeIsoLatin1(
+ tools.getRelative("tools/build_defs/repo/http.bzl"),
+ "def http_archive(**kwargs):",
+ " pass",
+ "",
+ "def http_file(**kwargs):",
+ " pass");
}
private void fetchExternalRepo(RepositoryName externalRepo) {
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/TestRuleClassProvider.java b/src/test/java/com/google/devtools/build/lib/testutil/TestRuleClassProvider.java
index 52d0ba0..1faa837 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/TestRuleClassProvider.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/TestRuleClassProvider.java
@@ -67,21 +67,27 @@
}
}
- /**
- * Return a rule class provider.
- */
- public static ConfiguredRuleClassProvider getRuleClassProvider() {
+ /** Return a rule class provider. */
+ public static ConfiguredRuleClassProvider getRuleClassProvider(boolean clearSuffix) {
if (ruleProvider == null) {
ConfiguredRuleClassProvider.Builder builder =
new ConfiguredRuleClassProvider.Builder();
addStandardRules(builder);
builder.addRuleDefinition(new TestingDummyRule());
builder.addRuleDefinition(new MockToolchainRule());
+ if (clearSuffix) {
+ builder.clearWorkspaceFileSuffixForTesting();
+ }
ruleProvider = builder.build();
}
return ruleProvider;
}
+ /** Return a rule class provider. */
+ public static ConfiguredRuleClassProvider getRuleClassProvider() {
+ return getRuleClassProvider(false);
+ }
+
/**
* A dummy rule with some dummy attributes.
*/
diff --git a/src/test/py/bazel/bazel_external_repository_test.py b/src/test/py/bazel/bazel_external_repository_test.py
index 323b7a5..3ed67f9 100644
--- a/src/test/py/bazel/bazel_external_repository_test.py
+++ b/src/test/py/bazel/bazel_external_repository_test.py
@@ -61,13 +61,14 @@
def testNewHttpArchive(self):
ip, port = self._http_server.server_address
rule_definition = [
- 'new_http_archive(',
+ 'load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")',
+ 'http_archive(',
' name = "six_archive",',
' urls = ["http://%s:%s/six-1.10.0.tar.gz"],' % (ip, port),
' sha256 = '
'"105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a",',
' strip_prefix = "six-1.10.0",',
- ' build_file = "//third_party:six.BUILD",',
+ ' build_file = "@//third_party:six.BUILD",',
')',
]
build_file = [
@@ -84,14 +85,6 @@
exit_code, _, stderr = self.RunBazel(['build', '@six_archive//...'])
self.assertEqual(exit_code, 0, os.linesep.join(stderr))
- # Test specifying build_file as path
- # TODO(pcloudy):
- # Remove this after specifying build_file as path is no longer supported.
- rule_definition[-2] = 'build_file = "third_party/six.BUILD"'
- self.ScratchFile('WORKSPACE', rule_definition)
- exit_code, _, stderr = self.RunBazel(['build', '@six_archive//...'])
- self.assertEqual(exit_code, 0, os.linesep.join(stderr))
-
fetching_disabled_msg = 'fetching is disabled'
# Changing the mtime of the BUILD file shouldn't invalidate it.
@@ -117,10 +110,11 @@
def testNewHttpArchiveWithSymlinks(self):
ip, port = self._http_server.server_address
self.ScratchFile('WORKSPACE', [
- 'new_http_archive(',
+ 'load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")',
+ 'http_archive(',
' name = "archive_with_symlink",',
' urls = ["http://%s:%s/archive_with_symlink.zip"],' % (ip, port),
- ' build_file = "archive_with_symlink.BUILD",',
+ ' build_file = "@//:archive_with_symlink.BUILD",',
')',
])
# In the archive, A is a symlink pointing to B
diff --git a/src/test/shell/bazel/bazel_build_event_stream_test.sh b/src/test/shell/bazel/bazel_build_event_stream_test.sh
index 3d1f93b..11f570c 100755
--- a/src/test/shell/bazel/bazel_build_event_stream_test.sh
+++ b/src/test/shell/bazel/bazel_build_event_stream_test.sh
@@ -58,6 +58,7 @@
fi
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(name="remote", urls=["${FILE_URL}"])
EOF
cat > pkg/BUILD <<'EOF'
diff --git a/src/test/shell/bazel/bazel_experimental_ui_test.sh b/src/test/shell/bazel/bazel_experimental_ui_test.sh
index b9a0607..2274a9c 100755
--- a/src/test/shell/bazel/bazel_experimental_ui_test.sh
+++ b/src/test/shell/bazel/bazel_experimental_ui_test.sh
@@ -58,6 +58,7 @@
local -r cwd="$PWD"
fi
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(name="remote", urls=["file://${cwd}/remote_file"])
EOF
touch BUILD
diff --git a/src/test/shell/bazel/bazel_repository_cache_test.sh b/src/test/shell/bazel/bazel_repository_cache_test.sh
index 0ff0fc3..9f5ff3d 100755
--- a/src/test/shell/bazel/bazel_repository_cache_test.sh
+++ b/src/test/shell/bazel/bazel_repository_cache_test.sh
@@ -170,6 +170,8 @@
if [[ $write_workspace = 0 ]]; then
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
http_archive(
name = 'endangered',
url = 'http://localhost:$nc_port/$repo2_name',
diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh
index 3cb8c96..066f543 100755
--- a/src/test/shell/bazel/external_integration_test.sh
+++ b/src/test/shell/bazel/external_integration_test.sh
@@ -322,6 +322,7 @@
serve_jar
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")
http_jar(name = 'endangered', url = 'http://127.0.0.1:$nc_port/lib.jar')
EOF
@@ -362,9 +363,10 @@
cd ${WORKSPACE_DIR}
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(
name = 'toto',
- url = 'http://127.0.0.1:$nc_port/toto',
+ urls = ['http://127.0.0.1:$nc_port/toto'],
sha256 = '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9826'
)
EOF
@@ -380,9 +382,10 @@
cd ${WORKSPACE_DIR}
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(
name = 'toto',
- url = 'http://127.0.0.1:$nc_port/toto',
+ urls = ['http://127.0.0.1:$nc_port/toto'],
sha256 = '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9826'
)
EOF
@@ -403,29 +406,27 @@
cd ${WORKSPACE_DIR}
cat > WORKSPACE <<EOF
-http_file(name = 'toto', url = 'http://127.0.0.1:$nc_port/toto',
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
+http_file(name = 'toto', urls = ['http://127.0.0.1:$nc_port/toto'],
sha256 = '$sha256', executable = True)
EOF
mkdir -p test
- cat > test/BUILD <<EOF
+ cat > test/BUILD <<'EOF'
sh_binary(
name = "test",
srcs = ["test.sh"],
data = ["@toto//file"],
)
+
+genrule(
+ name = "test_sh",
+ outs = ["test.sh"],
+ srcs = ["@toto//file"],
+ cmd = "echo '#!/bin/sh' > $@ && echo $(location @toto//file) >> $@",
+)
EOF
- cat > test/test.sh <<EOF
-#!/bin/sh
-echo "symlink:"
-ls -l ../toto/file
-echo "dest:"
-ls -l \$(readlink -f ../toto/file/toto)
-../toto/file/toto
-EOF
-
- chmod +x test/test.sh
bazel run //test >& $TEST_log || echo "Expected run to succeed"
kill_nc
expect_log "Tra-la!"
@@ -441,25 +442,27 @@
serve_redirect "http://127.0.0.1:$nc_port/toto"
cat > WORKSPACE <<EOF
-http_file(name = 'toto', url = 'http://127.0.0.1:$redirect_port/toto',
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
+http_file(name = 'toto', urls = ['http://127.0.0.1:$redirect_port/toto'],
sha256 = '$sha256')
EOF
mkdir -p test
- cat > test/BUILD <<EOF
+ cat > test/BUILD <<'EOF'
sh_binary(
name = "test",
srcs = ["test.sh"],
data = ["@toto//file"],
)
+
+genrule(
+ name = "test_sh",
+ outs = ["test.sh"],
+ srcs = ["@toto//file"],
+ cmd = "echo '#!/bin/sh' > $@ && echo cat $(location @toto//file) >> $@",
+)
EOF
- cat > test/test.sh <<EOF
-#!/bin/sh
-cat ../toto/file/toto
-EOF
-
- chmod +x test/test.sh
bazel run //test >& $TEST_log || echo "Expected run to succeed"
kill_nc
expect_log "Tra-la!"
@@ -474,11 +477,11 @@
cat > WORKSPACE <<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-new_http_archive(
+http_archive(
name = "x",
url = "http://127.0.0.1:$nc_port/x.tar.gz",
sha256 = "$sha256",
- build_file = "x.BUILD",
+ build_file = "@//:x.BUILD",
)
EOF
cat > x.BUILD <<EOF
@@ -556,23 +559,26 @@
"
if [ "$1" = "build_file" ] ; then
+ touch BUILD
echo ${build_file_content} > fox.BUILD
- build_file_attr="build_file = 'fox.BUILD'"
+ build_file_attr="build_file = '@//:fox.BUILD'"
else
build_file_attr="build_file_content=\"\"\"${build_file_content}\"\"\""
fi
if [ "$1" = "workspace_file" ]; then
+ touch BUILD
cat > fox.WORKSPACE <<EOF
workspace(name="endangered-fox")
EOF
- workspace_file_attr="workspace_file = 'fox.WORKSPACE'"
+ workspace_file_attr="workspace_file = '@//:fox.WORKSPACE'"
elif [ "$1" = "workspace_file_content" ]; then
workspace_file_attr="workspace_file_content = 'workspace(name=\"endangered-fox\")'"
fi
cat > WORKSPACE <<EOF
-new_http_archive(
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
name = 'endangered',
url = 'http://127.0.0.1:$nc_port/repo.zip',
sha256 = '$sha256',
@@ -645,12 +651,13 @@
serve_file x.tar.gz
cat > WORKSPACE <<EOF
-new_http_archive(
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
name = "x",
url = "http://127.0.0.1:$nc_port/x.tar.gz",
sha256 = "$sha256",
strip_prefix = "x/y/z",
- build_file = "x.BUILD",
+ build_file = "@//:x.BUILD",
)
EOF
cat > x.BUILD <<EOF
@@ -674,12 +681,13 @@
serve_file x.zip
cat > WORKSPACE <<EOF
-new_http_archive(
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
name = "x",
url = "http://127.0.0.1:$nc_port/x.zip",
sha256 = "$sha256",
strip_prefix = "x/y/z",
- build_file = "x.BUILD",
+ build_file = "@//:x.BUILD",
)
EOF
cat > x.BUILD <<EOF
@@ -712,6 +720,7 @@
serve_file x.zip
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "x",
url = "http://127.0.0.1:$nc_port/x.zip",
@@ -731,13 +740,15 @@
serve_file x.tar.gz
cat > WORKSPACE <<EOF
-new_http_archive(
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
name = "x",
url = "http://127.0.0.1:$nc_port/x.tar.gz",
sha256 = "$sha256",
- build_file = "x.BUILD",
+ build_file = "@//:x.BUILD",
)
EOF
+ touch BUILD
cat > x.BUILD <<EOF
genrule(
name = "catter",
@@ -767,11 +778,12 @@
serve_file x.tar.gz
cat > WORKSPACE <<EOF
-new_http_archive(
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
name = "x",
url = "http://127.0.0.1:$nc_port/x.tar.gz",
sha256 = "$sha256",
- build_file = "x.BUILD",
+ build_file = "@//:x.BUILD",
)
EOF
cat > x.BUILD <<EOF
@@ -938,7 +950,7 @@
cd main
cat > WORKSPACE <<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-new_http_archive(
+http_archive(
name="ext",
strip_prefix="ext",
url="file://${EXTREPODIR}/ext.zip",
diff --git a/src/test/shell/bazel/git_repository_test.sh b/src/test/shell/bazel/git_repository_test.sh
index 9852571..e663b67 100755
--- a/src/test/shell/bazel/git_repository_test.sh
+++ b/src/test/shell/bazel/git_repository_test.sh
@@ -69,6 +69,7 @@
# Create a workspace that clones the repository at the first commit.
cd $WORKSPACE_DIR
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "pluto",
remote = "$pluto_repo_dir",
@@ -130,6 +131,7 @@
if [ "$1" == "build_file" ] ; then
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
new_git_repository(
name = "pluto",
remote = "$pluto_repo_dir",
@@ -150,6 +152,7 @@
EOF
else
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
new_git_repository(
name = "pluto",
remote = "$pluto_repo_dir",
@@ -213,6 +216,7 @@
# Create a workspace that clones the outer_planets repository.
cd $WORKSPACE_DIR
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
new_git_repository(
name = "outer_planets",
remote = "$outer_planets_repo_dir",
@@ -269,61 +273,59 @@
cd $WORKSPACE_DIR
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(name='g', remote='$repo_dir', commit='22095302abaf776886879efa5129aa4d44c53017')
EOF
# Use batch to force server restarts.
- bazel --batch build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
- expect_log "Cloning"
+ bazel --batch build @g//:g >& $TEST_log || fail "Build failed"
assert_contains "GIT 1" bazel-genfiles/external/g/go
# Without changing anything, restart the server, which should not cause the checkout to be re-cloned.
- bazel --batch build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
- expect_not_log "Cloning"
+ bazel --batch build @g//:g >& $TEST_log || fail "Build failed"
assert_contains "GIT 1" bazel-genfiles/external/g/go
# Change the commit id, which should cause the checkout to be re-cloned.
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(name='g', remote='$repo_dir', commit='db134ae9b644d8237954a8e6f1ef80fcfd85d521')
EOF
- bazel --batch build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
- expect_log "Cloning"
+ bazel --batch build @g//:g >& $TEST_log || fail "Build failed"
assert_contains "GIT 2" bazel-genfiles/external/g/go
# Change the WORKSPACE but not the commit id, which should not cause the checkout to be re-cloned.
cat > WORKSPACE <<EOF
# This comment line is to change the line numbers, which should not cause Bazel
# to refetch the repository
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(name='g', remote='$repo_dir', commit='db134ae9b644d8237954a8e6f1ef80fcfd85d521')
EOF
- bazel --batch build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
- expect_not_log "Cloning"
+ bazel --batch build @g//:g >& $TEST_log || fail "Build failed"
assert_contains "GIT 2" bazel-genfiles/external/g/go
}
-
function test_git_repository_refetched_when_commit_changes() {
local repo_dir=$TEST_TMPDIR/repos/refetch
cd $WORKSPACE_DIR
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(name='g', remote='$repo_dir', commit='22095302abaf776886879efa5129aa4d44c53017')
EOF
- bazel build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
- expect_log "Cloning"
+ bazel build @g//:g >& $TEST_log || fail "Build failed"
assert_contains "GIT 1" bazel-genfiles/external/g/go
# Change the commit id, which should cause the checkout to be re-cloned.
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(name='g', remote='$repo_dir', commit='db134ae9b644d8237954a8e6f1ef80fcfd85d521')
EOF
- bazel build --noexperimental_ui @g//:g >& $TEST_log || fail "Build failed"
- expect_log "Cloning"
+ bazel build @g//:g >& $TEST_log || fail "Build failed"
assert_contains "GIT 2" bazel-genfiles/external/g/go
}
@@ -332,6 +334,7 @@
cd $WORKSPACE_DIR
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(name='g', remote='$repo_dir', commit='22095302abaf776886879efa5129aa4d44c53017')
EOF
@@ -341,10 +344,10 @@
assert_contains "GIT 1" bazel-genfiles/external/g/go
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(name='g', remote='$repo_dir', commit='db134ae9b644d8237954a8e6f1ef80fcfd85d521')
EOF
-
bazel build --nofetch @g//:g >& $TEST_log || fail "Build failed"
expect_log "External repository 'g' is not up-to-date"
assert_contains "GIT 1" bazel-genfiles/external/g/go
@@ -393,6 +396,7 @@
cd $WORKSPACE_DIR
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "pluto",
remote = "$pluto_repo_dir",
@@ -403,7 +407,7 @@
bazel fetch //planets:planet-info >& $TEST_log \
|| echo "Expect run to fail."
- expect_log "One of either commit or tag must be defined"
+ expect_log "Exactly one of commit"
}
# Verifies that rule fails if neither tag or commit are set.
@@ -421,6 +425,7 @@
cd $WORKSPACE_DIR
cat > WORKSPACE <<EOF
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "pluto",
remote = "$pluto_repo_dir",
@@ -429,7 +434,7 @@
bazel fetch //planets:planet-info >& $TEST_log \
|| echo "Expect run to fail."
- expect_log "One of either commit or tag must be defined"
+ expect_log "Exactly one of commit"
}
run_suite "git_repository tests"
diff --git a/src/test/shell/bazel/testdata/bazel_toolchain_test_data/WORKSPACE.linaro b/src/test/shell/bazel/testdata/bazel_toolchain_test_data/WORKSPACE.linaro
index ad61e0f..e32cb89 100644
--- a/src/test/shell/bazel/testdata/bazel_toolchain_test_data/WORKSPACE.linaro
+++ b/src/test/shell/bazel/testdata/bazel_toolchain_test_data/WORKSPACE.linaro
@@ -1,6 +1,7 @@
-new_http_archive(
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
name = 'org_linaro_components_toolchain_gcc_5_3_1',
- build_file = 'compilers/linaro_linux_gcc_5.3.1.BUILD',
+ build_file = '@//:compilers/linaro_linux_gcc_5.3.1.BUILD',
url = 'https://bazel-mirror.storage.googleapis.com/releases.linaro.org/components/toolchain/binaries/latest-5/arm-linux-gnueabihf/gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf.tar.xz',
strip_prefix = 'gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf',
-)
\ No newline at end of file
+)