|
| 1 | +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +use std::fs::{self, File}; |
| 12 | +use std::io::Write; |
| 13 | +use std::path::{PathBuf, Path}; |
| 14 | +use std::process::Command; |
| 15 | + |
| 16 | +use build::{Build, Compiler}; |
| 17 | +use build::util::{cp_r, libdir, is_dylib}; |
| 18 | + |
| 19 | +fn package_vers(build: &Build) -> &str { |
| 20 | + match &build.config.channel[..] { |
| 21 | + "stable" => &build.release, |
| 22 | + "beta" => "beta", |
| 23 | + "nightly" => "nightly", |
| 24 | + _ => &build.release, |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +fn distdir(build: &Build) -> PathBuf { |
| 29 | + build.out.join("dist") |
| 30 | +} |
| 31 | + |
| 32 | +fn tmpdir(build: &Build) -> PathBuf { |
| 33 | + build.out.join("tmp/dist") |
| 34 | +} |
| 35 | + |
| 36 | +pub fn docs(build: &Build, stage: u32, host: &str) { |
| 37 | + println!("Dist docs stage{} ({})", stage, host); |
| 38 | + let name = format!("rust-docs-{}", package_vers(build)); |
| 39 | + let image = tmpdir(build).join(format!("{}-{}-image", name, name)); |
| 40 | + let _ = fs::remove_dir_all(&image); |
| 41 | + |
| 42 | + let dst = image.join("share/doc/rust/html"); |
| 43 | + t!(fs::create_dir_all(&dst)); |
| 44 | + let src = build.out.join(host).join("doc"); |
| 45 | + cp_r(&src, &dst); |
| 46 | + |
| 47 | + let mut cmd = Command::new("sh"); |
| 48 | + cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh"))) |
| 49 | + .arg("--product-name=Rust-Documentation") |
| 50 | + .arg("--rel-manifest-dir=rustlib") |
| 51 | + .arg("--success-message=Rust-documentation-is-installed.") |
| 52 | + .arg(format!("--image-dir={}", sanitize_sh(&image))) |
| 53 | + .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) |
| 54 | + .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) |
| 55 | + .arg(format!("--package-name={}", name)) |
| 56 | + .arg("--component-name=rust-docs") |
| 57 | + .arg("--legacy-manifest-dirs=rustlib,cargo") |
| 58 | + .arg("--bulk-dirs=share/doc/rust/html"); |
| 59 | + build.run(&mut cmd); |
| 60 | + t!(fs::remove_dir_all(&image)); |
| 61 | + |
| 62 | + // As part of this step, *also* copy the docs directory to a directory which |
| 63 | + // buildbot typically uploads. |
| 64 | + let dst = distdir(build).join("doc").join(&build.package_vers); |
| 65 | + t!(fs::create_dir_all(&dst)); |
| 66 | + cp_r(&src, &dst); |
| 67 | +} |
| 68 | + |
| 69 | +pub fn mingw(build: &Build, host: &str) { |
| 70 | + println!("Dist mingw ({})", host); |
| 71 | + let name = format!("rust-mingw-{}", package_vers(build)); |
| 72 | + let image = tmpdir(build).join(format!("{}-{}-image", name, host)); |
| 73 | + let _ = fs::remove_dir_all(&image); |
| 74 | + |
| 75 | + // The first argument to the script is a "temporary directory" which is just |
| 76 | + // thrown away (this contains the runtime DLLs included in the rustc package |
| 77 | + // above) and the second argument is where to place all the MinGW components |
| 78 | + // (which is what we want). |
| 79 | + // |
| 80 | + // FIXME: this script should be rewritten into Rust |
| 81 | + let mut cmd = Command::new("python"); |
| 82 | + cmd.arg(build.src.join("src/etc/make-win-dist.py")) |
| 83 | + .arg(tmpdir(build)) |
| 84 | + .arg(&image) |
| 85 | + .arg(host); |
| 86 | + build.run(&mut cmd); |
| 87 | + |
| 88 | + let mut cmd = Command::new("sh"); |
| 89 | + cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh"))) |
| 90 | + .arg("--product-name=Rust-MinGW") |
| 91 | + .arg("--rel-manifest-dir=rustlib") |
| 92 | + .arg("--success-message=Rust-MinGW-is-installed.") |
| 93 | + .arg(format!("--image-dir={}", sanitize_sh(&image))) |
| 94 | + .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) |
| 95 | + .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) |
| 96 | + .arg(format!("--package-name={}-{}", name, host)) |
| 97 | + .arg("--component-name=rust-mingw") |
| 98 | + .arg("--legacy-manifest-dirs=rustlib,cargo"); |
| 99 | + build.run(&mut cmd); |
| 100 | + t!(fs::remove_dir_all(&image)); |
| 101 | +} |
| 102 | + |
| 103 | +pub fn rustc(build: &Build, stage: u32, host: &str) { |
| 104 | + println!("Dist rustc stage{} ({})", stage, host); |
| 105 | + let name = format!("rustc-{}", package_vers(build)); |
| 106 | + let image = tmpdir(build).join(format!("{}-{}-image", name, host)); |
| 107 | + let _ = fs::remove_dir_all(&image); |
| 108 | + let overlay = tmpdir(build).join(format!("{}-{}-overlay", name, host)); |
| 109 | + let _ = fs::remove_dir_all(&overlay); |
| 110 | + |
| 111 | + // Prepare the rustc "image", what will actually end up getting installed |
| 112 | + prepare_image(build, stage, host, &image); |
| 113 | + |
| 114 | + // Prepare the overlay which is part of the tarball but won't actually be |
| 115 | + // installed |
| 116 | + t!(fs::create_dir_all(&overlay)); |
| 117 | + let cp = |file: &str| { |
| 118 | + install(&build.src.join(file), &overlay, 0o644); |
| 119 | + }; |
| 120 | + cp("COPYRIGHT"); |
| 121 | + cp("LICENSE-APACHE"); |
| 122 | + cp("LICENSE-MIT"); |
| 123 | + cp("README.md"); |
| 124 | + // tiny morsel of metadata is used by rust-packaging |
| 125 | + let version = &build.version; |
| 126 | + t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes())); |
| 127 | + |
| 128 | + // On MinGW we've got a few runtime DLL dependencies that we need to |
| 129 | + // include. The first argument to this script is where to put these DLLs |
| 130 | + // (the image we're creating), and the second argument is a junk directory |
| 131 | + // to ignore all other MinGW stuff the script creates. |
| 132 | + // |
| 133 | + // On 32-bit MinGW we're always including a DLL which needs some extra |
| 134 | + // licenses to distribute. On 64-bit MinGW we don't actually distribute |
| 135 | + // anything requiring us to distribute a license, but it's likely the |
| 136 | + // install will *also* include the rust-mingw package, which also needs |
| 137 | + // licenses, so to be safe we just include it here in all MinGW packages. |
| 138 | + // |
| 139 | + // FIXME: this script should be rewritten into Rust |
| 140 | + if host.contains("pc-windows-gnu") { |
| 141 | + let mut cmd = Command::new("python"); |
| 142 | + cmd.arg(build.src.join("src/etc/make-win-dist.py")) |
| 143 | + .arg(&image) |
| 144 | + .arg(tmpdir(build)) |
| 145 | + .arg(host); |
| 146 | + build.run(&mut cmd); |
| 147 | + |
| 148 | + let dst = image.join("share/doc"); |
| 149 | + t!(fs::create_dir_all(&dst)); |
| 150 | + cp_r(&build.src.join("src/etc/third-party"), &dst); |
| 151 | + } |
| 152 | + |
| 153 | + // Finally, wrap everything up in a nice tarball! |
| 154 | + let mut cmd = Command::new("sh"); |
| 155 | + cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh"))) |
| 156 | + .arg("--product-name=Rust") |
| 157 | + .arg("--rel-manifest-dir=rustlib") |
| 158 | + .arg("--success-message=Rust-is-ready-to-roll.") |
| 159 | + .arg(format!("--image-dir={}", sanitize_sh(&image))) |
| 160 | + .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) |
| 161 | + .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) |
| 162 | + .arg(format!("--non-installed-overlay={}", sanitize_sh(&overlay))) |
| 163 | + .arg(format!("--package-name={}-{}", name, host)) |
| 164 | + .arg("--component-name=rustc") |
| 165 | + .arg("--legacy-manifest-dirs=rustlib,cargo"); |
| 166 | + build.run(&mut cmd); |
| 167 | + t!(fs::remove_dir_all(&image)); |
| 168 | + t!(fs::remove_dir_all(&overlay)); |
| 169 | + |
| 170 | + fn prepare_image(build: &Build, stage: u32, host: &str, image: &Path) { |
| 171 | + let src = build.sysroot(&Compiler::new(stage, host)); |
| 172 | + let libdir = libdir(host); |
| 173 | + |
| 174 | + // Copy rustc/rustdoc binaries |
| 175 | + t!(fs::create_dir_all(image.join("bin"))); |
| 176 | + cp_r(&src.join("bin"), &image.join("bin")); |
| 177 | + |
| 178 | + // Copy runtime DLLs needed by the compiler |
| 179 | + if libdir != "bin" { |
| 180 | + t!(fs::create_dir_all(image.join(libdir))); |
| 181 | + for entry in t!(src.join(libdir).read_dir()).map(|e| t!(e)) { |
| 182 | + let name = entry.file_name(); |
| 183 | + if let Some(s) = name.to_str() { |
| 184 | + if is_dylib(s) { |
| 185 | + install(&entry.path(), &image.join(libdir), 0o644); |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + } |
| 190 | + |
| 191 | + // Man pages |
| 192 | + t!(fs::create_dir_all(image.join("share/man/man1"))); |
| 193 | + cp_r(&build.src.join("man"), &image.join("share/man/man1")); |
| 194 | + |
| 195 | + // Debugger scripts |
| 196 | + let cp_debugger_script = |file: &str| { |
| 197 | + let dst = image.join("lib/rustlib/etc"); |
| 198 | + t!(fs::create_dir_all(&dst)); |
| 199 | + install(&build.src.join("src/etc/").join(file), &dst, 0o644); |
| 200 | + }; |
| 201 | + if host.contains("windows") { |
| 202 | + // no debugger scripts |
| 203 | + } else if host.contains("darwin") { |
| 204 | + // lldb debugger scripts |
| 205 | + install(&build.src.join("src/etc/rust-lldb"), &image.join("bin"), |
| 206 | + 0o755); |
| 207 | + |
| 208 | + cp_debugger_script("lldb_rust_formatters.py"); |
| 209 | + cp_debugger_script("debugger_pretty_printers_common.py"); |
| 210 | + } else { |
| 211 | + // gdb debugger scripts |
| 212 | + install(&build.src.join("src/etc/rust-gdb"), &image.join("bin"), |
| 213 | + 0o755); |
| 214 | + |
| 215 | + cp_debugger_script("gdb_load_rust_pretty_printers.py"); |
| 216 | + cp_debugger_script("gdb_rust_pretty_printing.py"); |
| 217 | + cp_debugger_script("debugger_pretty_printers_common.py"); |
| 218 | + } |
| 219 | + |
| 220 | + // Misc license info |
| 221 | + let cp = |file: &str| { |
| 222 | + install(&build.src.join(file), &image.join("share/doc/rust"), 0o644); |
| 223 | + }; |
| 224 | + t!(fs::create_dir_all(&image.join("share/doc/rust"))); |
| 225 | + cp("COPYRIGHT"); |
| 226 | + cp("LICENSE-APACHE"); |
| 227 | + cp("LICENSE-MIT"); |
| 228 | + cp("README.md"); |
| 229 | + } |
| 230 | +} |
| 231 | + |
| 232 | +pub fn std(build: &Build, compiler: &Compiler, target: &str) { |
| 233 | + println!("Dist std stage{} ({} -> {})", compiler.stage, compiler.host, |
| 234 | + target); |
| 235 | + let name = format!("rust-std-{}", package_vers(build)); |
| 236 | + let image = tmpdir(build).join(format!("{}-{}-image", name, target)); |
| 237 | + let _ = fs::remove_dir_all(&image); |
| 238 | + |
| 239 | + let dst = image.join("lib/rustlib").join(target); |
| 240 | + t!(fs::create_dir_all(&dst)); |
| 241 | + let src = build.sysroot(compiler).join("lib/rustlib"); |
| 242 | + cp_r(&src.join(target), &dst); |
| 243 | + |
| 244 | + let mut cmd = Command::new("sh"); |
| 245 | + cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh"))) |
| 246 | + .arg("--product-name=Rust") |
| 247 | + .arg("--rel-manifest-dir=rustlib") |
| 248 | + .arg("--success-message=std-is-standing-at-the-ready.") |
| 249 | + .arg(format!("--image-dir={}", sanitize_sh(&image))) |
| 250 | + .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) |
| 251 | + .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) |
| 252 | + .arg(format!("--package-name={}-{}", name, target)) |
| 253 | + .arg(format!("--component-name=rust-std-{}", target)) |
| 254 | + .arg("--legacy-manifest-dirs=rustlib,cargo"); |
| 255 | + build.run(&mut cmd); |
| 256 | + t!(fs::remove_dir_all(&image)); |
| 257 | +} |
| 258 | + |
| 259 | +fn install(src: &Path, dstdir: &Path, perms: u32) { |
| 260 | + let dst = dstdir.join(src.file_name().unwrap()); |
| 261 | + t!(fs::copy(src, &dst)); |
| 262 | + chmod(&dst, perms); |
| 263 | +} |
| 264 | + |
| 265 | +#[cfg(unix)] |
| 266 | +fn chmod(path: &Path, perms: u32) { |
| 267 | + use std::os::unix::fs::*; |
| 268 | + t!(fs::set_permissions(path, fs::Permissions::from_mode(perms))); |
| 269 | +} |
| 270 | +#[cfg(windows)] |
| 271 | +fn chmod(_path: &Path, _perms: u32) {} |
| 272 | + |
| 273 | +// We have to run a few shell scripts, which choke quite a bit on both `\` |
| 274 | +// characters and on `C:\` paths, so normalize both of them away. |
| 275 | +fn sanitize_sh(path: &Path) -> String { |
| 276 | + let path = path.to_str().unwrap().replace("\\", "/"); |
| 277 | + return change_drive(&path).unwrap_or(path); |
| 278 | + |
| 279 | + fn change_drive(s: &str) -> Option<String> { |
| 280 | + let mut ch = s.chars(); |
| 281 | + let drive = ch.next().unwrap_or('C'); |
| 282 | + if ch.next() != Some(':') { |
| 283 | + return None |
| 284 | + } |
| 285 | + if ch.next() != Some('/') { |
| 286 | + return None |
| 287 | + } |
| 288 | + Some(format!("/{}/{}", drive, &s[drive.len_utf8() + 2..])) |
| 289 | + } |
| 290 | +} |
0 commit comments