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

Refactor change detection for rustdoc and download-rustc #131043

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

liwagu
Copy link
Contributor

@liwagu liwagu commented Sep 29, 2024

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:

Cleanup:

@rustbot
Copy link
Collaborator

rustbot commented Sep 29, 2024

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 29, 2024
@rustbot
Copy link
Collaborator

rustbot commented Sep 29, 2024

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

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

@rustbot rustbot added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 29, 2024
@rustbot
Copy link
Collaborator

rustbot commented Sep 29, 2024

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:

$ # rebase
$ git pull --rebase https://github.com/rust-lang/rust.git master
$ git push --force-with-lease

The following commits are merge commits:

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 29, 2024
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Sep 30, 2024

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

Comment on lines 2838 to 2846
/// 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> {
Copy link
Member

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.

Copy link
Contributor Author

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, "--"]);
Copy link
Member

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.

Copy link
Contributor Author

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,
Copy link
Member

@onur-ozkan onur-ozkan Oct 3, 2024

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?

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it is.

Copy link
Contributor Author

@liwagu liwagu Oct 5, 2024

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);
}

Copy link
Member

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.

@rust-log-analyzer

This comment has been minimized.

@onur-ozkan
Copy link
Member

@rustbot author

@rustbot rustbot 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 Oct 5, 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.

LGTM. Could you please squash your commits?

@liwagu
Copy link
Contributor Author

liwagu commented Oct 7, 2024

LGTM. Could you please squash your commits?

Yes. I refer this https://rustc-dev-guide.rust-lang.org/git.html#squash-your-commits and did git rebase --interactive HEAD~5

Comment on lines 2856 to 2862
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));
Copy link
Member

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 joined to config.src.

Copy link
Contributor Author

@liwagu liwagu Oct 8, 2024

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")])

Copy link
Member

@onur-ozkan onur-ozkan Oct 8, 2024

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")].

@albertlarsan68
Copy link
Member

Thanks for the PR!
@bors r+

@bors
Copy link
Contributor

bors commented Oct 17, 2024

📌 Commit 46d98ba has been approved by albertlarsan68

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 Oct 17, 2024
@onur-ozkan
Copy link
Member

This shouldn't be merged yet (see #131043 (comment)), that's why it was tagged as "waiting-on-author".

@bors r-

@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 Oct 17, 2024
@onur-ozkan
Copy link
Member

onur-ozkan commented Oct 23, 2024

LGTM once #131043 (comment) and #131043 (comment) are fixed and commits are squashed.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Oct 23, 2024
@rustbot
Copy link
Collaborator

rustbot commented Oct 23, 2024

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:

$ # rebase
$ git pull --rebase https://github.com/rust-lang/rust.git master
$ git push --force-with-lease

The following commits are merge commits:

@rustbot rustbot removed the has-merge-commits PR has merge commits, merge with caution. label Oct 23, 2024
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() {
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

@liwagu liwagu Oct 23, 2024

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

Copy link
Member

Choose a reason for hiding this comment

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

Yes, and these:

println!("help: consider disabling `{option_name}`");

println!(
"warning: saw changes to one of {modified_paths:?} since {commit}; \
ignoring `{option_name}`"
);

println!(
"warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
);

don't make any sense with invalid option name.

Copy link
Contributor Author

@liwagu liwagu Oct 23, 2024

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

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 23, 2024
@onur-ozkan
Copy link
Member

Thanks!

@bors r=albertlarsan68,onur-ozkan

@bors
Copy link
Contributor

bors commented Oct 23, 2024

📌 Commit 1b59216 has been approved by albertlarsan68,onur-ozkan

It is now in the queue for this repository.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Oct 23, 2024
fmease added a commit to fmease/rust that referenced this pull request Oct 23, 2024
…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`
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 23, 2024
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
@bors bors merged commit 4caa60c into rust-lang:master Oct 23, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 23, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 23, 2024
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``
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.

7 participants