-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: create ephemeral workspace for git source #13689
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
Open
Rustin170506
wants to merge
2
commits into
rust-lang:master
Choose a base branch
from
Rustin170506:rustin-patch-install-git
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2064,6 +2064,76 @@ fn git_install_reads_workspace_manifest() { | |
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn git_install_the_same_bin_twice_with_different_rev() { | ||
let project = git::new("foo", |project| { | ||
project | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[workspace] | ||
members = ["bin1"] | ||
"#, | ||
) | ||
.file("bin1/Cargo.toml", &basic_manifest("bin1", "0.1.0")) | ||
.file( | ||
"bin1/src/main.rs", | ||
r#"fn main() { println!("Hello, world!"); }"#, | ||
) | ||
}); | ||
let repository = git2::Repository::open(&project.root()).unwrap(); | ||
let first_rev = repository.revparse_single("HEAD").unwrap().id().to_string(); | ||
|
||
// Change the main.rs. | ||
fs::write( | ||
project.root().join("bin1/src/main.rs"), | ||
r#"fn main() { println!("Hello, world! 2"); }"#, | ||
) | ||
.expect("failed to write file"); | ||
git::commit(&repository); | ||
let second_rev = repository.revparse_single("HEAD").unwrap().id().to_string(); | ||
|
||
// Set up a temp target directory. | ||
let temp_dir = paths::root().join("temp-target"); | ||
cargo_process(&format!( | ||
"install --git {} --rev {} bin1 --target-dir {}", | ||
project.url().to_string(), | ||
second_rev, | ||
temp_dir.display() | ||
)) | ||
.with_stderr( | ||
"\ | ||
[UPDATING] git repository [..] | ||
[INSTALLING] bin1 v0.1.0 [..] | ||
[COMPILING] bin1 v0.1.0 [..] | ||
[FINISHED] [..] | ||
[INSTALLING] [..]home/.cargo/bin/bin1[..] | ||
[INSTALLED] package `bin1 [..] | ||
[WARNING] be sure to add [..] | ||
", | ||
) | ||
.run(); | ||
|
||
cargo_process(&format!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should have a comment or two pointing out we want to observe a rebuild? |
||
"install --git {} --rev {} bin1 --target-dir {}", | ||
project.url().to_string(), | ||
first_rev, | ||
temp_dir.display() | ||
)) | ||
.with_stderr( | ||
"\ | ||
[UPDATING] git repository [..] | ||
[INSTALLING] bin1 v0.1.0 [..] | ||
[COMPILING] bin1 v0.1.0 [..] | ||
[FINISHED] [..] | ||
[REPLACING] [..]home/.cargo/bin/bin1[..] | ||
[REPLACED] package `bin1 [..] | ||
[WARNING] be sure to add [..] | ||
", | ||
) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn install_git_with_symlink_home() { | ||
// Ensure that `cargo install` with a git repo is OK when CARGO_HOME is a | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
A bit worried about this change. The in-memory property isn't held for ephemeral workspaces after this patch. It is also a bit fragile because the workspace discovery logic is only guarded by the other place, which is not immediately clear and hard to track.
I wonder if we really need this line here.
git_install_reads_workspace_manifest
seems to fail if we don't dofind_root
, but does cargo ever useprofile
or anything from there? Things we might want to figure out:cargo install --git
current provide?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.
After this PR we can only check the manifest for errors. Before that, I belive that we could use any information defined by the workspace. For example lints etc.
Before this PR, we just load the whole workspace and create a workspace based on the root manifest.
After this PR, we create the workspace based on the specific package and we don't use the information from the root manifest. Only searched the root to see if there is an error in the manifest.
After this PR, we only checked the manifest, we don't respect workspace information anymore.
For example:
If we try
cargo install --git https://github.com/hi-rustin/test-cargo-git-install bin-tool;
Before this change:
After this change:
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.
From a workspace information perspective, I think this PR introduces some regression.
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.
workspace is a feature which should not be there as it complicates all optimizations? it is only there because CARGO_TARGET_DIR does not work very well, isn't it?
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.
workspace is already there so to move forward we need to first figure out the feature set
cargo install --git
offers. However, I agree with soloturn, we may need to step back a bit to re-evaludate the bug.Both workspace initialization and
CARGO_TARGET_DIR
are symptoms of the bug. From my previous investigation, the bug is in workspace, members are collected as fromPathSource
, hencecargo install
recognizes the as path dependencies. In contrast, when using ingit
dependency, workspace members will be marked as fromGitSource
. I wonder if we should mark the entire workspace with the same source as the root one forcargo install
. Thinking of nested packages rust-lang/rfcs#3452, if we had that today, we might also need this, otherwise nested package will be marked as from local path and never get updated.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 it's hard to say the workspace feature complicates all optimizations. As my example in https://github.com/hi-rustin/test-cargo-git-install, respect workspace information will help us avoid inconsistency.
The problem is not caused by the CARGO_TARGET_DIR. If users set a CARGO_TARGET_DIR, then all compilation would happen in the CARGO_TARGET_DIR.
The problem here is as @weihanglo said, we cannot rebuild the binary after the git repository is updated.
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 sounds like a reasonable solution, I will take a look.
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've looked at how we calculate the fingerprint of the path member.
It seems we always try to track the workspace as much as possible.
So I am not sure what you mean by
mark the entire workspace with the same source
. Can you explain it a little bit?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.
When we read a dependency from a Git source, no matter it is a single package or workspace member, it always returns a
PackageId
withSourceKind::Git
. Under the hood it is actually aPathSource
assoicated with a GitSourceId
. This helps Cargo track the actual source.cargo/src/cargo/sources/git/source.rs
Lines 360 to 365 in b9d913e
However, in
cargo install
we use workspace to find members so we lost that sticky fashion.