facebook / buck

A fast build system that encourages the creation of small, reusable modules over a variety of platforms and languages.
https://buck.build
Apache License 2.0
8.56k stars 1.16k forks source link

[feature request] option to set working directory #2608

Open frankseide opened 3 years ago

frankseide commented 3 years ago

Hi, would it be possible to add an option like gmake's -C (--directory)?

  -C DIRECTORY, --directory=DIRECTORY
             Change to DIRECTORY before doing anything.

Right now, it seems I need to cd somewhere inside the buck project folder before being able to invoke buck. That is a little disruptive since most of the time my working directory is not inside the buck project directory, and setting the working directory changes my shell's global state. I cannot just "arrow up" to my buck command and hit enter, without also changing directory first.

Example: Instead of

pushd ~/MYBUCKPROJDIR
buck build //TARGETDIR:TARGET @mode/opt --out ~/bin
popd

I would like to do this:

buck build -C ~/MYBUCKPROJDIR //TARGETDIR:TARGET @mode/opt --out ~/bin

Note that this is not about specifying the relative target path, relative to the buck root. It is about being able to build without cd-ing out of my working directory outside of the buck project.

In my career, I have found gmake's -C option very convenient, and even added the same option to my own tools to avoid the state change.

Thanks!

KapJI commented 3 years ago

If you prefix target and mode file with // it should work anywhere in the repo. E.g.:

buck build //target @//mode/opt --out ~/bin
frankseide commented 3 years ago

Thanks for the quick response. I clarified my issue description that this is not about specifying the relative target path, relative to the buck root, but about being able to build without changing the working directory away from any working directory, which is most of the time outside the buck project folder. Thanks!

KapJI commented 3 years ago

Got it. Well, you're welcome to send the PR 🙂