Skip to content

Commit

Permalink
fix(write_source_files): fix writing to workspace root (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard authored Mar 31, 2022
1 parent d21acfb commit a2e228d
Show file tree
Hide file tree
Showing 4 changed files with 21 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/
14 changes: 14 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 5 additions & 0 deletions e2e/write_source_files_root.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

bazel run //:write_source_file_root-test
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 ctx.label.package else ctx.attr.out_file
paths.append((in_path, out_path))

if ctx.attr.is_windows:
Expand Down

0 comments on commit a2e228d

Please sign in to comment.