fix: allow for BUILD files in outputs of write_source_file (#540)
This commit is contained in:
parent
719b8f33b0
commit
8fa2127518
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
)
|
|
@ -0,0 +1 @@
|
|||
# Marker for a package
|
|
@ -0,0 +1 @@
|
|||
Another file
|
Loading…
Reference in New Issue