fix(write_source_files): fix writing to workspace root (#53)

This commit is contained in:
Jason Bedard 2022-03-30 17:04:35 -07:00 committed by GitHub
parent d21acfbd5a
commit a2e228dde0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 1 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
bazel-*
test-out/

View File

@ -20,3 +20,17 @@ bzl_library(
"@bazel_tools//tools/build_defs/repo:utils.bzl",
],
)
# write_source_files() to a git ignored subdirectory of the root
load("//lib:write_source_files.bzl", "write_source_files")
genrule(
name = "write_source_file_root",
outs = ["write_source_file-root_directory"],
cmd = "mkdir -p $@ && echo 'test' > $@/test.txt",
visibility = ["//visibility:private"],
)
write_source_files(
name = "write_source_file_root-test",
diff_test = False,
files = {"test-out/dist/write_source_file_root-test": ":write_source_file_root"},
)

5
e2e/write_source_files_root.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -e
bazel run //:write_source_file_root-test

View File

@ -266,7 +266,7 @@ def _write_source_file_impl(ctx):
else:
fail("in file %s must be a single file or a target that provides DefaultOutputPathInfo or DirectoryPathInfo" % ctx.attr.in_file.label)
out_path = "/".join([ctx.label.package, ctx.attr.out_file])
out_path = "/".join([ctx.label.package, ctx.attr.out_file]) if ctx.label.package else ctx.attr.out_file
paths.append((in_path, out_path))
if ctx.attr.is_windows: