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: improve debuggability (step 5) #127450

Merged
merged 15 commits into from
Jul 13, 2024

Conversation

Kobzol
Copy link
Contributor

@Kobzol Kobzol commented Jul 7, 2024

Continuation of #127321.

This PR improves the debuggability of command execution, by improving the output logged when a command fails (it now includes the exact location where the command was created and where it was executed), and also by adding a "drop bomb", which will panic if a command was created, but not executed (which is probably a bug).

Here is how the output of a failed command looks like:

Command "git" "foo" "[bar]" (failure_mode=Exit, stdout_mode=Capture, stderr_mode=Capture) did not execute successfully.
Expected success, got exit status: 1
Created at: src/core/build_steps/compile.rs:1699:9
Executed at: src/core/build_steps/compile.rs:1699:58

STDOUT ----


STDERR ----
git: 'foo' is not a git command. See 'git --help'.

And this is what is printed if you forget to execute a command:

thread 'main' panicked at /projects/personal/rust/rust/src/tools/build_helper/src/drop_bomb/mod.rs:42:13:
command constructed at `src/core/build_steps/compile.rs:1699:9` was dropped without being executed: `git`

Best reviewed commit by commit.

Tracking issue: #126819

r? @onur-ozkan

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs 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 Jul 7, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jul 7, 2024

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp.

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

The run-make-support library was changed

cc @jieyouxu

@rust-log-analyzer

This comment has been minimized.

@Kobzol
Copy link
Contributor Author

Kobzol commented Jul 7, 2024

The drop bomb is already hitting some cases where a command wasn't being executed.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Kobzol
Copy link
Contributor Author

Kobzol commented Jul 7, 2024

Ok, PR CI seems to have finally stabilized.

@rustbot ready

src/bootstrap/src/core/build_steps/dist.rs Show resolved Hide resolved
let host = self.host;
let compiler = builder.compiler(builder.top_stage, host);

builder.ensure(compile::Std::new(compiler, host));
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean this specific line or the whole step? I copy-pasted the whole step from the RunMakeSupport step.

Copy link
Member

Choose a reason for hiding this comment

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

This specific line. RunMakeSupport is using specific compiler in its type so it makes sense to ensure std for it. But we don't need to build the top stage compiler and std for testing build helper crate, using stage 0 compiler should be enough (and faster as we don't need to build entire tree for testing it). Same for CrateRunMakeSupport step too, it should use stage 0 compiler without needing to build compiler and std.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, changed it to stage 0.

src/bootstrap/src/utils/exec.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Jul 12, 2024

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

Kobzol added 12 commits July 12, 2024 20:14
So that it can be also used in bootstrap.
To enable the previously moved `DropBomb` tests.
Before, only the line was stored. This was enough for run-make tests, since these mostly only contain a single `rmake.rs` file, but not for bootstrap.
… it through the `as_command_mut` method

This will be useful for disarming drop bombs when the inner command is accessed.
This makes it harder to accidentally forget to execute a created command in bootstrap.
This should make it quicker to debug command failures.
Avoid printing useless information in the `Debug` output.
We can move the command creation to a block where it is clear that the command will be executed.
The code for running tests uses a custom command machinery because it streams the output of the command. We thus need to mark the command as executed in a dry run, to avoid a drop bomb panic.
If we're in dry run mode, the command will return an empty string, so we can just execute it.
There is no need to build a stage N toolchain for testing it.
@Kobzol
Copy link
Contributor Author

Kobzol commented Jul 12, 2024

Rebased to fix conflicts.

@onur-ozkan
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Jul 13, 2024

📌 Commit 72c3540 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 Jul 13, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 13, 2024
…nur-ozkan

Bootstrap command refactoring: improve debuggability (step 5)

Continuation of rust-lang#127321.

This PR improves the debuggability of command execution, by improving the output logged when a command fails (it now includes the exact location where the command was created and where it was executed), and also by adding a "drop bomb", which will panic if a command was created, but not executed (which is probably a bug).

Here is how the output of a failed command looks like:
```
Command "git" "foo" "[bar]" (failure_mode=Exit, stdout_mode=Capture, stderr_mode=Capture) did not execute successfully.
Expected success, got exit status: 1
Created at: src/core/build_steps/compile.rs:1699:9
Executed at: src/core/build_steps/compile.rs:1699:58

STDOUT ----

STDERR ----
git: 'foo' is not a git command. See 'git --help'.
```

And this is what is printed if you forget to execute a command:
```
thread 'main' panicked at /projects/personal/rust/rust/src/tools/build_helper/src/drop_bomb/mod.rs:42:13:
command constructed at `src/core/build_steps/compile.rs:1699:9` was dropped without being executed: `git`
```

Best reviewed commit by commit.

Tracking issue: rust-lang#126819

r? `@onur-ozkan`
@bors
Copy link
Contributor

bors commented Jul 13, 2024

⌛ Testing commit 72c3540 with merge 679b9c5...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jul 13, 2024

💔 Test failed - checks-actions

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

Kobzol commented Jul 13, 2024

Found two more cases of unused command executions.

@bors r=onur-ozkan rollup=never

@bors
Copy link
Contributor

bors commented Jul 13, 2024

📌 Commit 0cce0bb 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 Jul 13, 2024
@bors
Copy link
Contributor

bors commented Jul 13, 2024

⌛ Testing commit 0cce0bb with merge c1e3f03...

@bors
Copy link
Contributor

bors commented Jul 13, 2024

☀️ Test successful - checks-actions
Approved by: onur-ozkan
Pushing c1e3f03 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 13, 2024
@bors bors merged commit c1e3f03 into rust-lang:master Jul 13, 2024
7 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jul 13, 2024
@Kobzol Kobzol deleted the bootstrap-cmd-refactor-5 branch July 13, 2024 12:05
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c1e3f03): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 705.609s -> 704.365s (-0.18%)
Artifact size: 328.61 MiB -> 328.69 MiB (0.02%)

tgross35 added a commit to tgross35/rust that referenced this pull request Jul 16, 2024
…=onur-ozkan

Bootstrap command refactoring: port remaining commands with access to `Build` (step 6)

Continuation of rust-lang#127450.

This PR ports commands in bootstrap that can easily get access to `Build(er)` to `BootstrapCommand`. After this PR, everything that can access `Build(er)` should be using the new API.

Statistics of `bootstrap` code (ignoring `src/bin/<shims>`) after this PR:
```
7 usages of `Command::new`
69 usages of `command()` (new API)
 - out of that: 16 usages of `as_command_mut()` (new API, but accesses the inner command)
```

Tracking issue: rust-lang#126819

r? `@onur-ozkan`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 16, 2024
…nur-ozkan

Bootstrap command refactoring: port remaining commands with access to `Build` (step 6)

Continuation of rust-lang#127450.

This PR ports commands in bootstrap that can easily get access to `Build(er)` to `BootstrapCommand`. After this PR, everything that can access `Build(er)` should be using the new API.

Statistics of `bootstrap` code (ignoring `src/bin/<shims>`) after this PR:
```
7 usages of `Command::new`
69 usages of `command()` (new API)
 - out of that: 16 usages of `as_command_mut()` (new API, but accesses the inner command)
```

Tracking issue: rust-lang#126819

r? `@onur-ozkan`
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jul 20, 2024
Bootstrap command refactoring: port remaining commands with access to `Build` (step 6)

Continuation of rust-lang/rust#127450.

This PR ports commands in bootstrap that can easily get access to `Build(er)` to `BootstrapCommand`. After this PR, everything that can access `Build(er)` should be using the new API.

Statistics of `bootstrap` code (ignoring `src/bin/<shims>`) after this PR:
```
7 usages of `Command::new`
69 usages of `command()` (new API)
 - out of that: 16 usages of `as_command_mut()` (new API, but accesses the inner command)
```

Tracking issue: rust-lang/rust#126819

r? `@onur-ozkan`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs merged-by-bors This PR was explicitly merged by bors. 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
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants