Skip to content

Commit

Permalink
Rollup merge of #42109 - Keruspe:master, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
frewsxcv authored May 23, 2017
2 parents d1f6df3 + 150d644 commit 61e9ff9
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 140 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ Read ["Installing Rust"] from [The Book].
3. Build and install:

```sh
$ ./x.py build && sudo ./x.py dist --install
$ ./x.py build && sudo ./x.py install
```

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

When complete, `sudo ./x.py dist --install` will place several programs into
When complete, `sudo ./x.py install` will place several programs into
`/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
API-documentation tool. This install does not include [Cargo],
Rust's package manager, which you may also want to build.
Expand Down Expand Up @@ -96,7 +96,7 @@ build.
4. Navigate to Rust's source code (or clone it), then build it:
```sh
$ ./x.py build && ./x.py dist --install
$ ./x.py build && ./x.py install
```
#### MSVC
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,9 @@
# Note that this address should not contain a trailing slash as file names will
# be appended to it.
#upload-addr = "https://example.com/folder"

# Whether to build a plain source tarball to upload
# We disable that on Windows not to override the one already uploaded on S3
# as the one built on Windows will contain backslashes in paths causing problems
# on linux
#src-tarball = true
182 changes: 91 additions & 91 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ use {Build, Compiler, Mode};
use channel;
use util::{cp_r, libdir, is_dylib, cp_filtered, copy, exe};

fn pkgname(build: &Build, component: &str) -> String {
pub fn pkgname(build: &Build, component: &str) -> String {
if component == "cargo" {
format!("{}-{}", component, build.cargo_package_vers())
} else if component == "rls" {
format!("{}-{}", component, build.package_vers(&build.release_num("rls")))
format!("{}-{}", component, build.rls_package_vers())
} else {
assert!(component.starts_with("rust"));
format!("{}-{}", component, build.rust_package_vers())
Expand Down Expand Up @@ -369,38 +369,7 @@ pub fn analysis(build: &Build, compiler: &Compiler, target: &str) {
t!(fs::remove_dir_all(&image));
}

const CARGO_VENDOR_VERSION: &'static str = "0.1.4";

/// Creates the `rust-src` installer component and the plain source tarball
pub fn rust_src(build: &Build) {
if !build.config.rust_dist_src {
return
}

println!("Dist src");

// Make sure that the root folder of tarball has the correct name
let plain_name = format!("rustc-{}-src", build.rust_package_vers());
let plain_dst_src = tmpdir(build).join(&plain_name);
let _ = fs::remove_dir_all(&plain_dst_src);
t!(fs::create_dir_all(&plain_dst_src));

// This is the set of root paths which will become part of the source package
let src_files = [
"COPYRIGHT",
"LICENSE-APACHE",
"LICENSE-MIT",
"CONTRIBUTING.md",
"README.md",
"RELEASES.md",
"configure",
"x.py",
];
let src_dirs = [
"man",
"src",
];

fn copy_src_dirs(build: &Build, src_dirs: &[&str], dst_dir: &Path) {
let filter_fn = move |path: &Path| {
let spath = match path.to_str() {
Some(path) => path,
Expand Down Expand Up @@ -429,60 +398,16 @@ pub fn rust_src(build: &Build) {
};

// Copy the directories using our filter
for item in &src_dirs {
let dst = &plain_dst_src.join(item);
t!(fs::create_dir(dst));
for item in src_dirs {
let dst = &dst_dir.join(item);
t!(fs::create_dir_all(dst));
cp_filtered(&build.src.join(item), dst, &filter_fn);
}
// Copy the files normally
for item in &src_files {
copy(&build.src.join(item), &plain_dst_src.join(item));
}

// If we're building from git sources, we need to vendor a complete distribution.
if build.src_is_git {
// Get cargo-vendor installed, if it isn't already.
let mut has_cargo_vendor = false;
let mut cmd = Command::new(&build.cargo);
for line in output(cmd.arg("install").arg("--list")).lines() {
has_cargo_vendor |= line.starts_with("cargo-vendor ");
}
if !has_cargo_vendor {
let mut cmd = Command::new(&build.cargo);
cmd.arg("install")
.arg("--force")
.arg("--debug")
.arg("--vers").arg(CARGO_VENDOR_VERSION)
.arg("cargo-vendor")
.env("RUSTC", &build.rustc);
build.run(&mut cmd);
}

// Vendor all Cargo dependencies
let mut cmd = Command::new(&build.cargo);
cmd.arg("vendor")
.current_dir(&plain_dst_src.join("src"));
build.run(&mut cmd);
}

// Create the version file
write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes());

// Create plain source tarball
let mut tarball = rust_src_location(build);
tarball.set_extension(""); // strip .gz
tarball.set_extension(""); // strip .tar
if let Some(dir) = tarball.parent() {
t!(fs::create_dir_all(dir));
}
let mut cmd = rust_installer(build);
cmd.arg("tarball")
.arg("--input").arg(&plain_name)
.arg("--output").arg(&tarball)
.arg("--work-dir=.")
.current_dir(tmpdir(build));
build.run(&mut cmd);
}

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

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

for item in &std_src_dirs {
let dst = &dst_src.join(item);
t!(fs::create_dir_all(dst));
cp_r(&plain_dst_src.join(item), dst);
}
copy_src_dirs(build, &std_src_dirs[..], &dst_src);

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

t!(fs::remove_dir_all(&image));
t!(fs::remove_dir_all(&plain_dst_src));
}

const CARGO_VENDOR_VERSION: &'static str = "0.1.4";

/// Creates the plain source tarball
pub fn plain_source_tarball(build: &Build) {
println!("Create plain source tarball");

// Make sure that the root folder of tarball has the correct name
let plain_name = format!("{}-src", pkgname(build, "rustc"));
let plain_dst_src = tmpdir(build).join(&plain_name);
let _ = fs::remove_dir_all(&plain_dst_src);
t!(fs::create_dir_all(&plain_dst_src));

// This is the set of root paths which will become part of the source package
let src_files = [
"COPYRIGHT",
"LICENSE-APACHE",
"LICENSE-MIT",
"CONTRIBUTING.md",
"README.md",
"RELEASES.md",
"configure",
"x.py",
];
let src_dirs = [
"man",
"src",
];

copy_src_dirs(build, &src_dirs[..], &plain_dst_src);

// Copy the files normally
for item in &src_files {
copy(&build.src.join(item), &plain_dst_src.join(item));
}

// Create the version file
write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes());

// If we're building from git sources, we need to vendor a complete distribution.
if build.src_is_git {
// Get cargo-vendor installed, if it isn't already.
let mut has_cargo_vendor = false;
let mut cmd = Command::new(&build.cargo);
for line in output(cmd.arg("install").arg("--list")).lines() {
has_cargo_vendor |= line.starts_with("cargo-vendor ");
}
if !has_cargo_vendor {
let mut cmd = Command::new(&build.cargo);
cmd.arg("install")
.arg("--force")
.arg("--debug")
.arg("--vers").arg(CARGO_VENDOR_VERSION)
.arg("cargo-vendor")
.env("RUSTC", &build.rustc);
build.run(&mut cmd);
}

// Vendor all Cargo dependencies
let mut cmd = Command::new(&build.cargo);
cmd.arg("vendor")
.current_dir(&plain_dst_src.join("src"));
build.run(&mut cmd);
}

// Create plain source tarball
let mut tarball = rust_src_location(build);
tarball.set_extension(""); // strip .gz
tarball.set_extension(""); // strip .tar
if let Some(dir) = tarball.parent() {
t!(fs::create_dir_all(dir));
}
let mut cmd = rust_installer(build);
cmd.arg("tarball")
.arg("--input").arg(&plain_name)
.arg("--output").arg(&tarball)
.arg("--work-dir=.")
.current_dir(tmpdir(build));
build.run(&mut cmd);
}

fn install(src: &Path, dstdir: &Path, perms: u32) {
Expand Down
17 changes: 12 additions & 5 deletions src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ pub enum Subcommand {
Clean,
Dist {
paths: Vec<PathBuf>,
install: bool,
},
Install {
paths: Vec<PathBuf>,
},
}

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

Expand Down Expand Up @@ -125,7 +128,8 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
|| (s == "bench")
|| (s == "doc")
|| (s == "clean")
|| (s == "dist"));
|| (s == "dist")
|| (s == "install"));
let subcommand = match possible_subcommands.first() {
Some(s) => s,
None => {
Expand All @@ -139,7 +143,6 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
match subcommand.as_str() {
"test" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); },
"bench" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); },
"dist" => { opts.optflag("", "install", "run installer as well"); },
_ => { },
};

Expand Down Expand Up @@ -281,7 +284,11 @@ Arguments:
"dist" => {
Subcommand::Dist {
paths: paths,
install: matches.opt_present("install"),
}
}
"install" => {
Subcommand::Install {
paths: paths,
}
}
_ => {
Expand Down
Loading

0 comments on commit 61e9ff9

Please sign in to comment.