From 4eb8024dd6fbfeb1721a20cd0dc5852b7316c62c Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Wed, 30 Mar 2022 14:03:41 -0700 Subject: [PATCH] fix(write_source_files): fix writing to workspace root --- .gitignore | 1 + BUILD.bazel | 14 ++++++++++++++ lib/private/write_source_file.bzl | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ac51a054d..b1d35b86b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bazel-* +test-out/ diff --git a/BUILD.bazel b/BUILD.bazel index e7269d176..fade2cfcc 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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"}, +) diff --git a/lib/private/write_source_file.bzl b/lib/private/write_source_file.bzl index f52327fd5..46d0197e6 100644 --- a/lib/private/write_source_file.bzl +++ b/lib/private/write_source_file.bzl @@ -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: