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 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: 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
3 changes: 2 additions & 1 deletion src/rustup-dist/tests/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustup_mock::{MockCommand, MockInstallerBuilder};
use rustup_dist::prefix::InstallPrefix;
use rustup_dist::ErrorKind;
use rustup_dist::errors::Result;
use rustup_dist::dist::{ToolchainDesc, TargetTriple};
use rustup_dist::dist::{ToolchainDesc, TargetTriple, DEFAULT_DIST_SERVER};
use rustup_dist::download::DownloadCfg;
use rustup_dist::Notification;
use rustup_utils::utils;
Expand Down Expand Up @@ -319,6 +319,7 @@ fn setup(edit: Option<&Fn(&str, &mut MockPackage)>,

let work_tempdir = TempDir::new("multirust").unwrap();
let ref temp_cfg = temp::Cfg::new(work_tempdir.path().to_owned(),
DEFAULT_DIST_SERVER,
Box::new(|_| ()));

let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap();
Expand Down
13 changes: 7 additions & 6 deletions src/rustup-dist/tests/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate tempdir;
use rustup_dist::component::Components;
use rustup_dist::component::{DirectoryPackage, Package};
use rustup_dist::component::Transaction;
use rustup_dist::dist::DEFAULT_DIST_SERVER;
use rustup_dist::temp;
use rustup_dist::ErrorKind;
use rustup_dist::Notification;
Expand Down Expand Up @@ -109,7 +110,7 @@ fn basic_install() {
let prefix = InstallPrefix::from(instdir.path().to_owned());

let tmpdir = TempDir::new("multirust").unwrap();
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
let notify = |_: Notification| ();
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);

Expand Down Expand Up @@ -147,7 +148,7 @@ fn multiple_component_install() {
let prefix = InstallPrefix::from(instdir.path().to_owned());

let tmpdir = TempDir::new("multirust").unwrap();
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
let notify = |_: Notification| ();
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);

Expand Down Expand Up @@ -190,7 +191,7 @@ fn uninstall() {
let prefix = InstallPrefix::from(instdir.path().to_owned());

let tmpdir = TempDir::new("multirust").unwrap();
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
let notify = |_: Notification| ();
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);

Expand Down Expand Up @@ -242,7 +243,7 @@ fn component_bad_version() {
let prefix = InstallPrefix::from(instdir.path().to_owned());

let tmpdir = TempDir::new("multirust").unwrap();
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
let notify = |_: Notification| ();
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);

Expand Down Expand Up @@ -288,7 +289,7 @@ fn unix_permissions() {
let prefix = InstallPrefix::from(instdir.path().to_owned());

let tmpdir = TempDir::new("multirust").unwrap();
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
let notify = |_: Notification| ();
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);

Expand Down Expand Up @@ -332,7 +333,7 @@ fn install_to_prefix_that_does_not_exist() {
let prefix = InstallPrefix::from(does_not_exist.clone());

let tmpdir = TempDir::new("multirust").unwrap();
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
let notify = |_: Notification| ();
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);

Expand Down
Loading