Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(write_source_files): fix writing to workspace root
  • Loading branch information
jbedard committed Mar 31, 2022
commit 28514276571da9d82b09ed10e585e5f6660f4c06
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(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gregmagolan did you actually get your write_dist running as a test? This only failed previously when doing bazel run and not bazel test...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs an integration test but I'd prefer to avoid the added complexity of bazel-in-bazel

name = "write_source_file_root-test",
diff_test = False,
files = {"test-out/dist/write_source_file_root-test": ":write_source_file_root"},
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to add //visibility:private to this as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't tests be public?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, the angle I was gettting at was whether this should be available to anyone who depends on our repository.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is private by default unless there is a default_visiblity in the BUILD to set another default

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