diff options
15 files changed, 49 insertions, 123 deletions
diff --git a/site/docs/cpp.md b/site/docs/cpp.md index a927d917b9..1d32d4eed6 100644 --- a/site/docs/cpp.md +++ b/site/docs/cpp.md @@ -161,16 +161,11 @@ download Google Test and make it available in your repository: ```python new_http_archive( - name = "gtest-repo", + name = "gtest", url = "https://googletest.googlecode.com/files/gtest-1.7.0.zip", sha256 = "247ca18dd83f53deb1328be17e4b1be31514cedfc1e3424f672bf11fd7e0d60d", build_file = "gtest.BUILD", ) - -bind( - name = "gtest/main", - actual = "@gtest-repo//:main", -) ``` Then create _gtest.BUILD_, a BUILD file to use to compile Google Test. @@ -223,7 +218,7 @@ Then create a BUILD file for your tests: cc_test( name = "my_test", srcs = ["my_test.cc"], - deps = ["//external:gtest/main"], + deps = ["@gtest//:main"], ) ``` diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpArchiveRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpArchiveRule.java index 2550d8e6c8..f64bbdb303 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpArchiveRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpArchiveRule.java @@ -108,13 +108,8 @@ http_archive( url = "http://example.com/openssl.zip", sha256 = "03a58ac630e59778f328af4bcc4acb4f80208ed4", ) - -bind( - name = "openssl", - actual = "@my-ssl//src:openssl-lib", -) </pre> -<p>See <a href="#bind_examples">Bind</a> for how to use bound targets.</p> +<p>Then targets would specify <code>@my-ssl//src:openssl-lib</code> as a dependency.</p> <!-- #END_BLAZE_RULE -->*/ diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpJarRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpJarRule.java index 608e1b8594..c92042a9a4 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpJarRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpJarRule.java @@ -86,13 +86,8 @@ http_jar( url = "http://example.com/openssl-0.2.jar", sha256 = "03a58ac630e59778f328af4bcc4acb4f80208ed4", ) - -bind( - name = "openssl", - actual = "@my-ssl//jar", -) </pre> -<p>See <a href="#bind_examples">Bind</a> for how to use bound targets.</p> +<p>Targets would specify <code>@my-ssl//jar</code> as a dependency to depend on this jar.</p> <!-- #END_BLAZE_RULE -->*/ diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/LocalRepositoryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/LocalRepositoryRule.java index b283ced6df..91b33c0553 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/LocalRepositoryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/LocalRepositoryRule.java @@ -79,13 +79,9 @@ local_repository( name = "my-ssl", path = "/home/user/ssl", ) - -bind( - name = "openssl", - actual = "@my-ssl//src:openssl-lib", -) </pre> -<p>See <a href="#bind_examples">Bind</a> for how to use bound targets.</p> +<p>Targets would specify <code>@my-ssl//src:openssl-lib</code> as a dependency to depend on this +library.</p> <!-- #END_BLAZE_RULE -->*/ diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java index fb59402656..f79071eab6 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java @@ -110,15 +110,8 @@ maven_jar( artifact_id = "guava", version = "18.0", ) - -bind( - name = "guava-jar", - actual = "@guava//jar" -) </pre> -Then the java_library can depend on <code>//external:guava-jar</code>. - -<p>See <a href="#bind_examples">Bind</a> for how to use bound targets.</p> +<p>Targets would specify <code>@guava//jar</code> as a dependency to depend on this jar.</p> <!-- #END_BLAZE_RULE -->*/ diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewHttpArchiveRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewHttpArchiveRule.java index a0cb2ba327..5783b23e1e 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewHttpArchiveRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewHttpArchiveRule.java @@ -114,13 +114,9 @@ new_http_archive( sha256 = "03a58ac630e59778f328af4bcc4acb4f80208ed4", build_file = "ssl.BUILD", ) - -bind( - name = "openssl", - actual = "@my-ssl//:openssl-lib", -) </pre> -<p>See <a href="#bind_examples">Bind</a> for how to use bound targets.</p> +<p>Targets would specify <code>@my-ssl//:openssl-lib</code> as a dependency to depend on this + jar.</p> <!-- #END_BLAZE_RULE -->*/ diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewLocalRepositoryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewLocalRepositoryRule.java index 67aa27f5b1..f7bdc629cf 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewLocalRepositoryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewLocalRepositoryRule.java @@ -71,7 +71,7 @@ ${ATTRIBUTE_SIGNATURE} <p>This rule creates a Bazel repository by creating a WORKSPACE file and subdirectory containing symlinks to the BUILD file and path given. The build file should create targets relative to the -path, which can then be bound and used by the current build. +<code>path</code>. ${ATTRIBUTE_DEFINITION} @@ -86,7 +86,8 @@ ${ATTRIBUTE_DEFINITION} <pre class="code"> java_library( name = "openssl", - srcs = glob(['ssl/*.java']) + srcs = glob(['*.java']) + visibility = ["//visibility:public"], ) </pre> @@ -98,18 +99,11 @@ new_local_repository( path = "/home/user/ssl", build_file = "BUILD.my-ssl", ) - -bind( - name = "openssl", - actual = "@my-ssl//my-ssl:openssl", -) </pre> -<p>This will create a @my-ssl repository containing a my-ssl package that contains a symlink to -/home/user/ssl named ssl (so the BUILD file must refer to paths within /home/user/ssl relative to -ssl).</p> - -<p>See <a href="#bind_examples">Bind</a> for how to use bound targets.</p> +<p>This will create a <code>@my-ssl</code> repository that symlinks to <i>/home/user/ssl</i>. +Targets can depend on this library by adding <code>@my-ssl//:openssl</code> to a target's +dependencies.</p> <p>You can also use <code>new_local_repository</code> to include single files, not just directories. For example, suppose you had a jar file at /home/username/Downloads/piano.jar. You @@ -121,22 +115,18 @@ new_local_repository( path = "/home/username/Downloads/piano.jar", build_file = "BUILD.piano", ) - -bind( - name = "music", - actual = "@piano//piano:play-music", -) </pre> -<p>And creating the following BUILD file:</p> +<p>And creating the following BUILD.piano file:</p> <pre class="code"> java_import( name = "play-music", jars = ["piano.jar"], + visibility = ["//visibility:public"], ) </pre> -Then targets can depend on //external:music to use piano.jar. +Then targets can depend on <code>@piano//:play-music</code> to use piano.jar. <!-- #END_BLAZE_RULE -->*/ diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java b/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java index 3c082a57b0..bb6c8905e5 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java +++ b/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java @@ -219,7 +219,7 @@ public class PackageDeserializer { private static Label deserializeLabel(String labelName) throws PackageDeserializationException { try { - return Label.parseRepositoryLabel(labelName); + return Label.parseAbsolute(labelName); } catch (Label.SyntaxException e) { throw new PackageDeserializationException("Invalid label: " + e.getMessage(), e); } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java index 3866da7c03..6191c81359 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java @@ -16,7 +16,6 @@ package com.google.devtools.build.lib.skyframe; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.cmdline.LabelValidator; -import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException; import com.google.devtools.build.lib.packages.BuildFileNotFoundException; import com.google.devtools.build.lib.packages.ExternalPackage; import com.google.devtools.build.lib.packages.NoSuchPackageException; @@ -153,8 +152,8 @@ class PackageLookupFunction implements SkyFunction { } catch (NoSuchPackageException e) { throw new PackageLookupFunctionException(e, Transience.PERSISTENT); } catch (IOException | EvalException e) { - throw new PackageLookupFunctionException(new BuildFileContainsErrorsException( - PackageFunction.EXTERNAL_PACKAGE_NAME, e.getMessage()), Transience.PERSISTENT); + throw new PackageLookupFunctionException(new BuildFileNotFoundException( + ExternalPackage.NAME, e.getMessage()), Transience.PERSISTENT); } PathFragment buildFileFragment = id.getPackageFragment().getChild("BUILD"); RootedPath buildFileRootedPath = RootedPath.toRootedPath(repositoryValue.getPath(), diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java index 60c80a04ba..e55ea61a99 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java @@ -151,7 +151,7 @@ public class SkylarkImportLookupFunction implements SkyFunction { try { // This code relies on PackageIdentifier.RepositoryName.toString() - return Label.parseRepositoryLabel(repo + "//" + pkgName.getPathString() + ":" + fileInPkg); + return Label.parseAbsolute(repo + "//" + pkgName.getPathString() + ":" + fileInPkg); } catch (SyntaxException e) { throw new IllegalStateException(e); } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java index 8303bd87a6..ea54ef0e46 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java @@ -159,8 +159,7 @@ public class WorkspaceFileFunction implements SkyFunction { Label nameLabel = null; try { nameLabel = Label.parseAbsolute("//external:" + name); - builder.addBinding( - nameLabel, new Binding(Label.parseRepositoryLabel(actual), loc)); + builder.addBinding(nameLabel, new Binding(Label.parseAbsolute(actual), loc)); } catch (SyntaxException e) { throw new EvalException(loc, e.getMessage()); } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Label.java b/src/main/java/com/google/devtools/build/lib/syntax/Label.java index f250c50897..e1c28aa53f 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Label.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Label.java @@ -50,15 +50,15 @@ public final class Label implements Comparable<Label>, Serializable { } /** - * Factory for Labels from absolute string form, possibly including a repository name prefix. For - * example: + * Factory for Labels from absolute string form. e.g. * <pre> * //foo/bar + * //foo/bar:quux * {@literal @}foo//bar * {@literal @}foo//bar:baz * </pre> */ - public static Label parseRepositoryLabel(String absName) throws SyntaxException { + public static Label parseAbsolute(String absName) throws SyntaxException { String repo = PackageIdentifier.DEFAULT_REPOSITORY; int packageStartPos = absName.indexOf("//"); if (packageStartPos > 0) { @@ -67,6 +67,7 @@ public final class Label implements Comparable<Label>, Serializable { } try { LabelValidator.PackageAndTarget labelParts = LabelValidator.parseAbsoluteLabel(absName); + validate(labelParts.getPackageName(), labelParts.getTargetName()); return new Label(new PackageIdentifier(repo, new PathFragment(labelParts.getPackageName())), labelParts.getTargetName()); } catch (BadLabelException e) { @@ -75,22 +76,6 @@ public final class Label implements Comparable<Label>, Serializable { } /** - * Factory for Labels from absolute string form. e.g. - * <pre> - * //foo/bar - * //foo/bar:quux - * </pre> - */ - public static Label parseAbsolute(String absName) throws SyntaxException { - try { - LabelValidator.PackageAndTarget labelParts = LabelValidator.parseAbsoluteLabel(absName); - return create(labelParts.getPackageName(), labelParts.getTargetName()); - } catch (BadLabelException e) { - throw new SyntaxException(e.getMessage()); - } - } - - /** * Alternate factory method for Labels from absolute strings. This is a convenience method for * cases when a Label needs to be initialized statically, so the declared exception is * inconvenient. @@ -150,7 +135,7 @@ public final class Label implements Comparable<Label>, Serializable { public static Label parseCommandLineLabel(String label, PathFragment workspaceRelativePath) throws SyntaxException { Preconditions.checkArgument(!workspaceRelativePath.isAbsolute()); - if (label.startsWith("//")) { + if (isAbsolute(label)) { return parseAbsolute(label); } int index = label.indexOf(':'); @@ -165,6 +150,13 @@ public final class Label implements Comparable<Label>, Serializable { } /** + * Returns if the label starts with a repository (@whatever) or a package (//whatever). + */ + private static boolean isAbsolute(String label) { + return label.startsWith("//") || label.startsWith("@"); + } + + /** * Validates the given target name and returns a canonical String instance if it is valid. * Otherwise it throws a SyntaxException. */ @@ -359,7 +351,7 @@ public final class Label implements Comparable<Label>, Serializable { if (relName.length() == 0) { throw new SyntaxException("empty package-relative label"); } - if (relName.startsWith("//")) { + if (isAbsolute(relName)) { return parseAbsolute(relName); } else if (relName.equals(":")) { throw new SyntaxException("':' is not a valid package-relative label"); diff --git a/src/test/java/com/google/devtools/build/lib/syntax/LabelTest.java b/src/test/java/com/google/devtools/build/lib/syntax/LabelTest.java index cc4134f77b..322fb64e46 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/LabelTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/LabelTest.java @@ -343,20 +343,20 @@ public class LabelTest { @Test public void testRepoLabel() throws Exception { - Label label = Label.parseRepositoryLabel("@foo//bar/baz:bat/boo"); + Label label = Label.parseAbsolute("@foo//bar/baz:bat/boo"); assertEquals("@foo//bar/baz:bat/boo", label.toString()); } @Test public void testNoRepo() throws Exception { - Label label = Label.parseRepositoryLabel("//bar/baz:bat/boo"); + Label label = Label.parseAbsolute("//bar/baz:bat/boo"); assertEquals("//bar/baz:bat/boo", label.toString()); } @Test public void testInvalidRepo() throws Exception { try { - Label.parseRepositoryLabel("foo//bar/baz:bat/boo"); + Label.parseAbsolute("foo//bar/baz:bat/boo"); fail(); } catch (SyntaxException e) { assertThat(e).hasMessage("invalid repository name 'foo': workspace name must start with '@'"); diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh index 1f8eec689f..1c7bd6db78 100755 --- a/src/test/shell/bazel/external_integration_test.sh +++ b/src/test/shell/bazel/external_integration_test.sh @@ -154,14 +154,13 @@ EOF cat > WORKSPACE <<EOF http_archive(name = 'endangered', url = 'http://localhost:$nc_port/repo.zip', sha256 = '$sha256') -bind(name = 'stud', actual = '@endangered//fox') EOF cat > zoo/BUILD <<EOF sh_binary( name = "breeding-program", srcs = ["female.sh"], - data = ["//external:stud"], + data = ["@endangered//fox"], ) EOF @@ -183,14 +182,13 @@ function test_http_archive_no_server() { cat > WORKSPACE <<EOF http_archive(name = 'endangered', url = 'http://localhost:$nc_port/repo.zip', sha256 = 'dummy') -bind(name = 'stud', actual = '@endangered//fox') EOF cat > zoo/BUILD <<EOF sh_binary( name = "breeding-program", srcs = ["female.sh"], - data = ["//external:stud"], + data = ["@endangered//fox"], ) EOF @@ -220,14 +218,13 @@ function test_http_archive_mismatched_sha256() { cat > WORKSPACE <<EOF http_archive(name = 'endangered', url = 'http://localhost:$nc_port/repo.zip', sha256 = '$wrong_sha256') -bind(name = 'stud', actual = '@endangered//fox') EOF cat > zoo/BUILD <<EOF sh_binary( name = "breeding-program", srcs = ["female.sh"], - data = ["//external:stud"], + data = ["@endangered//fox"], ) EOF @@ -278,7 +275,6 @@ function test_jar_download() { cat > WORKSPACE <<EOF http_jar(name = 'endangered', url = 'http://localhost:$nc_port/lib.jar', sha256 = '$sha256') -bind(name = 'mongoose', actual = '@endangered//jar') EOF mkdir -p zoo @@ -287,7 +283,7 @@ java_binary( name = "ball-pit", srcs = ["BallPit.java"], main_class = "BallPit", - deps = ["//external:mongoose"], + deps = ["@endangered//jar"], ) EOF diff --git a/src/test/shell/bazel/local_repository_test.sh b/src/test/shell/bazel/local_repository_test.sh index 60a95100f8..3aa6363903 100755 --- a/src/test/shell/bazel/local_repository_test.sh +++ b/src/test/shell/bazel/local_repository_test.sh @@ -57,14 +57,13 @@ EOF mkdir -p {zoo,red} cat > WORKSPACE <<EOF local_repository(name = 'pandas', path = '${repo2}') -bind(name = 'red', actual = '@pandas//red:panda') EOF cat > zoo/BUILD <<EOF sh_binary( name = "dumper", srcs = ["dumper.sh"], - data = ["//external:red", "//red:keepers"] + data = ["@pandas//red:panda", "//red:keepers"] ) EOF @@ -117,7 +116,6 @@ EOF cd ${WORKSPACE_DIR} cat > WORKSPACE <<EOF local_repository(name = 'endangered', path = '$repo2') -bind(name = 'mongoose', actual = '@endangered//carnivore:mongoose') EOF mkdir -p zoo @@ -126,7 +124,7 @@ java_binary( name = "ball-pit", srcs = ["BallPit.java"], main_class = "BallPit", - deps = ["//external:mongoose"], + deps = ["@endangered//carnivore:mongoose"], ) EOF @@ -175,10 +173,6 @@ new_local_repository( path = '$project_dir', build_file = '$build_file', ) -bind( - name = 'mongoose', - actual = '@endangered//:mongoose' -) EOF mkdir -p zoo @@ -187,7 +181,7 @@ java_binary( name = "ball-pit", srcs = ["BallPit.java"], main_class = "BallPit", - deps = ["//external:mongoose"], + deps = ["@endangered//:mongoose"], ) EOF @@ -273,7 +267,7 @@ EOF cc_binary( name = "greeter", srcs = ["greeter.cc"], - deps = ["//external:greet-lib"], + deps = ["@greet-ws//:greet_lib"], ) EOF cat > WORKSPACE <<EOF @@ -281,10 +275,6 @@ local_repository( name = "greet-ws", path = "$external_ws", ) -bind( - name = "greet-lib", - actual = "@greet-ws//:greet_lib" -) EOF bazel fetch //:greeter || fail "Fetch failed" @@ -331,7 +321,7 @@ EOF java_library( name = "b", srcs = ["B.java"], - deps = ["//external:x"], + deps = ["@x-repo//x"], visibility = ["//visibility:public"], ) EOF @@ -359,11 +349,6 @@ local_repository( name = "x-repo", path = "$external_dir", ) - -bind( - name = "x", - actual = "@x-repo//x", -) EOF bazel fetch //a:a || fail "Fetch failed" @@ -399,17 +384,12 @@ local_repository( name = "clib-repo", path = "$clib", ) - -bind( - name = "clib", - actual = "@clib-repo//:clib" -) EOF cat > BUILD <<EOF cc_binary( name = "printer", srcs = ["printer.cc"], - deps = ["//external:clib"], + deps = ["@clib-repo//:clib"], ) EOF cat > printer.cc <<EOF |