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

Some test changes for component install #667

Merged
merged 1 commit into from
Aug 19, 2016
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
3 changes: 2 additions & 1 deletion src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,13 @@ fn component_list(cfg: &Cfg, m: &ArgMatches) -> Result<()> {

fn component_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
let toolchain = try!(explicit_or_dir_toolchain(cfg, m));
let component = m.value_of("component").expect("");
let target = m.value_of("target").map(TargetTriple::from_str).or_else(|| {
toolchain.desc().as_ref().ok().map(|desc| desc.target.clone())
});

let new_component = Component {
pkg: "rust-std".to_string(),
pkg: component.to_string(),
target: target,
};

Expand Down
18 changes: 18 additions & 0 deletions src/rustup-mock/src/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ fn build_mock_channel(s: Scenario, channel: &str, date: &str,
let rust = build_combined_installer(&[&std, &rustc, &cargo, &rust_docs]);
let cross_std1 = build_mock_cross_std_installer(CROSS_ARCH1, date);
let cross_std2 = build_mock_cross_std_installer(CROSS_ARCH2, date);
let rust_src = build_mock_rust_src_installer();

// Convert the mock installers to mock package definitions for the
// mock dist server
Expand All @@ -360,6 +361,7 @@ fn build_mock_channel(s: Scenario, channel: &str, date: &str,
("rustc", vec![(rustc, host_triple.clone())]),
("cargo", vec![(cargo, host_triple.clone())]),
("rust-docs", vec![(rust_docs, host_triple.clone())]),
("rust-src", vec![(rust_src, "*".to_string())]),
("rust", vec![(rust, host_triple.clone())])];

if s == Scenario::MultiHost {
Expand All @@ -370,6 +372,7 @@ fn build_mock_channel(s: Scenario, channel: &str, date: &str,
let rust = build_combined_installer(&[&std, &rustc, &cargo, &rust_docs]);
let cross_std1 = build_mock_cross_std_installer(CROSS_ARCH1, date);
let cross_std2 = build_mock_cross_std_installer(CROSS_ARCH2, date);
let rust_src = build_mock_rust_src_installer();

let triple = MULTI_ARCH1.to_string();
let more = vec![("rust-std", vec![(std, triple.clone()),
Expand All @@ -378,6 +381,7 @@ fn build_mock_channel(s: Scenario, channel: &str, date: &str,
("rustc", vec![(rustc, triple.clone())]),
("cargo", vec![(cargo, triple.clone())]),
("rust-docs", vec![(rust_docs, triple.clone())]),
("rust-src", vec![(rust_src, "*".to_string())]),
("rust", vec![(rust, triple.clone())])];

all.extend(more);
Expand Down Expand Up @@ -431,6 +435,10 @@ fn build_mock_channel(s: Scenario, channel: &str, date: &str,
name: "rust-std".to_string(),
target: CROSS_ARCH2.to_string(),
});
target_pkg.extensions.push(MockComponent {
name: "rust-src".to_string(),
target: "*".to_string(),
});
}
}

Expand Down Expand Up @@ -528,6 +536,16 @@ fn build_mock_rust_doc_installer() -> MockInstallerBuilder {
}
}

fn build_mock_rust_src_installer() -> MockInstallerBuilder {
MockInstallerBuilder {
components: vec![
("rust-src".to_string(),
vec![MockCommand::File("lib/rustlib/src/rust-src/foo.rs".to_string())],
vec![("lib/rustlib/src/rust-src/foo.rs".to_string(), "".into())])
]
}
}

fn build_combined_installer(components: &[&MockInstallerBuilder]) -> MockInstallerBuilder {
MockInstallerBuilder {
components: components.iter().flat_map(|m| m.components.clone()).collect()
Expand Down
18 changes: 15 additions & 3 deletions src/rustup-mock/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ impl MockDistServer {
let tmpdir = TempDir::new("multirust").unwrap();

let workdir = tmpdir.path().join("work");
let ref installer_name = format!("{}-{}-{}", package.name, channel.name, target_package.target);
let ref installer_name = if target_package.target != "*" {
format!("{}-{}-{}", package.name, channel.name, target_package.target)
} else {
format!("{}-{}", package.name, channel.name)
};
let ref installer_dir = workdir.join(installer_name);
let ref installer_tarball = archive_dir.join(format!("{}.tar.gz", installer_name));
let ref installer_hash = archive_dir.join(format!("{}.tar.gz.sha256", installer_name));
Expand Down Expand Up @@ -182,7 +186,11 @@ impl MockDistServer {
let mut buf = String::new();
let package = channel.packages.iter().find(|p| p.name == "rust").unwrap();
for target in &package.targets {
let package_file_name = format!("{}-{}-{}.tar.gz", package.name, channel.name, target.target);
let package_file_name = if target.target != "*" {
format!("{}-{}-{}.tar.gz", package.name, channel.name, target.target)
} else {
format!("{}-{}.tar.gz", package.name, channel.name)
};
buf = buf + &package_file_name + "\n";
}

Expand Down Expand Up @@ -220,7 +228,11 @@ impl MockDistServer {
let mut toml_target = toml::Table::new();
toml_target.insert(String::from("available"), toml::Value::Boolean(target.available));

let package_file_name = format!("{}-{}-{}.tar.gz", package.name, channel.name, target.target);
let package_file_name = if target.target != "*" {
format!("{}-{}-{}.tar.gz", package.name, channel.name, target.target)
} else {
format!("{}-{}.tar.gz", package.name, channel.name)
};
let path = self.path.join("dist").join(&channel.date).join(package_file_name);
let url = format!("file://{}", path.to_string_lossy());
toml_target.insert(String::from("url"), toml::Value::String(url));
Expand Down
12 changes: 12 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,15 @@ fn proxy_toolchain_shorthand() {
expect_stdout_ok(config, &["rustc", "+nightly", "--version"], "hash-n-2");
});
}

#[test]
fn src_component_smoke_test() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "stable"]);
expect_ok(config, &["rustup", "component", "add", "rust-src"]);
let path = format!("toolchains/{}/lib/rustlib/src/rust-src/foo.rs",
this_host_triple());
let path = config.rustupdir.join(path);
assert!(path.exists());
});
}