fix: allow for BUILD files in outputs of write_source_file (#540)

This commit is contained in:
Matt Mackay 2023-09-21 19:50:04 -04:00 committed by GitHub
parent 719b8f33b0
commit 8fa2127518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 1 deletions

View File

@ -372,4 +372,11 @@ def _is_file_missing(label):
file_abs = "%s/%s" % (label.package, label.name)
file_rel = file_abs[len(native.package_name()) + 1:]
file_glob = native.glob([file_rel], exclude_directories = 0, allow_empty = True)
return len(file_glob) == 0
# Check for subpackages in case the expected output contains BUILD files,
# the above files glob will return empty.
subpackage_glob = []
if hasattr(native, "subpackages"):
subpackage_glob = native.subpackages(include = [file_rel], allow_empty = True)
return len(file_glob) == 0 and len(subpackage_glob) == 0

View File

@ -0,0 +1,33 @@
load("//lib:write_source_files.bzl", "write_source_file")
load("//lib:copy_to_directory.bzl", "copy_to_directory")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
write_file(
name = "write_build",
out = "BUILD",
content = [
"# Marker for a package",
"",
],
)
write_file(
name = "write_other",
out = "other.txt",
content = ["Another file"],
)
copy_to_directory(
name = "dir",
srcs = [
":BUILD",
":other.txt",
],
)
# This will cause an analysis failure if "expected_out" is considered missing.
write_source_file(
name = "build_files_in_outs",
in_file = ":dir",
out_file = ":expected_out",
)

View File

@ -0,0 +1 @@
# Marker for a package

View File

@ -0,0 +1 @@
Another file