-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Verify build-std resolve against original lockfile #13916
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
Closed
adamgemmell
wants to merge
1
commit into
rust-lang:master
from
adamgemmell:dev/adagem01/verify-std-lock
Closed
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ use crate::core::compiler::UnitInterner; | |
use crate::core::compiler::{CompileKind, CompileMode, RustcTargetData, Unit}; | ||
use crate::core::profiles::{Profiles, UnitFor}; | ||
use crate::core::resolver::features::{CliFeatures, FeaturesFor, ResolvedFeatures}; | ||
use crate::core::resolver::HasDevUnits; | ||
use crate::core::resolver::{EncodableResolve, HasDevUnits}; | ||
use crate::core::{Dependency, PackageId, PackageSet, Resolve, SourceId, Workspace}; | ||
use crate::ops::{self, Packages}; | ||
use crate::util::errors::CargoResult; | ||
|
@@ -125,9 +125,12 @@ pub fn resolve_std<'gctx>( | |
// now. Perhaps in the future features will be decoupled from the resolver | ||
// and it will be easier to control feature selection. | ||
let current_manifest = src_path.join("library/sysroot/Cargo.toml"); | ||
// TODO: Consider doing something to enforce --locked? Or to prevent the | ||
// lock file from being written, such as setting ephemeral. | ||
let mut std_ws = Workspace::new_virtual(src_path, current_manifest, virtual_manifest, gctx)?; | ||
let mut std_ws = | ||
Workspace::new_virtual(src_path.clone(), current_manifest, virtual_manifest, gctx)?; | ||
|
||
// The source checkout isn't managed by us, so setting ephemeral here | ||
// ensures the lockfile isn't updated. | ||
std_ws.set_ephemeral(true); | ||
// Don't require optional dependencies in this workspace, aka std's own | ||
// `[dev-dependencies]`. No need for us to generate a `Resolve` which has | ||
// those included because we'll never use them anyway. | ||
|
@@ -158,6 +161,47 @@ pub fn resolve_std<'gctx>( | |
HasDevUnits::No, | ||
crate::core::resolver::features::ForceAllTargets::No, | ||
)?; | ||
|
||
// Verify that we have resolved to a subset of the lockfile | ||
let lockfile = std::fs::read_to_string(&src_path.join("Cargo.lock")) | ||
.expect("Couldn't read the Rust source's lockfile"); | ||
|
||
let encoded_lockfile: EncodableResolve = toml::from_str(&lockfile).unwrap(); | ||
adamgemmell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let lockfile_packages = encoded_lockfile.package().expect("libstd has no packages!"); | ||
adamgemmell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for resolved_pkg in resolve.targeted_resolve.iter() { | ||
adamgemmell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let pkg_name = resolved_pkg.name().to_string(); | ||
let pkg_ver = resolved_pkg.version().to_string(); | ||
Comment on lines
+173
to
+174
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. why do we need to |
||
let lockfile_pkg = lockfile_packages.binary_search_by_key( | ||
&(pkg_name.as_str(), pkg_ver.as_str()), | ||
|p| (p.name(), p.version()) | ||
) | ||
adamgemmell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.and_then(|idx| Ok(&lockfile_packages[idx])) | ||
.unwrap_or_else(|_| | ||
panic!("Standard library's package graph changed during resolution: | ||
Package '{}' ({}) was present in the resolve but not in the original lockfile", | ||
resolved_pkg.name(), resolved_pkg.version()) | ||
); | ||
// If the lockfile wasn't sorted then the binary search result can be nonsensical | ||
assert!(lockfile_pkg.name() == pkg_name); | ||
|
||
for (dep, _) in resolve.targeted_resolve.deps(resolved_pkg) { | ||
adamgemmell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
lockfile_pkg.dependencies() | ||
.and_then(|deps| { | ||
deps.iter().find(|pkg| { | ||
pkg.name() == dep.name().as_str() | ||
&& (pkg.version() == None | ||
|| pkg.version() == Some(dep.version().to_string().as_str())) | ||
}) | ||
}) | ||
.unwrap_or_else(|| | ||
panic!("Standard library's package graph changed during resolution: | ||
Package '{}' ({}) was present as a dependency of '{} ({}) in the resolve but not in the lockfile", | ||
dep.name(), dep.version(), resolved_pkg.name(), resolved_pkg.version()) | ||
); | ||
adamgemmell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
Ok(( | ||
resolve.pkg_set, | ||
resolve.targeted_resolve, | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ authors = ["Alex Crichton <[email protected]>"] | |
edition = "2018" | ||
|
||
[dependencies] | ||
core = { path = "../core" } | ||
registry-dep-using-core = { version = "*", features = ['mockbuild'] } |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ authors = ["Alex Crichton <[email protected]>"] | |
edition = "2018" | ||
|
||
[dependencies] | ||
alloc = { path = "../alloc" } | ||
registry-dep-using-alloc = { version = "*", features = ['mockbuild'] } | ||
|
||
[features] | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.