Bazel: Allow workspaces to reference themselves canonically

Created on 11 Mar 2016  路  7Comments  路  Source: bazelbuild/bazel

This is a blocking issue for the Closure Rules.

If I say:

workspace(name = "io_bazel_rules_closure")

Then I should be able to say within my workspace:

deps = ["@io_bazel_rules_closure//foo/bar"]

Which makes the codebase more copy/pasteable. But most importantly, I need to be able to say:

"_jschecker": attr.label(default=Label("@io_bazel_rules_closure//closure/compiler/jschecker"), executable=True)

Because otherwise the bzl rule will have no way to reference its own tooling. This is because a bzl rule exists in the namespace to which it's loaded. Without the ability to specify a fully canonical name, the rule will only work from other repositories. But if I run bazel test ... within the Closure rules repository, it will not be able to test itself.

CC: @damienmg

P2 feature request

Most helpful comment

This is now committed (https://github.com/bazelbuild/bazel/commit/6f15335deac0c04cfae11623efbe745f11e177ff). The options are:

  • Label("//foo") refers to the Skylark file's repository.
  • Label("//foo", relative_to_caller_repository = True) refers to the repository the BUILD file is that's using the Skylark rule.
  • Label("@//foo") refers to the repository the build is happening from.

All 7 comments

Hi Justine,

We decided this week to do be able to use the Label() function to refer to the repository containing the skylark extension. @kchodorow will work on that.

@kchodorow also work on a more principle ways to refer to external repository but that will take time.

Is there an estimated timeline for this functionality becoming available in Bazel head?

For reference, this sounds like it came out of the (fairly extensive) discussion in #975.

Label("//foo") referring to the skylark rule's repo should be available this week, barring unforeseen issues on the code review.

This is now committed (https://github.com/bazelbuild/bazel/commit/6f15335deac0c04cfae11623efbe745f11e177ff). The options are:

  • Label("//foo") refers to the Skylark file's repository.
  • Label("//foo", relative_to_caller_repository = True) refers to the repository the BUILD file is that's using the Skylark rule.
  • Label("@//foo") refers to the repository the build is happening from.

This is a different issue that still doesn't seem to be fixed. This bug is about "@io_bazel_rules_closure//:something" working from the closure repository itself. It definitely does not work in a build_file attribute with current Bazel master.

Once this is fixed, bazelbuild/rules_closure#9 will be easy to fix.

On second thought, this doesn't actually block anything any more. Just using default-repository labels should work fine... However, it would be still nice if referring to the main repository by name worked for consistency.

Was this page helpful?
0 / 5 - 0 ratings