Skip to content

Commit 5009823

Browse files
authored
Merge pull request #521 from knight42/change-static-site
Change upstream via $RUSTUP_DIST_SERVER
2 parents dc84b3d + 9763334 commit 5009823

File tree

9 files changed

+87
-53
lines changed

9 files changed

+87
-53
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,14 @@ Command | Description
357357
invocations. A toolchain with this name should be installed, or
358358
invocations will fail.
359359

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

365+
- `RUSTUP_DIST_ROOT` (default: `https://static.rust-lang.org/dist`)
366+
Deprecated. Use `RUSTUP_DIST_SERVER` instead.
367+
365368
- `RUSTUP_UPDATE_ROOT` (default `https://static.rust-lang.org/rustup/dist`)
366369
Sets the root URL for downloading self-updates.
367370

src/rustup-dist/src/dist.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ use std::env;
1515
use regex::Regex;
1616
use sha2::{Sha256, Digest};
1717

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

21+
// Deprecated
22+
pub const DEFAULT_DIST_ROOT: &'static str = "https://static.rust-lang.org/dist";
23+
2124
// A toolchain descriptor from rustup's perspective. These contain
2225
// 'partial target triples', which allow toolchain names like
2326
// 'stable-msvc' to work. Partial target triples though are parsed

src/rustup-dist/src/manifestation.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use config::Config;
55
use manifest::{Component, Manifest, TargettedPackage};
6-
use dist::{download_and_check, DownloadCfg, TargetTriple};
6+
use dist::{download_and_check, DownloadCfg, TargetTriple, DEFAULT_DIST_SERVER};
77
use component::{Components, Transaction, TarGzPackage, Package};
88
use temp;
99
use errors::*;
@@ -122,13 +122,20 @@ impl Manifestation {
122122
components_urls_and_hashes.push(c_u_h);
123123
}
124124

125+
let altered = temp_cfg.dist_server != DEFAULT_DIST_SERVER;
126+
125127
// Download component packages and validate hashes
126128
let mut things_to_install: Vec<(Component, temp::File)> = Vec::new();
127129
for (component, url, hash) in components_urls_and_hashes {
128130

129131
notify_handler(Notification::DownloadingComponent(&component.pkg,
130132
&self.target_triple,
131133
&component.target));
134+
let url = if altered {
135+
url.replace(DEFAULT_DIST_SERVER, temp_cfg.dist_server.as_str())
136+
} else {
137+
url
138+
};
132139

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

306314
notify_handler(Notification::DownloadingComponent("rust",
307315
&self.target_triple,

src/rustup-dist/src/temp.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub enum Notification<'a> {
3737

3838
pub struct Cfg {
3939
root_directory: PathBuf,
40+
pub dist_server: String,
4041
notify_handler: Box<Fn(Notification)>,
4142
}
4243

@@ -131,9 +132,10 @@ impl Display for Error {
131132
}
132133

133134
impl Cfg {
134-
pub fn new(root_directory: PathBuf, notify_handler: Box<Fn(Notification)>) -> Self {
135+
pub fn new(root_directory: PathBuf, dist_server: &str, notify_handler: Box<Fn(Notification)>) -> Self {
135136
Cfg {
136137
root_directory: root_directory,
138+
dist_server: dist_server.to_owned(),
137139
notify_handler: notify_handler,
138140
}
139141
}

src/rustup-dist/tests/dist.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustup_mock::{MockCommand, MockInstallerBuilder};
1717
use rustup_dist::prefix::InstallPrefix;
1818
use rustup_dist::ErrorKind;
1919
use rustup_dist::errors::Result;
20-
use rustup_dist::dist::{ToolchainDesc, TargetTriple};
20+
use rustup_dist::dist::{ToolchainDesc, TargetTriple, DEFAULT_DIST_SERVER};
2121
use rustup_dist::download::DownloadCfg;
2222
use rustup_dist::Notification;
2323
use rustup_utils::utils;
@@ -319,6 +319,7 @@ fn setup(edit: Option<&Fn(&str, &mut MockPackage)>,
319319

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

324325
let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap();

src/rustup-dist/tests/install.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern crate tempdir;
66
use rustup_dist::component::Components;
77
use rustup_dist::component::{DirectoryPackage, Package};
88
use rustup_dist::component::Transaction;
9+
use rustup_dist::dist::DEFAULT_DIST_SERVER;
910
use rustup_dist::temp;
1011
use rustup_dist::ErrorKind;
1112
use rustup_dist::Notification;
@@ -109,7 +110,7 @@ fn basic_install() {
109110
let prefix = InstallPrefix::from(instdir.path().to_owned());
110111

111112
let tmpdir = TempDir::new("multirust").unwrap();
112-
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
113+
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
113114
let notify = |_: Notification| ();
114115
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);
115116

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

149150
let tmpdir = TempDir::new("multirust").unwrap();
150-
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
151+
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
151152
let notify = |_: Notification| ();
152153
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);
153154

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

192193
let tmpdir = TempDir::new("multirust").unwrap();
193-
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
194+
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
194195
let notify = |_: Notification| ();
195196
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);
196197

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

244245
let tmpdir = TempDir::new("multirust").unwrap();
245-
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
246+
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
246247
let notify = |_: Notification| ();
247248
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);
248249

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

290291
let tmpdir = TempDir::new("multirust").unwrap();
291-
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
292+
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
292293
let notify = |_: Notification| ();
293294
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);
294295

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

334335
let tmpdir = TempDir::new("multirust").unwrap();
335-
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), Box::new(|_| ()));
336+
let tmpcfg = temp::Cfg::new(tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()));
336337
let notify = |_: Notification| ();
337338
let tx = Transaction::new(prefix.clone(), &tmpcfg, &notify);
338339

0 commit comments

Comments
 (0)