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

Exec bazel instead of subprocessing #566

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aaron-skydio
Copy link

@aaron-skydio aaron-skydio commented Mar 28, 2024

Instead of running bazel as a subprocess of bazelisk, replace bazelisk with bazel in the same process (in the case when bazelisk is only being used to invoke bazel once and then exit, as opposed to invoking bazel multiple times or post-processing output from bazel). This eliminates several classes of issues.

A couple concrete examples:

  • shells' segfault detection often does not fire on subprocesses, so doing bazel run //:something_that_segfaults will not cause bash to display that the process segfaulted if bazelisk subprocesses to bazel, but it does if bazelisk execs bazel.
  • terminal emulators that display the name of the running process currently display bazel, even once bazel run has execd the binary it built, since the running top-level process is still bazelisk; they should display the name of the binary, and they do after this change

syscall.Exec is not supported on windows, so this only applies to linux and macos.

@tjgq
Copy link
Contributor

tjgq commented Feb 6, 2025

@aaron-skydio I like this PR - I think it's a more definitive solution to the signal handling issues I partially fixed in edab5e0. Mind rebasing onto master so we can get this merged?

@aaron-skydio
Copy link
Author

Done!


// RunBazeliskWithArgsFuncAndConfigAndOut runs the main Bazelisk logic for the given ArgsFunc and Bazel
// repositories and config, writing its stdout to the passed writer.
func RunBazeliskWithArgsFuncAndConfigAndOut(argsFunc ArgsFunc, repos *Repositories, config config.Config, out io.Writer) (int, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of this function will break users (#526), so I'd like to keep it.
Also, in the current version the out parameter of runBazel is basically useless since it will always be nil.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks, I didn't realize bazelisk supported use as a library so I just looked for uses in bazelisk itself. Added it back.

Are there going to be callers who need to call one of these RunBazelisk functions with out == nil and have it return instead of execing? The way I've written this right now doesn't support that, and I'm not sure how you'd rather me do that if we need that - duplicate all these public functions with ExecBazelisk copies? Or add a flag to exec if possible or not?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I think if I were a user I'd want to have the behavior of these preserved to return instead of execing, so I've added Exec versions of the ones that make sense (without out) and left the Run ones to still run in a subprocess and return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants