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

"Execute an input binary" Skylark cookbook example fails #993

Closed
dfabulich opened this issue Mar 1, 2016 · 7 comments
Closed

"Execute an input binary" Skylark cookbook example fails #993

dfabulich opened this issue Mar 1, 2016 · 7 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional)
Milestone

Comments

@dfabulich
Copy link
Contributor

Consider this git repository: https://github.com/dfabulich/bazel-tempfile-example

It's a copy and paste from the "Execute an input binary" sample from the Skylark cookbook. http://bazel.io/docs/skylark/cookbook.html

I expected it to succeed, but it failed.

dfab: /tp/tempfiles $ bazel build --verbose_failures //:e
INFO: Found 1 target...
ERROR: /private/tmp/tp/tempfiles/BUILD:3:1: Executing a.sh failed: a.sh failed: error executing command
  (cd /private/var/tmp/_bazel_dfabulich/cddaf6252bd073c3ed3cc32458593a42/tempfiles && \
  exec env - \
  a.sh bazel-out/local_darwin-fastbuild/bin/hello bazel-out/local_darwin-fastbuild/bin/foo): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1: a.sh failed: error executing command
  (cd /private/var/tmp/_bazel_dfabulich/cddaf6252bd073c3ed3cc32458593a42/tempfiles && \
  exec env - \
  a.sh bazel-out/local_darwin-fastbuild/bin/hello bazel-out/local_darwin-fastbuild/bin/foo): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
process-wrapper: execvp("a.sh", ...): No such file or directory
Target //:e failed to build
INFO: Elapsed time: 0.066s, Critical Path: 0.01s
dfab: /tp/tempfiles $ ls -l bazel-tempfiles/a.sh
lrwxr-xr-x  1 dfabulich  wheel  30 Feb 29 23:33 bazel-tempfiles/a.sh -> /private/tmp/tp/tempfiles/a.sh

a.sh is definitely there in the bazel-tempfiles directory, but since it's not being invoked with ./a.sh, it's not on the path, so the script isn't executed. You can run a.sh by hand like this:

bazel-tempfiles/a.sh bazel-out/local_darwin-fastbuild/bin/hello bazel-out/local_darwin-fastbuild/bin/foo

How is this example supposed to work?

@dfabulich
Copy link
Contributor Author

$ bazel version
Build label: 0.2.0-homebrew
Build target: bazel-out/local_darwin-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Feb 23 14:12:29 2016 (1456236749)
Build timestamp: 1456236749
Build timestamp as int: 1456236749

@kchodorow
Copy link
Contributor

We should update the example to prefix a.sh with "./". Thanks for the report!

@kchodorow kchodorow added type: documentation (cleanup) Skylark P2 We'll consider working on this in future. (Assignee optional) labels Mar 2, 2016
@dfabulich
Copy link
Contributor Author

I don't think that's possible. In the example, "a.sh" is a file label. If you change it to "./a.sh" it fails with this error:

ERROR: /private/tmp/tp/tempfiles/BUILD:3:1: //:e: invalid label './a.sh' in attribute 'binary' in 'execute' rule: invalid target name './a.sh': target names may not contain '.' as a path segment.

And since a.sh is being provided as the executable of a ctx.action call, there's no place to add ./ anywhere in the Skylark code, either.

I think the only way to fix this code is to to move a.sh into a subdirectory.

Which is to say, I think there's an actual bug in Bazel, because running an executable in the WORKSPACE root directory really ought to work.

@kchodorow
Copy link
Contributor

Ah, good point. Perhaps the skylark action code needs to change.

@kchodorow
Copy link
Contributor

Assigning to @jmmv, since you just did #958.

@jmmv
Copy link
Contributor

jmmv commented Mar 3, 2016

This actually looks like #347.

I very much doubt #958 had to do anything with this: the default path modified in that bug should have never come into play because it's very hard to imagine a realistic scenario in which PATH is unset in the environment. If a user's rules worked when invoking a binary from the top-level directory, they most likely did so because the user's own PATH included the current directory in it.

I think the examples in the documentation are correct, but those examples are not specific to any BUILD file: if you put them in a subdirectory, they would work; but if you put them in the top-level directory they do not.

@dslomov dslomov added this to the 0.5 milestone Dec 8, 2016
@dslomov dslomov modified the milestones: 0.6, 0.5 Dec 20, 2016
@laurentlb
Copy link
Contributor

Obsolete.

Examples are now here: https://github.com/bazelbuild/examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional)
Projects
None yet
Development

No branches or pull requests

7 participants