Skip to content

Commit 7a9ef08

Browse files
authored
Merge pull request #178 from Eh2406/master
capture_lockfile offline if available
2 parents d77a2f5 + b7703b3 commit 7a9ef08

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/docker.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub struct RustEnv<'a> {
3232
pub rustup_home: (PathBuf, Perm),
3333
pub target_dir: (PathBuf, Perm),
3434
pub cap_lints: &'a ExCapLints,
35+
pub enable_unstable_cargo_features: bool,
3536
}
3637

3738
pub struct MountConfig<'a> {
@@ -97,7 +98,7 @@ pub fn rust_container(config: RustEnv) -> ContainerConfig {
9798
},
9899
];
99100

100-
let env = vec![
101+
let mut env = vec![
101102
("USER_ID", format!("{}", user_id())),
102103
("CMD", config.args.join(" ")),
103104
("CARGO_INCREMENTAL", "0".to_string()),
@@ -107,6 +108,12 @@ pub fn rust_container(config: RustEnv) -> ContainerConfig {
107108
format!("--cap-lints={}", config.cap_lints.to_str()),
108109
),
109110
];
111+
if config.enable_unstable_cargo_features {
112+
env.push((
113+
"__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS",
114+
"nightly".to_string(),
115+
));
116+
}
110117

111118
ContainerConfig {
112119
image_name: IMAGE_NAME,

src/ex.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,12 @@ fn capture_lockfile_inner(
374374
path: &Path,
375375
toolchain: &Toolchain,
376376
) -> Result<()> {
377-
let args = &["generate-lockfile", "--manifest-path", "Cargo.toml"];
377+
let args = &[
378+
"generate-lockfile",
379+
"--manifest-path",
380+
"Cargo.toml",
381+
"-Zno-index-update",
382+
];
378383
toolchain
379384
.run_cargo(ex, path, args, CargoState::Unlocked, false)
380385
.chain_err(|| format!("unable to generate lockfile for {}", krate))?;

src/toolchain.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ impl Toolchain {
4444
}
4545
}
4646

47+
self.prep_offline_registry()?;
48+
4749
Ok(())
4850
}
4951

@@ -90,6 +92,10 @@ impl Toolchain {
9092
CargoState::Locked => docker::Perm::ReadOnly,
9193
CargoState::Unlocked => docker::Perm::ReadWrite,
9294
};
95+
96+
let enable_unstable_cargo_features =
97+
!toolchain_name.starts_with("nightly-") && args.iter().any(|a| a.starts_with("-Z"));
98+
9399
let rust_env = docker::RustEnv {
94100
args: &full_args,
95101
work_dir: (source_dir.into(), perm),
@@ -98,9 +104,27 @@ impl Toolchain {
98104
// This is configured as CARGO_TARGET_DIR by the docker container itself
99105
target_dir: (ex_target_dir, docker::Perm::ReadWrite),
100106
cap_lints: &ex.cap_lints,
107+
enable_unstable_cargo_features,
101108
};
102109
docker::run(&docker::rust_container(rust_env), quiet)
103110
}
111+
112+
pub fn prep_offline_registry(&self) -> Result<()> {
113+
// This nop cargo command is to update the registry
114+
// so we don't have to do it for each crate.
115+
let toolchain_arg = "+".to_string() + &self.rustup_name();
116+
let full_args = [&toolchain_arg, "search", "lazy_static"];
117+
RunCommand::new(&installed_binary("cargo"), &full_args)
118+
.local_rustup()
119+
.quiet(true)
120+
.run()
121+
.chain_err(|| {
122+
format!(
123+
"unable to update the index for toolchain {}",
124+
&self.rustup_name()
125+
)
126+
})
127+
}
104128
}
105129

106130
impl ToString for Toolchain {

0 commit comments

Comments
 (0)