-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Refactor change detection for rustdoc and download-rustc #131043
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @albertlarsan68 (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This PR modifies If appropriate, please update |
There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged. You can start a rebase with the following commands:
The following commits are merge commits: |
This comment has been minimized.
This comment has been minimized.
100ac12
to
da6754f
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #131063) made this pull request unmergeable. Please resolve the merge conflicts. |
ed198f7
to
174e36f
Compare
/// Check for changes in specified directories since a given commit. | ||
/// Returns Some(true) if changes exist, Some(false) if no changes, None if check should be ignored. | ||
pub fn check_for_changes( | ||
&self, | ||
dirs: &[PathBuf], | ||
commit: &str, | ||
option_name: &str, | ||
if_unchanged: bool, | ||
) -> Option<bool> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should have only one purpose: check whether there are changes or not. There is no need to add if_unchanged
argument and an optional result type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. done.
if_unchanged: bool, | ||
) -> Option<bool> { | ||
let mut git = helpers::git(Some(&self.src)); | ||
git.args(["diff-index", "--quiet", commit, "--"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add "--"
separately with if !dirs.is_empty()
check above the for dir in dirs
line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. done.
pub fn check_for_changes( | ||
&self, | ||
dirs: &[PathBuf], | ||
commit: &str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about removing this argument and moving commit finding logic into the function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commit: &str
Is this the argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure if this is appropriate; the original annotations in config.rs may need to be changed.
if commit.is_empty() {
println!("ERROR: could not find commit hash for downloading rustc");
println!("HELP: maybe your repository history is too shallow?");
println!("HELP: consider disabling `download-rustc`");
println!("HELP: or fetch enough history to include one upstream commit");
crate::exit!(1);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That check is needed for any usage not only for config.rs
module. If commit.is_empty()
we could return an error from check_for_changes
.
This comment has been minimized.
This comment has been minimized.
@rustbot author |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Could you please squash your commits?
cfc54ea
to
57c439e
Compare
Yes. I refer this https://rustc-dev-guide.rust-lang.org/git.html#squash-your-commits and did |
57c439e
to
ac8a7d1
Compare
pub fn check_for_changes(&self, dirs: &[PathBuf], commit: &str) -> bool { | ||
let mut git = helpers::git(Some(&self.src)); | ||
git.args(["diff-index", "--quiet", commit]); | ||
if !dirs.is_empty() { | ||
git.arg("--"); | ||
for dir in dirs { | ||
git.arg(self.src.join(dir)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this part in the previous reviews, sorry about that. Could you please accept the directory paths as they are and join
them outside? Right now it's quite unclear and there's a high chance that some contributors might provide paths that are already join
ed to config.src
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does contributors provide the path from?
In the previous code, I only saw hardcoded: .args([self.src.join("compiler"), self.src.join("library")])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just don't modify the given paths in check_for_changes
function and from the caller side pass them like [self.src.join("compiler"), self.src.join("library")]
.
Thanks for the PR! |
This shouldn't be merged yet (see #131043 (comment)), that's why it was tagged as "waiting-on-author". @bors r- |
46d98ba
to
9133a8e
Compare
9133a8e
to
c5cc78d
Compare
LGTM once #131043 (comment) and #131043 (comment) are fixed and commits are squashed. |
There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged. You can start a rebase with the following commands:
The following commits are merge commits: |
32197a7
to
df09ae2
Compare
let files_to_track = &["src/librustdoc", "src/tools/rustdoc"]; | ||
|
||
// Check if unchanged | ||
if builder.config.last_modified_commit(files_to_track, "rustdoc", true).is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this "rustdoc" value here sorry; it should be "download-rustc" instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why it shoud be that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is gated from "download-rustc" option and there is no option such "rustdoc" in config.toml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed option_name
appears as logs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and these:
rust/src/bootstrap/src/core/config/config.rs
Line 2878 in 9abfcb4
println!("help: consider disabling `{option_name}`"); |
rust/src/bootstrap/src/core/config/config.rs
Lines 2898 to 2901 in 9abfcb4
println!( | |
"warning: saw changes to one of {modified_paths:?} since {commit}; \ | |
ignoring `{option_name}`" | |
); |
rust/src/bootstrap/src/core/config/config.rs
Lines 2905 to 2907 in 9abfcb4
println!( | |
"warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}" | |
); |
don't make any sense with invalid option name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is gated from "download-rustc" option and there is no option such "rustdoc" in config.toml.
Ah, I haven't thought that far ahead; not thought about connecting these code changes to config.toml
yet. To be honest, I'm not sure how they're linked.
but I will change it for now
df09ae2
to
1b59216
Compare
Thanks! @bors r=albertlarsan68,onur-ozkan |
…r-ozkan Refactor change detection for rustdoc and download-rustc This pull request refactors the change detection logic in the build process by consolidating redundant code into a new helper method. The key changes include the removal of duplicate logic for checking changes in directories and the addition of a new method to handle this functionality. Refactoring and code simplification: * [`src/bootstrap/src/core/build_steps/tool.rs`](diffhunk://#diff-dc86e288bcf7b3ca3f8c127d3568fbafc785704883bc7fc336bd185910aed5daL588-R593): Removed redundant change detection logic and replaced it with a call to the new `check_for_changes` method. * [`src/bootstrap/src/core/config/config.rs`](diffhunk://#diff-5f5330cfcdb0a89b85ac3547b761c3a45c2534a85c4aaae8fea88c711a7a65b2R2837-R2872): Added a new method `check_for_changes` to centralize the logic for detecting changes in specified directories since a given commit. * [`src/bootstrap/src/core/config/config.rs`](diffhunk://#diff-5f5330cfcdb0a89b85ac3547b761c3a45c2534a85c4aaae8fea88c711a7a65b2L2728-R2740): Updated the existing change detection code to use the new `check_for_changes` method. Cleanup: * [`src/bootstrap/src/core/build_steps/tool.rs`](diffhunk://#diff-dc86e288bcf7b3ca3f8c127d3568fbafc785704883bc7fc336bd185910aed5daL13-R13): Removed the unused import `git` from the helpers module. r? `@AlbertLarsan68`
Rollup of 5 pull requests Successful merges: - rust-lang#131043 (Refactor change detection for rustdoc and download-rustc) - rust-lang#131181 (Compiletest: Custom differ) - rust-lang#131487 (Add wasm32v1-none target (compiler-team/rust-lang#791)) - rust-lang#132054 (do not remove `.cargo` directory) - rust-lang#132058 (CI: rfl: use rust-next temporary commit) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#131043 - liwagu:unify, r=albertlarsan68,onur-ozkan Refactor change detection for rustdoc and download-rustc This pull request refactors the change detection logic in the build process by consolidating redundant code into a new helper method. The key changes include the removal of duplicate logic for checking changes in directories and the addition of a new method to handle this functionality. Refactoring and code simplification: * [`src/bootstrap/src/core/build_steps/tool.rs`](diffhunk://#diff-dc86e288bcf7b3ca3f8c127d3568fbafc785704883bc7fc336bd185910aed5daL588-R593): Removed redundant change detection logic and replaced it with a call to the new `check_for_changes` method. * [`src/bootstrap/src/core/config/config.rs`](diffhunk://#diff-5f5330cfcdb0a89b85ac3547b761c3a45c2534a85c4aaae8fea88c711a7a65b2R2837-R2872): Added a new method `check_for_changes` to centralize the logic for detecting changes in specified directories since a given commit. * [`src/bootstrap/src/core/config/config.rs`](diffhunk://#diff-5f5330cfcdb0a89b85ac3547b761c3a45c2534a85c4aaae8fea88c711a7a65b2L2728-R2740): Updated the existing change detection code to use the new `check_for_changes` method. Cleanup: * [`src/bootstrap/src/core/build_steps/tool.rs`](diffhunk://#diff-dc86e288bcf7b3ca3f8c127d3568fbafc785704883bc7fc336bd185910aed5daL13-R13): Removed the unused import `git` from the helpers module. r? ``@AlbertLarsan68``
This pull request refactors the change detection logic in the build process by consolidating redundant code into a new helper method. The key changes include the removal of duplicate logic for checking changes in directories and the addition of a new method to handle this functionality.
Refactoring and code simplification:
src/bootstrap/src/core/build_steps/tool.rs
: Removed redundant change detection logic and replaced it with a call to the newcheck_for_changes
method.src/bootstrap/src/core/config/config.rs
: Added a new methodcheck_for_changes
to centralize the logic for detecting changes in specified directories since a given commit.src/bootstrap/src/core/config/config.rs
: Updated the existing change detection code to use the newcheck_for_changes
method.Cleanup:
src/bootstrap/src/core/build_steps/tool.rs
: Removed the unused importgit
from the helpers module.r? @albertlarsan68