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: consolidate subcommand parsing and matching #96003

Merged
merged 1 commit into from
Apr 21, 2022

Conversation

aswild
Copy link
Contributor

@aswild aswild commented Apr 13, 2022

There's several places where the x.py command names are matched as
strings, leading to some inconsistencies and opportunities for cleanup.

  • Add Format, Clean, and Setup variants to builder::Kind.
  • Use Kind to parse the x.py subcommand name (including aliases)
  • Match on the subcommand Kind rather than strings when handling
    options and help text.
  • Several subcommands don't display any paths when run with -h -v even
    though the help text indicates that they should. Fix this and refactor
    so that manually keeping matches in sync isn't necessary.

Fixes #95937

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 13, 2022
@aswild
Copy link
Contributor Author

aswild commented Apr 13, 2022

r? @jyn514

@Mark-Simulacrum
Copy link
Member

@bors delegate=jyn514

@bors
Copy link
Contributor

bors commented Apr 13, 2022

✌️ @jyn514 can now approve this pull request

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

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

This looks like the right approach, thanks so much! My only concern is that there are a lot of unrelated changes along with the fix - I'd prefer to leave things as they are unless necessary, since bootstrap is very prone to regressions.

src/bootstrap/builder.rs Outdated Show resolved Hide resolved
src/bootstrap/builder.rs Show resolved Hide resolved
src/bootstrap/builder.rs Outdated Show resolved Hide resolved
pub fn get_help(build: &Build, kind: Kind) -> Option<String> {
let step_descriptions = Builder::get_step_descriptions(kind);
if step_descriptions.is_empty() {
return None;
Copy link
Member

Choose a reason for hiding this comment

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

Why did this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was part of the logic for printing the hint to run with -h -v to see available paths if and only if there are paths that we could list for that subcommand.

For example, in Rust now if you run ./x.py clippy -h it will suggest Run './x.py clippy -h -v' to see a list of available paths., but when you run ./x.py clippy -v -v it doesn't actually list any paths.

My assumption was that all of these commands could have useful paths to pass to them but I might be mistaken about that. It seems like check and clippy would take paths just like build does, but it kinda seems like clippy runs for "everything" in the build graph anyway and passing paths doesn't do much.

Is this specific list of commands which could print a list of paths for help text intentional and the others (clippy, check, fix) are supposed to be excluded?

Copy link
Member

@jyn514 jyn514 Apr 14, 2022

Choose a reason for hiding this comment

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

My assumption was that all of these commands could have useful paths to pass to them but I might be mistaken about that.

This is not currently true. There are several related issues:

  1. Not all commands accept paths. x clippy, as you noticed, runs on the whole tree. x clean does the same.
  2. Some commands that do not accept paths do not check whether a path was passed - x clippy src/bootstrap is exactly the same as an unconditional x clippy.
  3. Some commands the do accept paths do not go through StepDescription. For example x fmt src/bootstrap is perfectly valid and limits the changes to bootstrap itself, but there is no impl Step for Format description, because Step has no way to say "all paths".

Fixing those issues should wait for follow up PRs, I think. In the meantime, can you do the following:

  • Remove clippy and fix from the check arm and down to the vec![] arm. clippy is certainly not supported with paths, and fix has been broken for ages.
  • Change the code in usage that calls get_help to panic if -h -v is called for a subcommand that does not support paths. We should give the user an idea that something is broken rather than silently ignoring the flag.

"Run `./x.py {} -h -v` to see a list of available paths.",
subcommand.as_str()
);
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this refactoring necessary for the fix? Unrelated changes like this make the PR harder to review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's related to the logic in get_help(), see my comments there. I might have had the wrong idea about the desired behavior in this area.

src/bootstrap/flags.rs Show resolved Hide resolved
@jyn514
Copy link
Member

jyn514 commented Apr 13, 2022

@rustbot label -S-waiting-on-review +S-waiting-on-author +A-rustbuild +C-cleanup

@rustbot rustbot added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) C-cleanup Category: PRs that clean code up or issues documenting cleanup. 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 Apr 13, 2022
@aswild
Copy link
Contributor Author

aswild commented Apr 14, 2022

Thanks for the review and guidance! I'll get things cleaned up.

Regarding the bigger changes in get_help and usage, those were more about UX than straight refactoring, but now I'm questioning whether I'm going the right direction there.

It's not great for help text to say "run this other command for more info" when that other command doesn't actually have more info. I went the direction of providing that info (available build target paths) in more cases, but maybe not printing the -h -v hint is more appropriate. Let me know which you prefer.

@jyn514
Copy link
Member

jyn514 commented Apr 14, 2022

@aswild I think you took the right approach, I misunderstood the issues you were running into. I left suggestions in #96003 (comment) :)

There's several places where the x.py command names are matched as
strings, leading to some inconsistencies and opportunities for cleanup.

* Add Format, Clean, and Setup variants to builder::Kind.
* Use Kind to parse the x.py subcommand name (including aliases)
* Match on the subcommand Kind rather than strings when handling
  options and help text.
* Several subcommands don't display any paths when run with `-h -v` even
  though the help text indicates that they should. Fix this and refactor
  so that manually keeping matches in sync isn't necessary.

Fixes rust-lang#95937
@aswild aswild force-pushed the pr/bootstrap-subcommands-cleanup branch from c6d27bb to 870cb8e Compare April 16, 2022 18:57
@aswild
Copy link
Contributor Author

aswild commented Apr 16, 2022

Thanks for the suggestions! I implemented them and force-pushed a new patch set.

@jyn514
Copy link
Member

jyn514 commented Apr 16, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Apr 16, 2022

📌 Commit 870cb8e has been approved by jyn514

@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 Apr 16, 2022
@jyn514
Copy link
Member

jyn514 commented Apr 16, 2022

Thanks for the PR!

@aswild
Copy link
Contributor Author

aswild commented Apr 17, 2022

Thanks for the opportunity to contribute to Rust! Compilers are big and scary but I can wrap my head around tooling and build systems

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 20, 2022
…anup, r=jyn514

bootstrap: consolidate subcommand parsing and matching

There's several places where the x.py command names are matched as
strings, leading to some inconsistencies and opportunities for cleanup.

* Add Format, Clean, and Setup variants to builder::Kind.
* Use Kind to parse the x.py subcommand name (including aliases)
* Match on the subcommand Kind rather than strings when handling
  options and help text.
* Several subcommands don't display any paths when run with `-h -v` even
  though the help text indicates that they should. Fix this and refactor
  so that manually keeping matches in sync isn't necessary.

Fixes rust-lang#95937
@bors
Copy link
Contributor

bors commented Apr 21, 2022

⌛ Testing commit 870cb8e with merge 1dec35a...

@bors
Copy link
Contributor

bors commented Apr 21, 2022

☀️ Test successful - checks-actions
Approved by: jyn514
Pushing 1dec35a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 21, 2022
@bors bors merged commit 1dec35a into rust-lang:master Apr 21, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 21, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1dec35a): comparison url.

Summary:

  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: no relevant changes found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 1 0 0 0 1
mean2 2.3% N/A N/A N/A 2.3%
max 2.3% N/A N/A N/A 2.3%

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@rustbot rustbot added the perf-regression Performance regression. label Apr 21, 2022
@rylev
Copy link
Member

rylev commented Apr 26, 2022

This seems to be a possible case of the syn-1.0.89 opt becoming noisy since it is the only test case (in the full scenario) impacted. We should mark it as triaged for now until we figure out what's up with that benchmark.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.

Consolidate subcommand parsing in bootstrap
8 participants