diff options
Diffstat (limited to 'src/main/java/com')
11 files changed, 34 insertions, 79 deletions
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"); |