]>
Commit | Line | Data |
---|---|---|
c30ab7b3 SL |
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 | //! Implementation of the install aspects of the compiler. | |
12 | //! | |
13 | //! This module is responsible for installing the standard library, | |
14 | //! compiler, and documentation. | |
15 | ||
16 | use std::fs; | |
17 | use std::borrow::Cow; | |
18 | use std::path::Path; | |
19 | use std::process::Command; | |
20 | ||
21 | use Build; | |
22 | use dist::{package_vers, sanitize_sh, tmpdir}; | |
23 | ||
24 | /// Installs everything. | |
25 | pub fn install(build: &Build, stage: u32, host: &str) { | |
26 | let prefix = build.config.prefix.as_ref().clone().map(|x| Path::new(x)) | |
27 | .unwrap_or(Path::new("/usr/local")); | |
28 | let docdir = build.config.docdir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x))) | |
29 | .unwrap_or(Cow::Owned(prefix.join("share/doc/rust"))); | |
30 | let libdir = build.config.libdir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x))) | |
31 | .unwrap_or(Cow::Owned(prefix.join("lib"))); | |
32 | let mandir = build.config.mandir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x))) | |
33 | .unwrap_or(Cow::Owned(prefix.join("share/man"))); | |
34 | let empty_dir = build.out.join("tmp/empty_dir"); | |
35 | t!(fs::create_dir_all(&empty_dir)); | |
36 | if build.config.docs { | |
37 | install_sh(&build, "docs", "rust-docs", stage, host, prefix, | |
38 | &docdir, &libdir, &mandir, &empty_dir); | |
39 | } | |
40 | install_sh(&build, "std", "rust-std", stage, host, prefix, | |
41 | &docdir, &libdir, &mandir, &empty_dir); | |
42 | install_sh(&build, "rustc", "rustc", stage, host, prefix, | |
43 | &docdir, &libdir, &mandir, &empty_dir); | |
44 | t!(fs::remove_dir_all(&empty_dir)); | |
45 | } | |
46 | ||
47 | fn install_sh(build: &Build, package: &str, name: &str, stage: u32, host: &str, | |
48 | prefix: &Path, docdir: &Path, libdir: &Path, mandir: &Path, empty_dir: &Path) { | |
49 | println!("Install {} stage{} ({})", package, stage, host); | |
50 | let package_name = format!("{}-{}-{}", name, package_vers(build), host); | |
51 | ||
52 | let mut cmd = Command::new("sh"); | |
53 | cmd.current_dir(empty_dir) | |
54 | .arg(sanitize_sh(&tmpdir(build).join(&package_name).join("install.sh"))) | |
55 | .arg(format!("--prefix={}", sanitize_sh(prefix))) | |
56 | .arg(format!("--docdir={}", sanitize_sh(docdir))) | |
57 | .arg(format!("--libdir={}", sanitize_sh(libdir))) | |
58 | .arg(format!("--mandir={}", sanitize_sh(mandir))) | |
59 | .arg("--disable-ldconfig"); | |
60 | build.run(&mut cmd); | |
61 | } |