Skip to content
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

capture_lockfile offline if available #178

Merged
merged 3 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct RustEnv<'a> {
pub rustup_home: (PathBuf, Perm),
pub target_dir: (PathBuf, Perm),
pub cap_lints: &'a ExCapLints,
pub enable_unstable_cargo_features: bool,
}

pub struct MountConfig<'a> {
Expand Down Expand Up @@ -97,7 +98,7 @@ pub fn rust_container(config: RustEnv) -> ContainerConfig {
},
];

let env = vec![
let mut env = vec![
("USER_ID", format!("{}", user_id())),
("CMD", config.args.join(" ")),
("CARGO_INCREMENTAL", "0".to_string()),
Expand All @@ -107,6 +108,12 @@ pub fn rust_container(config: RustEnv) -> ContainerConfig {
format!("--cap-lints={}", config.cap_lints.to_str()),
),
];
if config.enable_unstable_cargo_features {
env.push((
"__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS",
"nightly".to_string(),
));
}

ContainerConfig {
image_name: IMAGE_NAME,
Expand Down
7 changes: 6 additions & 1 deletion src/ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,12 @@ fn capture_lockfile_inner(
path: &Path,
toolchain: &Toolchain,
) -> Result<()> {
let args = &["generate-lockfile", "--manifest-path", "Cargo.toml"];
let args = &[
"generate-lockfile",
"--manifest-path",
"Cargo.toml",
"-Zno-index-update",
];
toolchain
.run_cargo(ex, path, args, CargoState::Unlocked, false)
.chain_err(|| format!("unable to generate lockfile for {}", krate))?;
Expand Down
24 changes: 24 additions & 0 deletions src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ impl Toolchain {
}
}

self.prep_offline_registry()?;

Ok(())
}

Expand Down Expand Up @@ -90,6 +92,10 @@ impl Toolchain {
CargoState::Locked => docker::Perm::ReadOnly,
CargoState::Unlocked => docker::Perm::ReadWrite,
};

let enable_unstable_cargo_features =
!toolchain_name.starts_with("nightly-") && args.iter().any(|a| a.starts_with("-Z"));

let rust_env = docker::RustEnv {
args: &full_args,
work_dir: (source_dir.into(), perm),
Expand All @@ -98,9 +104,27 @@ impl Toolchain {
// This is configured as CARGO_TARGET_DIR by the docker container itself
target_dir: (ex_target_dir, docker::Perm::ReadWrite),
cap_lints: &ex.cap_lints,
enable_unstable_cargo_features,
};
docker::run(&docker::rust_container(rust_env), quiet)
}

pub fn prep_offline_registry(&self) -> Result<()> {
// This nop cargo command is to update the registry
// so we don't have to do it for each crate.
let toolchain_arg = "+".to_string() + &self.rustup_name();
let full_args = [&toolchain_arg, "search", "lazy_static"];
RunCommand::new(&installed_binary("cargo"), &full_args)
.local_rustup()
.quiet(true)
.run()
.chain_err(|| {
format!(
"unable to update the index for toolchain {}",
&self.rustup_name()
)
})
}
}

impl ToString for Toolchain {
Expand Down