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

Bootstrap command refactoring: port more Command usages to BootstrapCmd (step 2) #126822

Merged
merged 11 commits into from
Jun 29, 2024

Conversation

Kobzol
Copy link
Contributor

@Kobzol Kobzol commented Jun 22, 2024

This PR moves more of bootstrap to use BooststrapCmd, and also refactors the struct to allow it to serve as a proper command wrapper.

Tracking issue: #126819

Best reviewed commit-by-commit, I have been adding some helper impls along the way to ease the migration, and then later I remove some of them since they were no longer needed.

r? @onur-ozkan

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jun 22, 2024
@@ -1024,18 +1022,7 @@ impl Build {

/// Runs a command, printing out nice contextual information if it fails.
fn run(&self, cmd: &mut Command) {
self.run_cmd(BootstrapCommand::from(cmd).fail_fast().output_mode(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: fail_fast and the given output_mode are default in BootstrapCommand.

@onur-ozkan onur-ozkan added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 22, 2024
@Kobzol
Copy link
Contributor Author

Kobzol commented Jun 22, 2024

Rebased over #126731.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Jun 22, 2024
@@ -2070,7 +2071,7 @@ pub fn stream_cargo(
tail_args: Vec<String>,
cb: &mut dyn FnMut(CargoMessage<'_>),
) -> bool {
let mut cargo = Command::from(cargo);
let mut cargo = BootstrapCommand::from(cargo).command;
Copy link
Member

Choose a reason for hiding this comment

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

It seems like this usage makes it like building commands from std Command, so it will not be possible to profile/debug/log (pretty much any reason that this implementation was based on) the execution. The inner command should never be exposed to avoid this problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, I plan to address this later. I'm doing the refactoring step by step, by introducing compatibility layers in the meantime, otherwise, I'd have to change all usages at once and that would be very hard to review and implement for me. One of those compatibility layers is making the Command pub, so that I can access it when needed.

As one of the next N steps, I will make the command private, which will force me to deal with the more complex cases, like output streaming. But I don't want to do that yet, first I want to port all/most of the simple use-cases and iterate on the API.

@onur-ozkan onur-ozkan added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 28, 2024
Copy link
Member

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

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

It's hard to examine every Command<->BootstrapCommand because almost all of them look the same. I hope I didn't miss anything 🙂

Just some nits; other than that LGTM.

src/bootstrap/src/utils/exec.rs Show resolved Hide resolved
src/bootstrap/src/utils/exec.rs Show resolved Hide resolved
src/bootstrap/src/utils/exec.rs Show resolved Hide resolved
@Kobzol
Copy link
Contributor Author

Kobzol commented Jun 28, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 28, 2024
@onur-ozkan
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 28, 2024

📌 Commit 0c599cb has been approved by onur-ozkan

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 28, 2024
@bors
Copy link
Contributor

bors commented Jun 28, 2024

☔ The latest upstream changes (presumably #127076) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 28, 2024
This will make it easier to migrate existing commands to bootstrap command.
By allowing `run` to receive all of `BootstrapCmd`, `&mut BootstrapCmd`, `Command` and `&mut Command`.
@Kobzol
Copy link
Contributor Author

Kobzol commented Jun 28, 2024

Rebased.

@bors r=onur-ozkan

@bors
Copy link
Contributor

bors commented Jun 28, 2024

📌 Commit 2ebfcce has been approved by onur-ozkan

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 28, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 29, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#126822 (Bootstrap command refactoring: port more `Command` usages to `BootstrapCmd` (step 2))
 - rust-lang#126835 (Simplifications in match lowering)
 - rust-lang#126953 (std: separate TLS key creation from TLS access)
 - rust-lang#127045 (Rename `super_predicates_of` and similar queries to `explicit_*` to note that they're not elaborated)
 - rust-lang#127075 (rustc_data_structures: Explicitly check for 64-bit atomics support)
 - rust-lang#127101 (remove redundant match statement from dataflow const prop)
 - rust-lang#127102 (Rename fuchsia builder and bump Fuchsia)
 - rust-lang#127103 (Move binder and polarity parsing into `parse_generic_ty_bound`)
 - rust-lang#127108 (unify `dylib` and `bin_helpers` and create `shared_helpers::parse_value_from_args`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit dfa68f1 into rust-lang:master Jun 29, 2024
6 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jun 29, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 29, 2024
Rollup merge of rust-lang#126822 - Kobzol:bootstrap-cmd-refactor-2, r=onur-ozkan

Bootstrap command refactoring: port more `Command` usages to `BootstrapCmd` (step 2)

This PR moves more of bootstrap to use `BooststrapCmd`, and also refactors the struct to allow it to serve as a proper command wrapper.

Tracking issue: rust-lang#126819

Best reviewed commit-by-commit, I have been adding some helper impls along the way to ease the migration, and then later I remove some of them since they were no longer needed.

r? `@onur-ozkan`
@Kobzol Kobzol deleted the bootstrap-cmd-refactor-2 branch June 29, 2024 11:49
@klensy
Copy link
Contributor

klensy commented Jun 29, 2024

BootstrapCommand looks similar to rmake's Command wrapper, can it be potentially shared?

@Kobzol
Copy link
Contributor Author

Kobzol commented Jun 29, 2024

I thought about it, but I don't think it's a good idea. They seem similar, but they are actually quite different. In rmake, we want to make sure that all errors fail as soon and as loudly as possible, and we test the commands, so the API is accustomed to asserts. In bootstrap, we want to handle failures in various different ways, and we don't really need asserts. Trying to shoehorn both into a single abstraction would IMO lead to more complexity and a worse API. It's also not a lot of code, so I don't think it's needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants