Skip to content

Commit a11c26f

Browse files
committed
Auto merge of #42109 - Keruspe:master, r=alexcrichton
rustbuild: don't create a source tarball when installing This splits Install out of Dist as it is not a full dist anymore, and creates the source tarball only for the Dist command. This will allow splitting install in a few rules if we want as it's done for other phases.
2 parents 3e7908f + d0ea705 commit a11c26f

File tree

7 files changed

+210
-144
lines changed

7 files changed

+210
-144
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())
@@ -489,38 +489,7 @@ pub fn analysis(build: &Build, compiler: &Compiler, target: &str) {
489489
t!(fs::remove_dir_all(&image));
490490
}
491491

492-
const CARGO_VENDOR_VERSION: &'static str = "0.1.4";
493-
494-
/// Creates the `rust-src` installer component and the plain source tarball
495-
pub fn rust_src(build: &Build) {
496-
if !build.config.rust_dist_src {
497-
return
498-
}
499-
500-
println!("Dist src");
501-
502-
// Make sure that the root folder of tarball has the correct name
503-
let plain_name = format!("rustc-{}-src", build.rust_package_vers());
504-
let plain_dst_src = tmpdir(build).join(&plain_name);
505-
let _ = fs::remove_dir_all(&plain_dst_src);
506-
t!(fs::create_dir_all(&plain_dst_src));
507-
508-
// This is the set of root paths which will become part of the source package
509-
let src_files = [
510-
"COPYRIGHT",
511-
"LICENSE-APACHE",
512-
"LICENSE-MIT",
513-
"CONTRIBUTING.md",
514-
"README.md",
515-
"RELEASES.md",
516-
"configure",
517-
"x.py",
518-
];
519-
let src_dirs = [
520-
"man",
521-
"src",
522-
];
523-
492+
fn copy_src_dirs(build: &Build, src_dirs: &[&str], dst_dir: &Path) {
524493
let filter_fn = move |path: &Path| {
525494
let spath = match path.to_str() {
526495
Some(path) => path,
@@ -549,60 +518,16 @@ pub fn rust_src(build: &Build) {
549518
};
550519

551520
// Copy the directories using our filter
552-
for item in &src_dirs {
553-
let dst = &plain_dst_src.join(item);
554-
t!(fs::create_dir(dst));
521+
for item in src_dirs {
522+
let dst = &dst_dir.join(item);
523+
t!(fs::create_dir_all(dst));
555524
cp_filtered(&build.src.join(item), dst, &filter_fn);
556525
}
557-
// Copy the files normally
558-
for item in &src_files {
559-
copy(&build.src.join(item), &plain_dst_src.join(item));
560-
}
561-
562-
// If we're building from git sources, we need to vendor a complete distribution.
563-
if build.src_is_git {
564-
// Get cargo-vendor installed, if it isn't already.
565-
let mut has_cargo_vendor = false;
566-
let mut cmd = Command::new(&build.cargo);
567-
for line in output(cmd.arg("install").arg("--list")).lines() {
568-
has_cargo_vendor |= line.starts_with("cargo-vendor ");
569-
}
570-
if !has_cargo_vendor {
571-
let mut cmd = Command::new(&build.cargo);
572-
cmd.arg("install")
573-
.arg("--force")
574-
.arg("--debug")
575-
.arg("--vers").arg(CARGO_VENDOR_VERSION)
576-
.arg("cargo-vendor")
577-
.env("RUSTC", &build.rustc);
578-
build.run(&mut cmd);
579-
}
580-
581-
// Vendor all Cargo dependencies
582-
let mut cmd = Command::new(&build.cargo);
583-
cmd.arg("vendor")
584-
.current_dir(&plain_dst_src.join("src"));
585-
build.run(&mut cmd);
586-
}
587-
588-
// Create the version file
589-
write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes());
590-
591-
// Create plain source tarball
592-
let mut tarball = rust_src_location(build);
593-
tarball.set_extension(""); // strip .gz
594-
tarball.set_extension(""); // strip .tar
595-
if let Some(dir) = tarball.parent() {
596-
t!(fs::create_dir_all(dir));
597-
}
598-
let mut cmd = rust_installer(build);
599-
cmd.arg("tarball")
600-
.arg("--input").arg(&plain_name)
601-
.arg("--output").arg(&tarball)
602-
.arg("--work-dir=.")
603-
.current_dir(tmpdir(build));
604-
build.run(&mut cmd);
526+
}
605527

528+
/// Creates the `rust-src` installer component
529+
pub fn rust_src(build: &Build) {
530+
println!("Dist src");
606531

607532
let name = pkgname(build, "rust-src");
608533
let image = tmpdir(build).join(format!("{}-image", name));
@@ -636,11 +561,7 @@ pub fn rust_src(build: &Build) {
636561
"src/rustc/libc_shim",
637562
];
638563

639-
for item in &std_src_dirs {
640-
let dst = &dst_src.join(item);
641-
t!(fs::create_dir_all(dst));
642-
cp_r(&plain_dst_src.join(item), dst);
643-
}
564+
copy_src_dirs(build, &std_src_dirs[..], &dst_src);
644565

645566
// Create source tarball in rust-installer format
646567
let mut cmd = rust_installer(build);
@@ -657,7 +578,86 @@ pub fn rust_src(build: &Build) {
657578
build.run(&mut cmd);
658579

659580
t!(fs::remove_dir_all(&image));
660-
t!(fs::remove_dir_all(&plain_dst_src));
581+
}
582+
583+
const CARGO_VENDOR_VERSION: &'static str = "0.1.4";
584+
585+
/// Creates the plain source tarball
586+
pub fn plain_source_tarball(build: &Build) {
587+
println!("Create plain source tarball");
588+
589+
// Make sure that the root folder of tarball has the correct name
590+
let plain_name = format!("{}-src", pkgname(build, "rustc"));
591+
let plain_dst_src = tmpdir(build).join(&plain_name);
592+
let _ = fs::remove_dir_all(&plain_dst_src);
593+
t!(fs::create_dir_all(&plain_dst_src));
594+
595+
// This is the set of root paths which will become part of the source package
596+
let src_files = [
597+
"COPYRIGHT",
598+
"LICENSE-APACHE",
599+
"LICENSE-MIT",
600+
"CONTRIBUTING.md",
601+
"README.md",
602+
"RELEASES.md",
603+
"configure",
604+
"x.py",
605+
];
606+
let src_dirs = [
607+
"man",
608+
"src",
609+
];
610+
611+
copy_src_dirs(build, &src_dirs[..], &plain_dst_src);
612+
613+
// Copy the files normally
614+
for item in &src_files {
615+
copy(&build.src.join(item), &plain_dst_src.join(item));
616+
}
617+
618+
// Create the version file
619+
write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes());
620+
621+
// If we're building from git sources, we need to vendor a complete distribution.
622+
if build.src_is_git {
623+
// Get cargo-vendor installed, if it isn't already.
624+
let mut has_cargo_vendor = false;
625+
let mut cmd = Command::new(&build.cargo);
626+
for line in output(cmd.arg("install").arg("--list")).lines() {
627+
has_cargo_vendor |= line.starts_with("cargo-vendor ");
628+
}
629+
if !has_cargo_vendor {
630+
let mut cmd = Command::new(&build.cargo);
631+
cmd.arg("install")
632+
.arg("--force")
633+
.arg("--debug")
634+
.arg("--vers").arg(CARGO_VENDOR_VERSION)
635+
.arg("cargo-vendor")
636+
.env("RUSTC", &build.rustc);
637+
build.run(&mut cmd);
638+
}
639+
640+
// Vendor all Cargo dependencies
641+
let mut cmd = Command::new(&build.cargo);
642+
cmd.arg("vendor")
643+
.current_dir(&plain_dst_src.join("src"));
644+
build.run(&mut cmd);
645+
}
646+
647+
// Create plain source tarball
648+
let mut tarball = rust_src_location(build);
649+
tarball.set_extension(""); // strip .gz
650+
tarball.set_extension(""); // strip .tar
651+
if let Some(dir) = tarball.parent() {
652+
t!(fs::create_dir_all(dir));
653+
}
654+
let mut cmd = rust_installer(build);
655+
cmd.arg("tarball")
656+
.arg("--input").arg(&plain_name)
657+
.arg("--output").arg(&tarball)
658+
.arg("--work-dir=.")
659+
.current_dir(tmpdir(build));
660+
build.run(&mut cmd);
661661
}
662662

663663
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)