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

Make original working directory available to commands that are run #3635

Closed
wants to merge 1 commit into from

Conversation

ianthehat
Copy link
Contributor

@ianthehat ianthehat commented Aug 29, 2017

This adds the environment variable BAZEL_PWD for things invoked with bazel run
This allows programs that you run to access the original path it was run from.
It enables you to write rules to run code modification tools (refactoring, formatting, build file generation) without changing anything fundamental.
You can see an example of using it here, to run the gazelle build file generator.

See #3325 for the discussion that led to this suggestion

@johnynek
Copy link
Member

johnynek commented Sep 1, 2017

I like this solution. Seems useful to me.

@meteorcloudy meteorcloudy requested a review from ulfjack September 5, 2017 09:16
@meteorcloudy
Copy link
Member

@ulfjack, what do you think about this?

@ulfjack
Copy link
Contributor

ulfjack commented Sep 7, 2017

I'm not sure it's the right way to go, but it's a simple change and doesn't require any configuration. Seems reasonable. Needs test(s) and documentation.

@ianthehat
Copy link
Contributor Author

Happy to do that.
Do you have any pointers to tests that would be similar in nature to work from?

@philwo
Copy link
Member

philwo commented Sep 12, 2017

@ianthehat I'd suggest adding a shell integration test that uses "bazel run" to run a shell script that prints the contents of $BAZEL_PWD and ensure that the output is equal to the current $PWD in the test.

I think you could add it to this one: https://github.com/bazelbuild/bazel/blob/master/src/test/shell/integration/run_test.sh

The existing test methods should serve as examples on how it generally works. Feel free to ask here if you need more information.

@philwo philwo added category: misc > misc P3 We're not considering working on this, but happy to review a PR. (No assignee) type: feature request labels Sep 12, 2017
@hlopko
Copy link
Member

hlopko commented Oct 11, 2017

Friendly ping @ianthehat

@ianthehat
Copy link
Contributor Author

I basically abandoned this approach, because it still does not solve all the problems (we really need to release the lock as well).

Instead I have switched to using the bazel-run script, and recommending to people they download it from the repository and put it on their path somewhere. It's an annoying extra step, to have to tell people to do, and I really dislike telling people to curl a bash script, but it unlocks a lot more functionality.

curl --output bazel-run https://raw.githubusercontent.com/bazelbuild/bazel/master/scripts/bazel-run.sh && chmod +x bazel-run

@hlopko
Copy link
Member

hlopko commented Oct 11, 2017

So that means that this pull request should be closed, correct?

@ianthehat
Copy link
Contributor Author

Sure, unless someone else wants to take it on, I have no plans to add the test myself at this point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: misc > misc cla: yes P3 We're not considering working on this, but happy to review a PR. (No assignee) type: feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants