bazelbuild / bazel-watcher

Tools for building Bazel targets when source files change.
Apache License 2.0
438 stars 114 forks source link

how to forward arguments to bazel ? #530

Closed teto closed 2 years ago

teto commented 2 years ago

Describe the bug I would like to be able to forward arguments to bazel (with ibazel Version 0.14.0).

ibazel run -- --run_under "export BAZEL_RUN_DIR=$(pwd) && cd \$BUILD_WORKING_DIRECTORY && " --run_under "export BAZEL_RUN_DIR=$(pwd) && cd \$BUILD_WORKING_DIRECTORY && "  //target`

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.handle(0xc000192000, {0x7ffcc278c268, 0x3}, {0xc00013c020, 0x0, 0x1010123b4874108})
    ibazel/main.go:197 +0x2be
main.main()
    ibazel/main.go:182 +0x2cc

Reproduction instructions Private repo but my previous command should work with any target

Expected behavior Can pass arguments to bazel

Version (please complete the following information):

Additional context I've found related issues in the tracker but no solution/workaround yet (putting the command in the bazelrc does not work for this scenario.

achew22 commented 2 years ago

There are a relatively finite list of flags that we pass down to Bazel. Since we have a list of them, we can handle them in most positions in argv. You should be able to just pass most of them, but if the flag you want to pass isn't in the list, you can add it here in a pr

https://github.com/bazelbuild/bazel-watcher/blob/a81ca7638158e0c320d19c88a18ca3d44138ed65/ibazel/main.go#L33

teto commented 2 years ago

why not pass forward all flags ibazel doesn't recognize ? adding them one by one seems like a lost cause, especially for a programs like bazel with billions flags that keep changing because google doesn't care about backwards compability. I dont know go but surely it's possible to at least for now mentions "unsupported flag" instead of:

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.handle(0xc000192000, {0x7ffcc278c268, 0x3}, {0xc00013c020, 0x0, 0x1010123b4874108})
    ibazel/main.go:197 +0x2be
main.main()
    ibazel/main.go:182 +0x2cc

(or maybe it's fixed on master, sry I have't tried)

achew22 commented 2 years ago

If you'd like to revisit the strategy for flag handling, I would love a PR to improve it! How can I help out with that process?

teto commented 2 years ago

thanks for the offer but I have 50 open PRs, I will try to merge those first. Just keep the issue open in case someone with more abilities/availibility want to take it on ?

achew22 commented 2 years ago

There is a pretty good system in place to pass flags that are already in that list. If it's needed, let's open another issue and discuss a design.

teto commented 2 years ago

I dont understand why you closed this ? why do we need to whitelist flags ? A change is needed hence the issue, closing the ticket wont make the problem go away.