Skip to content

Commit 31b02e2

Browse files
Nemo157syphar
authored andcommitted
Allow index-update during lockfile regeneration
Since the default index changed to the sparse-index we have had issues with regenerating the lockfile if the dependency list changed, we relied on the previous fetch having pulled down details for all crates to use, but now it's only guaranteed to have details on the crates in the original locked dependency list. If new versions of crates (like log 0.4.17 -> 0.4.19) changed what dependencies it used we wouldn't have the details on these dependencies to use the updated version in the lockfile.
1 parent c5fa27a commit 31b02e2

File tree

1 file changed

+55
-18
lines changed

1 file changed

+55
-18
lines changed

src/docbuilder/rustwide_builder.rs

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl RustwideBuilder {
408408
std::fs::remove_file(cargo_lock)?;
409409
Command::new(&self.workspace, self.toolchain.cargo())
410410
.cd(build.host_source_dir())
411-
.args(&["generate-lockfile", "-Zno-index-update"])
411+
.args(&["generate-lockfile"])
412412
.run()?;
413413
Command::new(&self.workspace, self.toolchain.cargo())
414414
.cd(build.host_source_dir())
@@ -885,9 +885,39 @@ pub(crate) struct BuildResult {
885885
#[cfg(test)]
886886
mod tests {
887887
use super::*;
888-
use crate::test::{assert_redirect, assert_success, wrapper};
888+
use crate::test::{assert_redirect, assert_success, wrapper, TestEnvironment};
889889
use serde_json::Value;
890890

891+
fn remove_cache_files(env: &TestEnvironment, crate_: &str, version: &str) -> Result<()> {
892+
let paths = [
893+
format!("cache/index.crates.io-6f17d22bba15001f/{crate_}-{version}.crate"),
894+
format!("src/index.crates.io-6f17d22bba15001f/{crate_}-{version}"),
895+
format!(
896+
"index/index.crates.io-6f17d22bba15001f/.cache/{}/{}/{crate_}",
897+
&crate_[0..2],
898+
&crate_[2..4]
899+
),
900+
];
901+
902+
for path in paths {
903+
let full_path = env
904+
.config()
905+
.rustwide_workspace
906+
.join("cargo-home/registry")
907+
.join(path);
908+
if full_path.exists() {
909+
info!("deleting {}", full_path.display());
910+
if full_path.is_file() {
911+
std::fs::remove_file(full_path)?;
912+
} else {
913+
std::fs::remove_dir_all(full_path)?;
914+
}
915+
}
916+
}
917+
918+
Ok(())
919+
}
920+
891921
#[test]
892922
#[ignore]
893923
fn test_build_crate() {
@@ -1136,22 +1166,7 @@ mod tests {
11361166
env.override_config(|cfg| cfg.include_default_targets = false);
11371167

11381168
// if the corrected dependency of the crate was already downloaded we need to remove it
1139-
let crate_file = env.config().rustwide_workspace.join(
1140-
"cargo-home/registry/cache/github.com-1ecc6299db9ec823/rand_core-0.5.1.crate",
1141-
);
1142-
let src_dir = env
1143-
.config()
1144-
.rustwide_workspace
1145-
.join("cargo-home/registry/src/github.com-1ecc6299db9ec823/rand_core-0.5.1");
1146-
1147-
if crate_file.exists() {
1148-
info!("deleting {}", crate_file.display());
1149-
std::fs::remove_file(crate_file)?;
1150-
}
1151-
if src_dir.exists() {
1152-
info!("deleting {}", src_dir.display());
1153-
std::fs::remove_dir_all(src_dir)?;
1154-
}
1169+
remove_cache_files(env, "rand_core", "0.5.1")?;
11551170

11561171
// Specific setup required:
11571172
// * crate has a binary so that it is published with a lockfile
@@ -1169,6 +1184,28 @@ mod tests {
11691184
});
11701185
}
11711186

1187+
#[test]
1188+
#[ignore]
1189+
fn test_locked_fails_unlocked_needs_new_unknown_deps() {
1190+
wrapper(|env| {
1191+
env.override_config(|cfg| cfg.include_default_targets = false);
1192+
1193+
// if the corrected dependency of the crate was already downloaded we need to remove it
1194+
remove_cache_files(env, "value-bag-sval2", "1.4.1")?;
1195+
1196+
// Similar to above, this crate fails to build with the published
1197+
// lockfile, but generating a new working lockfile requires
1198+
// introducing a completely new dependency (not just version) which
1199+
// would not have had its details pulled down from the sparse-index.
1200+
let crate_ = "docs_rs_test_incorrect_lockfile";
1201+
let version = "0.2.0";
1202+
let mut builder = RustwideBuilder::init(env).unwrap();
1203+
assert!(builder.build_package(crate_, version, PackageKind::CratesIo)?);
1204+
1205+
Ok(())
1206+
});
1207+
}
1208+
11721209
#[test]
11731210
#[ignore]
11741211
fn test_rustflags_are_passed_to_build_script() {

0 commit comments

Comments
 (0)