Skip to content

Commit

Permalink
Use MakeSymlink in one other place
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jun 28, 2022
1 parent 0e8e5f6 commit bf0e72e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ private boolean checkOutputs(
if (e instanceof NotASymlinkException) {
reporter.handle(Event.error(
action.getOwner().getLocation(),
String.format("output '%s' is not a symlink", output.prettyPrint())));
String.format("declared output '%s' is not a symlink", output.prettyPrint())));
} else {
// Are all exceptions caught due to missing files?
reportMissingOutputFile(action, output, reporter, output.getPath().isSymbolicLink(),
Expand Down
27 changes: 25 additions & 2 deletions src/test/shell/bazel/bazel_symlink_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ EOF

function test_file_instead_of_symlink() {
mkdir -p a
cat > a/MakeSymlink.java <<'EOF'
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class MakeSymlink {
public static void main(String[] args) throws IOException {
Files.createSymbolicLink(Paths.get(args[0]), Paths.get(args[1]));
}
}
EOF

cat > a/a.bzl <<'EOF'
def _bad_symlink_impl(ctx):
symlink = ctx.actions.declare_symlink(ctx.label.name)
Expand Down Expand Up @@ -258,17 +269,29 @@ EOF
cat > a/BUILD <<'EOF'
load(":a.bzl", "bad_symlink", "bad_write")
java_binary(
name = "MakeSymlink",
srcs = ["MakeSymlink.java"],
main_class = "MakeSymlink",
)
bad_symlink(name="bs", link_target="bad/symlink")
genrule(name="bsg", srcs=[":bs"], outs=["bsgo"], cmd="echo BSGO > $@")
bad_write(name="bw", contents="badcontents")
genrule(name="bwg", srcs=[":bw"], outs=["bwgo"], cmd="echo BWGO > $@")
genrule(name="bg", srcs=[], outs=["bgo"], cmd = "ln -s bad/symlink $@")
genrule(
name="bg",
srcs=[],
outs=["bgo"],
exec_tools = [":MakeSymlink"],
cmd = "$(execpath :MakeSymlink) $@ bad/symlink",
)
EOF

bazel --windows_enable_symlinks build --experimental_allow_unresolved_symlinks //a:bsg >& $TEST_log && fail "build succeeded"
expect_log "output 'a/bs' is not a symlink"
expect_log "declared output 'a/bs' is not a symlink"

bazel --windows_enable_symlinks build --experimental_allow_unresolved_symlinks //a:bwg >& $TEST_log && fail "build succeeded"
expect_log "symlink() with \"target_path\" param requires that \"output\" be declared as a symlink, not a regular file"
Expand Down

0 comments on commit bf0e72e

Please sign in to comment.