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:
parent
0e485c80b7
commit
9b26156bbb
|
@ -47,9 +47,10 @@ def _directory_impl(ctx):
|
||||||
f = ctx.actions.declare_file("_directory_rule_" + ctx.label.name)
|
f = ctx.actions.declare_file("_directory_rule_" + ctx.label.name)
|
||||||
ctx.actions.write(f, "")
|
ctx.actions.write(f, "")
|
||||||
|
|
||||||
source_prefix = ctx.label.package + "/"
|
source_prefix = ctx.label.package
|
||||||
if ctx.label.workspace_root:
|
if ctx.label.workspace_root:
|
||||||
source_prefix = ctx.label.workspace_root + "/" + source_prefix
|
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.
|
# 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.
|
# The arbitrary file is used to present error messages if we have both generated files and source files.
|
||||||
|
|
|
@ -14,10 +14,21 @@
|
||||||
|
|
||||||
"""Generates tests for the directory rules from outside the repository."""
|
"""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):
|
def _external_directory_tests_impl(repo_ctx):
|
||||||
for f in repo_ctx.attr.files:
|
for f in repo_ctx.attr.files:
|
||||||
repo_ctx.symlink(repo_ctx.path(f), f.package + "/" + f.name)
|
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.
|
# Directory paths work differently while inside and outside the repository.
|
||||||
# To properly test this, we copy all our test code to an external
|
# To properly test this, we copy all our test code to an external
|
||||||
# repository.
|
# repository.
|
||||||
|
|
Loading…
Reference in a new issue