2
0
Fork 0
mirror of https://github.com/bazelbuild/bazel-skylib synced 2024-12-03 17:52:40 +00:00

fix: Ensure directories work when the package is empty (#515)

Previously, I was getting the error
`Expected external/_main~toolchains~toolchain_sdk/usr/bin/clang++ to start with one of ["external/_main~toolchains~toolchain_sdk//", "bazel-out/k8-dbg/bin/external/_main~toolchains~toolchain_sdk/"]`
This commit is contained in:
Matt 2024-05-31 17:26:49 +10:00 committed by GitHub
parent 0e485c80b7
commit 9b26156bbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View file

@ -47,9 +47,10 @@ def _directory_impl(ctx):
f = ctx.actions.declare_file("_directory_rule_" + ctx.label.name)
ctx.actions.write(f, "")
source_prefix = ctx.label.package + "/"
source_prefix = ctx.label.package
if ctx.label.workspace_root:
source_prefix = ctx.label.workspace_root + "/" + source_prefix
source_prefix = source_prefix.rstrip("/") + "/"
# Mapping of a prefix to an arbitrary (but deterministic) file matching that path.
# The arbitrary file is used to present error messages if we have both generated files and source files.

View file

@ -14,10 +14,21 @@
"""Generates tests for the directory rules from outside the repository."""
_ROOT_BUILD_FILE_CONTENTS = """
load("@bazel_skylib//rules/directory:directory.bzl", "directory")
directory(
name = "root",
srcs = ["BUILD"],
)
"""
def _external_directory_tests_impl(repo_ctx):
for f in repo_ctx.attr.files:
repo_ctx.symlink(repo_ctx.path(f), f.package + "/" + f.name)
repo_ctx.file("BUILD", _ROOT_BUILD_FILE_CONTENTS)
# Directory paths work differently while inside and outside the repository.
# To properly test this, we copy all our test code to an external
# repository.