Skip to content

Commit 150d644

Browse files
committed
rustbuild: split Install out of Dist subcommand
only create source tarball for the Dist subcommand mark install rule as default for Kind::Install split install-docs split install-std factor out empty_dir handling split install-cargo split install-analysis split install-src rework install-rustc properly handle cross-compilation setups for install use pkgname in install split plain source tarball generation from rust-src dist document src-tarball in config.toml.exmaple Signed-off-by: Marc-Antoine Perennou <[email protected]>
1 parent 81734e0 commit 150d644

File tree

7 files changed

+209
-140
lines changed

7 files changed

+209
-140
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ Read ["Installing Rust"] from [The Book].
3535
3. Build and install:
3636

3737
```sh
38-
$ ./x.py build && sudo ./x.py dist --install
38+
$ ./x.py build && sudo ./x.py install
3939
```
4040

4141
> ***Note:*** Install locations can be adjusted by copying the config file
4242
> from `./src/bootstrap/config.toml.example` to `./config.toml`, and
4343
> adjusting the `prefix` option under `[install]`. Various other options are
4444
> also supported, and are documented in the config file.
4545

46-
When complete, `sudo ./x.py dist --install` will place several programs into
46+
When complete, `sudo ./x.py install` will place several programs into
4747
`/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
4848
API-documentation tool. This install does not include [Cargo],
4949
Rust's package manager, which you may also want to build.
@@ -96,7 +96,7 @@ build.
9696
4. Navigate to Rust's source code (or clone it), then build it:
9797

9898
```sh
99-
$ ./x.py build && ./x.py dist --install
99+
$ ./x.py build && ./x.py install
100100
```
101101

102102
#### MSVC

src/bootstrap/config.toml.example

+6
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,9 @@
314314
# Note that this address should not contain a trailing slash as file names will
315315
# be appended to it.
316316
#upload-addr = "https://example.com/folder"
317+
318+
# Whether to build a plain source tarball to upload
319+
# We disable that on Windows not to override the one already uploaded on S3
320+
# as the one built on Windows will contain backslashes in paths causing problems
321+
# on linux
322+
#src-tarball = true

src/bootstrap/dist.rs

+91-91
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ use {Build, Compiler, Mode};
3030
use channel;
3131
use util::{cp_r, libdir, is_dylib, cp_filtered, copy, exe};
3232

33-
fn pkgname(build: &Build, component: &str) -> String {
33+
pub fn pkgname(build: &Build, component: &str) -> String {
3434
if component == "cargo" {
3535
format!("{}-{}", component, build.cargo_package_vers())
3636
} else if component == "rls" {
37-
format!("{}-{}", component, build.package_vers(&build.release_num("rls")))
37+
format!("{}-{}", component, build.rls_package_vers())
3838
} else {
3939
assert!(component.starts_with("rust"));
4040
format!("{}-{}", component, build.rust_package_vers())
@@ -369,38 +369,7 @@ pub fn analysis(build: &Build, compiler: &Compiler, target: &str) {
369369
t!(fs::remove_dir_all(&image));
370370
}
371371

372-
const CARGO_VENDOR_VERSION: &'static str = "0.1.4";
373-
374-
/// Creates the `rust-src` installer component and the plain source tarball
375-
pub fn rust_src(build: &Build) {
376-
if !build.config.rust_dist_src {
377-
return
378-
}
379-
380-
println!("Dist src");
381-
382-
// Make sure that the root folder of tarball has the correct name
383-
let plain_name = format!("rustc-{}-src", build.rust_package_vers());
384-
let plain_dst_src = tmpdir(build).join(&plain_name);
385-
let _ = fs::remove_dir_all(&plain_dst_src);
386-
t!(fs::create_dir_all(&plain_dst_src));
387-
388-
// This is the set of root paths which will become part of the source package
389-
let src_files = [
390-
"COPYRIGHT",
391-
"LICENSE-APACHE",
392-
"LICENSE-MIT",
393-
"CONTRIBUTING.md",
394-
"README.md",
395-
"RELEASES.md",
396-
"configure",
397-
"x.py",
398-
];
399-
let src_dirs = [
400-
"man",
401-
"src",
402-
];
403-
372+
fn copy_src_dirs(build: &Build, src_dirs: &[&str], dst_dir: &Path) {
404373
let filter_fn = move |path: &Path| {
405374
let spath = match path.to_str() {
406375
Some(path) => path,
@@ -429,60 +398,16 @@ pub fn rust_src(build: &Build) {
429398
};
430399

431400
// Copy the directories using our filter
432-
for item in &src_dirs {
433-
let dst = &plain_dst_src.join(item);
434-
t!(fs::create_dir(dst));
401+
for item in src_dirs {
402+
let dst = &dst_dir.join(item);
403+
t!(fs::create_dir_all(dst));
435404
cp_filtered(&build.src.join(item), dst, &filter_fn);
436405
}
437-
// Copy the files normally
438-
for item in &src_files {
439-
copy(&build.src.join(item), &plain_dst_src.join(item));
440-
}
441-
442-
// If we're building from git sources, we need to vendor a complete distribution.
443-
if build.src_is_git {
444-
// Get cargo-vendor installed, if it isn't already.
445-
let mut has_cargo_vendor = false;
446-
let mut cmd = Command::new(&build.cargo);
447-
for line in output(cmd.arg("install").arg("--list")).lines() {
448-
has_cargo_vendor |= line.starts_with("cargo-vendor ");
449-
}
450-
if !has_cargo_vendor {
451-
let mut cmd = Command::new(&build.cargo);
452-
cmd.arg("install")
453-
.arg("--force")
454-
.arg("--debug")
455-
.arg("--vers").arg(CARGO_VENDOR_VERSION)
456-
.arg("cargo-vendor")
457-
.env("RUSTC", &build.rustc);
458-
build.run(&mut cmd);
459-
}
460-
461-
// Vendor all Cargo dependencies
462-
let mut cmd = Command::new(&build.cargo);
463-
cmd.arg("vendor")
464-
.current_dir(&plain_dst_src.join("src"));
465-
build.run(&mut cmd);
466-
}
467-
468-
// Create the version file
469-
write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes());
470-
471-
// Create plain source tarball
472-
let mut tarball = rust_src_location(build);
473-
tarball.set_extension(""); // strip .gz
474-
tarball.set_extension(""); // strip .tar
475-
if let Some(dir) = tarball.parent() {
476-
t!(fs::create_dir_all(dir));
477-
}
478-
let mut cmd = rust_installer(build);
479-
cmd.arg("tarball")
480-
.arg("--input").arg(&plain_name)
481-
.arg("--output").arg(&tarball)
482-
.arg("--work-dir=.")
483-
.current_dir(tmpdir(build));
484-
build.run(&mut cmd);
406+
}
485407

408+
/// Creates the `rust-src` installer component
409+
pub fn rust_src(build: &Build) {
410+
println!("Dist src");
486411

487412
let name = pkgname(build, "rust-src");
488413
let image = tmpdir(build).join(format!("{}-image", name));
@@ -516,11 +441,7 @@ pub fn rust_src(build: &Build) {
516441
"src/rustc/libc_shim",
517442
];
518443

519-
for item in &std_src_dirs {
520-
let dst = &dst_src.join(item);
521-
t!(fs::create_dir_all(dst));
522-
cp_r(&plain_dst_src.join(item), dst);
523-
}
444+
copy_src_dirs(build, &std_src_dirs[..], &dst_src);
524445

525446
// Create source tarball in rust-installer format
526447
let mut cmd = rust_installer(build);
@@ -537,7 +458,86 @@ pub fn rust_src(build: &Build) {
537458
build.run(&mut cmd);
538459

539460
t!(fs::remove_dir_all(&image));
540-
t!(fs::remove_dir_all(&plain_dst_src));
461+
}
462+
463+
const CARGO_VENDOR_VERSION: &'static str = "0.1.4";
464+
465+
/// Creates the plain source tarball
466+
pub fn plain_source_tarball(build: &Build) {
467+
println!("Create plain source tarball");
468+
469+
// Make sure that the root folder of tarball has the correct name
470+
let plain_name = format!("{}-src", pkgname(build, "rustc"));
471+
let plain_dst_src = tmpdir(build).join(&plain_name);
472+
let _ = fs::remove_dir_all(&plain_dst_src);
473+
t!(fs::create_dir_all(&plain_dst_src));
474+
475+
// This is the set of root paths which will become part of the source package
476+
let src_files = [
477+
"COPYRIGHT",
478+
"LICENSE-APACHE",
479+
"LICENSE-MIT",
480+
"CONTRIBUTING.md",
481+
"README.md",
482+
"RELEASES.md",
483+
"configure",
484+
"x.py",
485+
];
486+
let src_dirs = [
487+
"man",
488+
"src",
489+
];
490+
491+
copy_src_dirs(build, &src_dirs[..], &plain_dst_src);
492+
493+
// Copy the files normally
494+
for item in &src_files {
495+
copy(&build.src.join(item), &plain_dst_src.join(item));
496+
}
497+
498+
// Create the version file
499+
write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes());
500+
501+
// If we're building from git sources, we need to vendor a complete distribution.
502+
if build.src_is_git {
503+
// Get cargo-vendor installed, if it isn't already.
504+
let mut has_cargo_vendor = false;
505+
let mut cmd = Command::new(&build.cargo);
506+
for line in output(cmd.arg("install").arg("--list")).lines() {
507+
has_cargo_vendor |= line.starts_with("cargo-vendor ");
508+
}
509+
if !has_cargo_vendor {
510+
let mut cmd = Command::new(&build.cargo);
511+
cmd.arg("install")
512+
.arg("--force")
513+
.arg("--debug")
514+
.arg("--vers").arg(CARGO_VENDOR_VERSION)
515+
.arg("cargo-vendor")
516+
.env("RUSTC", &build.rustc);
517+
build.run(&mut cmd);
518+
}
519+
520+
// Vendor all Cargo dependencies
521+
let mut cmd = Command::new(&build.cargo);
522+
cmd.arg("vendor")
523+
.current_dir(&plain_dst_src.join("src"));
524+
build.run(&mut cmd);
525+
}
526+
527+
// Create plain source tarball
528+
let mut tarball = rust_src_location(build);
529+
tarball.set_extension(""); // strip .gz
530+
tarball.set_extension(""); // strip .tar
531+
if let Some(dir) = tarball.parent() {
532+
t!(fs::create_dir_all(dir));
533+
}
534+
let mut cmd = rust_installer(build);
535+
cmd.arg("tarball")
536+
.arg("--input").arg(&plain_name)
537+
.arg("--output").arg(&tarball)
538+
.arg("--work-dir=.")
539+
.current_dir(tmpdir(build));
540+
build.run(&mut cmd);
541541
}
542542

543543
fn install(src: &Path, dstdir: &Path, perms: u32) {

src/bootstrap/flags.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ pub enum Subcommand {
6969
Clean,
7070
Dist {
7171
paths: Vec<PathBuf>,
72-
install: bool,
72+
},
73+
Install {
74+
paths: Vec<PathBuf>,
7375
},
7476
}
7577

@@ -85,7 +87,8 @@ Subcommands:
8587
bench Build and run some benchmarks
8688
doc Build documentation
8789
clean Clean out build directories
88-
dist Build and/or install distribution artifacts
90+
dist Build distribution artifacts
91+
install Install distribution artifacts
8992
9093
To learn more about a subcommand, run `./x.py <subcommand> -h`");
9194

@@ -125,7 +128,8 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
125128
|| (s == "bench")
126129
|| (s == "doc")
127130
|| (s == "clean")
128-
|| (s == "dist"));
131+
|| (s == "dist")
132+
|| (s == "install"));
129133
let subcommand = match possible_subcommands.first() {
130134
Some(s) => s,
131135
None => {
@@ -139,7 +143,6 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
139143
match subcommand.as_str() {
140144
"test" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); },
141145
"bench" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); },
142-
"dist" => { opts.optflag("", "install", "run installer as well"); },
143146
_ => { },
144147
};
145148

@@ -281,7 +284,11 @@ Arguments:
281284
"dist" => {
282285
Subcommand::Dist {
283286
paths: paths,
284-
install: matches.opt_present("install"),
287+
}
288+
}
289+
"install" => {
290+
Subcommand::Install {
291+
paths: paths,
285292
}
286293
}
287294
_ => {

0 commit comments

Comments
 (0)