Skip to content

Commit

Permalink
fix(write_source_files): fix writing to workspace root
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Mar 30, 2022
1 parent 3599515 commit dd298c5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bazel-*
test-out/
13 changes: 13 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ 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",
files = {"test-out/dist/write_source_file_root-test": ":write_source_file_root"},
)
2 changes: 1 addition & 1 deletion lib/private/write_source_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 len(ctx.label.package) > 0 else ctx.attr.out_file
paths.append((in_path, out_path))

if ctx.attr.is_windows:
Expand Down

0 comments on commit dd298c5

Please sign in to comment.