-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(vendor)!: direct extraction for registry sources #15514
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
Changes from 4 commits
a506ceb
d760d6e
8fee50a
060ab41
12c8ba5
feb364d
0eeedae
79d17e7
0290e40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,14 +111,14 @@ fn sync( | |
opts: &VendorOptions<'_>, | ||
) -> CargoResult<VendorConfig> { | ||
let dry_run = false; | ||
let canonical_destination = try_canonicalize(opts.destination); | ||
let canonical_destination = canonical_destination.as_deref().unwrap_or(opts.destination); | ||
let dest_dir_already_exists = canonical_destination.exists(); | ||
let vendor_dir = try_canonicalize(opts.destination); | ||
let vendor_dir = vendor_dir.as_deref().unwrap_or(opts.destination); | ||
let vendor_dir_already_exists = vendor_dir.exists(); | ||
|
||
paths::create_dir_all(&canonical_destination)?; | ||
paths::create_dir_all(&vendor_dir)?; | ||
let mut to_remove = HashSet::new(); | ||
if !opts.no_delete { | ||
for entry in canonical_destination.read_dir()? { | ||
for entry in vendor_dir.read_dir()? { | ||
let entry = entry?; | ||
if !entry | ||
.file_name() | ||
|
@@ -247,7 +247,7 @@ fn sync( | |
}; | ||
|
||
sources.insert(id.source_id()); | ||
let dst = canonical_destination.join(&dst_name); | ||
let dst = vendor_dir.join(&dst_name); | ||
to_remove.remove(&dst); | ||
let cksum = dst.join(".cargo-checksum.json"); | ||
// Registries are the only immutable sources, | ||
|
@@ -265,14 +265,14 @@ fn sync( | |
let _ = fs::remove_dir_all(&dst); | ||
let pathsource = PathSource::new(src, id.source_id(), gctx); | ||
let paths = pathsource.list_files(pkg)?; | ||
let mut map = BTreeMap::new(); | ||
cp_sources(pkg, src, &paths, &dst, &mut map, &mut tmp_buf, gctx) | ||
let mut file_cksums = BTreeMap::new(); | ||
cp_sources(pkg, src, &paths, &dst, &mut file_cksums, &mut tmp_buf, gctx) | ||
.with_context(|| format!("failed to copy over vendored sources for: {}", id))?; | ||
|
||
// Finally, emit the metadata about this package | ||
let json = serde_json::json!({ | ||
"package": checksums.get(id), | ||
"files": map, | ||
"files": file_cksums, | ||
}); | ||
|
||
paths::write(&cksum, json.to_string())?; | ||
|
@@ -347,9 +347,9 @@ fn sync( | |
directory: opts.destination.to_string_lossy().replace("\\", "/"), | ||
}, | ||
); | ||
} else if !dest_dir_already_exists { | ||
} else if !vendor_dir_already_exists { | ||
// Nothing to vendor. Remove the destination dir we've just created. | ||
paths::remove_dir(canonical_destination)?; | ||
paths::remove_dir(vendor_dir)?; | ||
} | ||
|
||
Ok(VendorConfig { source: config }) | ||
|
@@ -368,26 +368,9 @@ fn cp_sources( | |
let p = p.as_ref(); | ||
let relative = p.strip_prefix(&src).unwrap(); | ||
|
||
match relative.to_str() { | ||
// Skip git config files as they're not relevant to builds most of | ||
// the time and if we respect them (e.g. in git) then it'll | ||
// probably mess with the checksums when a vendor dir is checked | ||
// into someone else's source control | ||
Some(".gitattributes" | ".gitignore" | ".git") => continue, | ||
|
||
// Temporary Cargo files | ||
Some(".cargo-ok") => continue, | ||
|
||
// Skip patch-style orig/rej files. Published crates on crates.io | ||
// have `Cargo.toml.orig` which we don't want to use here and | ||
// otherwise these are rarely used as part of the build process. | ||
Some(filename) => { | ||
if filename.ends_with(".orig") || filename.ends_with(".rej") { | ||
continue; | ||
} | ||
} | ||
_ => {} | ||
}; | ||
if !vendor_this(relative) { | ||
continue; | ||
} | ||
|
||
// Join pathname components individually to make sure that the joined | ||
// path uses the correct directory separators everywhere, since | ||
|
@@ -417,7 +400,7 @@ fn cp_sources( | |
&dst, | ||
&mut dst_opts, | ||
&mut contents.as_bytes(), | ||
"Generated Cargo.toml", | ||
Path::new("Generated Cargo.toml"), | ||
tmp_buf, | ||
)? | ||
} else { | ||
|
@@ -430,13 +413,7 @@ fn cp_sources( | |
.with_context(|| format!("failed to stat {:?}", p))?; | ||
dst_opts.mode(src_metadata.mode()); | ||
} | ||
copy_and_checksum( | ||
&dst, | ||
&mut dst_opts, | ||
&mut src, | ||
&p.display().to_string(), | ||
tmp_buf, | ||
)? | ||
copy_and_checksum(&dst, &mut dst_opts, &mut src, &p, tmp_buf)? | ||
}; | ||
|
||
cksums.insert(relative.to_str().unwrap().replace("\\", "/"), cksum); | ||
|
@@ -562,7 +539,7 @@ fn copy_and_checksum<T: Read>( | |
dst_path: &Path, | ||
dst_opts: &mut OpenOptions, | ||
contents: &mut T, | ||
contents_path: &str, | ||
contents_path: &Path, | ||
buf: &mut [u8], | ||
) -> CargoResult<String> { | ||
let mut dst = dst_opts | ||
|
@@ -584,3 +561,25 @@ fn copy_and_checksum<T: Read>( | |
.with_context(|| format!("failed to write to {:?}", dst_path))?; | ||
} | ||
} | ||
|
||
/// Filters files we want to vendor. | ||
/// | ||
/// `relative` is a path relative to the package root. | ||
fn vendor_this(relative: &Path) -> bool { | ||
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 we filter out Also, we're closing #11000 without having a test for that case 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. Got it rearranged. 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. 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. That was confusing. I approved your updates. 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. |
||
match relative.to_str() { | ||
// Skip git config files as they're not relevant to builds most of | ||
// the time and if we respect them (e.g. in git) then it'll | ||
// probably mess with the checksums when a vendor dir is checked | ||
// into someone else's source control | ||
Some(".gitattributes" | ".gitignore" | ".git") => false, | ||
|
||
// Temporary Cargo files | ||
Some(".cargo-ok") => false, | ||
|
||
// Skip patch-style orig/rej files. Published crates on crates.io | ||
// have `Cargo.toml.orig` which we don't want to use here and | ||
// otherwise these are rarely used as part of the build process. | ||
Some(p) if p.ends_with(".orig") || p.ends_with(".rej") => false, | ||
_ => true, | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.