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

Change upstream via $RUSTUP_DIST_SERVER #521

Merged
merged 7 commits into from
Jun 17, 2016
Merged
Show file tree
Hide file tree
Changes from 6 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: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,14 @@ Command | Description
invocations. A toolchain with this name should be installed, or
invocations will fail.

- `RUSTUP_DIST_ROOT` (default: `https://static.rust-lang.org/dist`)
Sets the root URL for downloading Rust toolchains and release
channel updates. You can change this to instead use a local mirror,
- `RUSTUP_DIST_SERVER` (default: `https://static.rust-lang.org`)
Sets the root URL for downloading static resources related to Rust.
You can change this to instead use a local mirror,
or to test the binaries from the staging directory.

- `RUSTUP_DIST_ROOT` (default: `https://static.rust-lang.org/dist`)
Deprecated. Use `RUSTUP_DIST_SERVER` instead.

- `RUSTUP_UPDATE_ROOT` (default `https://static.rust-lang.org/rustup/dist`)
Sets the root URL for downloading self-updates.

Expand Down
5 changes: 4 additions & 1 deletion src/rustup-dist/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ use std::env;
use regex::Regex;
use sha2::{Sha256, Digest};

pub const DEFAULT_DIST_ROOT: &'static str = "https://static.rust-lang.org/dist";
pub const DEFAULT_DIST_SERVER: &'static str = "https://static.rust-lang.org";
pub const UPDATE_HASH_LEN: usize = 20;

// Deprecated
pub const DEFAULT_DIST_ROOT: &'static str = "https://static.rust-lang.org/dist";

// A toolchain descriptor from rustup's perspective. These contain
// 'partial target triples', which allow toolchain names like
// 'stable-msvc' to work. Partial target triples though are parsed
Expand Down
12 changes: 10 additions & 2 deletions src/rustup-dist/src/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use config::Config;
use manifest::{Component, Manifest, TargettedPackage};
use dist::{download_and_check, DownloadCfg, TargetTriple};
use dist::{download_and_check, DownloadCfg, TargetTriple, DEFAULT_DIST_SERVER};
use component::{Components, Transaction, TarGzPackage, Package};
use temp;
use errors::*;
Expand Down Expand Up @@ -122,13 +122,20 @@ impl Manifestation {
components_urls_and_hashes.push(c_u_h);
}

let altered = temp_cfg.dist_server != DEFAULT_DIST_SERVER;

// Download component packages and validate hashes
let mut things_to_install: Vec<(Component, temp::File)> = Vec::new();
for (component, url, hash) in components_urls_and_hashes {

notify_handler(Notification::DownloadingComponent(&component.pkg,
&self.target_triple,
&component.target));
let url = if altered {
url.replace(DEFAULT_DIST_SERVER, temp_cfg.dist_server.as_str())
} else {
url
};

// Download each package to temp file
let temp_file = try!(temp_cfg.new_file());
Expand Down Expand Up @@ -301,7 +308,8 @@ impl Manifestation {
return Err(format!("binary package was not provided for '{}'",
self.target_triple.to_string()).into());
}
let url = url.unwrap();
// Only replace once. The cost is inexpensive.
let url = url.unwrap().replace(DEFAULT_DIST_SERVER, temp_cfg.dist_server.as_str());

notify_handler(Notification::DownloadingComponent("rust",
&self.target_triple,
Expand Down
4 changes: 3 additions & 1 deletion src/rustup-dist/src/temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum Notification<'a> {

pub struct Cfg {
root_directory: PathBuf,
pub dist_server: String,
notify_handler: Box<Fn(Notification)>,
}

Expand Down Expand Up @@ -131,9 +132,10 @@ impl Display for Error {
}

impl Cfg {
pub fn new(root_directory: PathBuf, notify_handler: Box<Fn(Notification)>) -> Self {
pub fn new(root_directory: PathBuf, dist_server: &str, notify_handler: Box<Fn(Notification)>) -> Self {
Cfg {
root_directory: root_directory,
dist_server: dist_server.to_owned(),
notify_handler: notify_handler,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rustup-mock/src/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub fn cmd(config: &Config, name: &str, args: &[&str]) -> Command {

pub fn env(config: &Config, cmd: &mut Command) {
cmd.env("RUSTUP_HOME", config.rustupdir.to_string_lossy().to_string());
cmd.env("RUSTUP_DIST_ROOT", format!("file://{}", config.distdir.join("dist").to_string_lossy()));
cmd.env("RUSTUP_DIST_SERVER", format!("file://{}", config.distdir.to_string_lossy()));
cmd.env("CARGO_HOME", config.cargodir.to_string_lossy().to_string());
cmd.env("RUSTUP_OVERRIDE_HOST_TRIPLE", this_host_triple());

Expand Down
39 changes: 27 additions & 12 deletions src/rustup/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pub struct Cfg {
pub temp_cfg: temp::Cfg,
pub gpg_key: Cow<'static, str>,
pub env_override: Option<String>,
pub dist_root_url: Cow<'static, str>,
pub dist_root_url: String,
pub dist_root_server: String,
pub notify_handler: Arc<Fn(Notification)>,
}

Expand All @@ -60,12 +61,6 @@ impl Cfg {
let toolchains_dir = multirust_dir.join("toolchains");
let update_hash_dir = multirust_dir.join("update-hashes");

let notify_clone = notify_handler.clone();
let temp_cfg = temp::Cfg::new(multirust_dir.join("tmp"),
Box::new(move |n| {
(notify_clone)(n.into())
}));

// GPG key
let gpg_key = if let Some(path) = env::var_os("RUSTUP_GPG_KEY")
.and_then(utils::if_not_empty) {
Expand All @@ -79,10 +74,29 @@ impl Cfg {
.ok()
.and_then(utils::if_not_empty);

let dist_root_url = env::var("RUSTUP_DIST_ROOT")
.ok()
.and_then(utils::if_not_empty)
.map_or(Cow::Borrowed(dist::DEFAULT_DIST_ROOT), Cow::Owned);
let dist_root_server = match env::var("RUSTUP_DIST_SERVER") {
Ok(ref s) if !s.is_empty() => {
s.clone()
}
_ => {
// For backward compatibility
env::var("RUSTUP_DIST_ROOT")
.ok()
.and_then(utils::if_not_empty)
.map_or(Cow::Borrowed(dist::DEFAULT_DIST_ROOT), Cow::Owned)
.as_ref()
.trim_right_matches("/dist")
.to_owned()
}
};

let notify_clone = notify_handler.clone();
let temp_cfg = temp::Cfg::new(multirust_dir.join("tmp"),
dist_root_server.as_str(),
Box::new(move |n| {
(notify_clone)(n.into())
}));
let dist_root = dist_root_server.clone() + "/dist";

Ok(Cfg {
multirust_dir: multirust_dir,
Expand All @@ -93,7 +107,8 @@ impl Cfg {
gpg_key: gpg_key,
notify_handler: notify_handler,
env_override: env_override,
dist_root_url: dist_root_url,
dist_root_url: dist_root,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch looks great now, but is it possible to remove this dist_root_url field completely? Looks like it's mainly used by rustup_dist::dist, so that module can just be changed to append "/dist".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brson I am afraid not.

The dist_root_url field is accessed in rustup::toolchain(see here), which is used to construct the DownloadCfg.

Because the type of DownloadCfg.dist_root is &str, it is impossible to assign a modified value.

dist_root_server: dist_root_server,
})
}

Expand Down