Skip to content

Commit

Permalink
Change missing crate implementation to work with bazel fetch.
Browse files Browse the repository at this point in the history
The existing handling of missing crates in `aliasing_crates_repository`
produces clear error messages, but also causes `bazel fetch` to fail
because the targets don't exist. This issue can be avoided by not
depending on a missing target in a different repository.

New error messages look like the following:

> rule '@oak_crates_index//:oak_std_crates_index__missing__anyhow' does
> not exist

Change-Id: Ife5e60ef59caeb0ca46dac8ce23188123082dac5
  • Loading branch information
bmclarnon committed Aug 30, 2024
1 parent 7ddc16f commit 3e9ebf0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions bazel/crates/aliasing_crates_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ def _aliasing_crates_repository_impl(repository_ctx):
" name = \"{}\",\n".format(package) +
" actual = select({\n")
for repo in repositories:
# We include an entry even if the crates index doesn't contain the
# package because because the resulting error is clearer than what
# might happen if a //conditions:default package is used instead.
target = repo["overrides"].get(package, "@{}//:{}".format(repo["name"], package))
if package in repo["overrides"]:
target = repo["overrides"][package]
elif package in repo["packages"]:
target = "@{}//:{}".format(repo["name"], package)
else:
# Construct a target name explaining that the repository is
# missing the specified package. This is better than using
# "@repo//:target", which causes errors during `bazel fetch`.
# It's also better than omitting an entry since that could
# cause the wrong package to be used if any of the other
# repositories contain a "//conditions:default" condition.
target = ":{}__missing__{}".format(repo["name"], package)
for condition in repo["conditions"]:
contents += " \"{}\": \"{}\",\n".format(condition, target)
contents += (" }),\n" +
Expand Down

0 comments on commit 3e9ebf0

Please sign in to comment.