]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/install.rs
rustbuild: install rustc after cargo and rls
[rust.git] / src / bootstrap / install.rs
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::env;
17 use std::fs;
18 use std::path::{Path, PathBuf, Component};
19 use std::process::Command;
20
21 use Build;
22 use dist::{sanitize_sh, tmpdir};
23
24 /// Installs everything.
25 pub fn install(build: &Build, stage: u32, host: &str) {
26     let prefix_default = PathBuf::from("/usr/local");
27     let docdir_default = PathBuf::from("share/doc/rust");
28     let mandir_default = PathBuf::from("share/man");
29     let libdir_default = PathBuf::from("lib");
30     let prefix = build.config.prefix.as_ref().unwrap_or(&prefix_default);
31     let docdir = build.config.docdir.as_ref().unwrap_or(&docdir_default);
32     let libdir = build.config.libdir.as_ref().unwrap_or(&libdir_default);
33     let mandir = build.config.mandir.as_ref().unwrap_or(&mandir_default);
34
35     let docdir = prefix.join(docdir);
36     let libdir = prefix.join(libdir);
37     let mandir = prefix.join(mandir);
38
39     let destdir = env::var_os("DESTDIR").map(PathBuf::from);
40
41     let prefix = add_destdir(&prefix, &destdir);
42     let docdir = add_destdir(&docdir, &destdir);
43     let libdir = add_destdir(&libdir, &destdir);
44     let mandir = add_destdir(&mandir, &destdir);
45
46     let empty_dir = build.out.join("tmp/empty_dir");
47     t!(fs::create_dir_all(&empty_dir));
48     if build.config.docs {
49         install_sh(&build, "docs", "rust-docs", &build.rust_package_vers(),
50                    stage, host, &prefix, &docdir, &libdir, &mandir, &empty_dir);
51     }
52
53     for target in build.config.target.iter() {
54         install_sh(&build, "std", "rust-std", &build.rust_package_vers(),
55                    stage, target, &prefix, &docdir, &libdir, &mandir, &empty_dir);
56     }
57
58     if build.config.extended {
59         install_sh(&build, "cargo", "cargo", &build.cargo_package_vers(),
60                    stage, host, &prefix, &docdir, &libdir, &mandir, &empty_dir);
61         install_sh(&build, "rls", "rls", &build.rls_package_vers(),
62                    stage, host, &prefix, &docdir, &libdir, &mandir, &empty_dir);
63     }
64
65     install_sh(&build, "rustc", "rustc", &build.rust_package_vers(),
66                stage, host, &prefix, &docdir, &libdir, &mandir, &empty_dir);
67
68     t!(fs::remove_dir_all(&empty_dir));
69 }
70
71 fn install_sh(build: &Build, package: &str, name: &str, version: &str, stage: u32, host: &str,
72               prefix: &Path, docdir: &Path, libdir: &Path, mandir: &Path, empty_dir: &Path) {
73     println!("Install {} stage{} ({})", package, stage, host);
74     let package_name = format!("{}-{}-{}", name, version, host);
75
76     let mut cmd = Command::new("sh");
77     cmd.current_dir(empty_dir)
78        .arg(sanitize_sh(&tmpdir(build).join(&package_name).join("install.sh")))
79        .arg(format!("--prefix={}", sanitize_sh(prefix)))
80        .arg(format!("--docdir={}", sanitize_sh(docdir)))
81        .arg(format!("--libdir={}", sanitize_sh(libdir)))
82        .arg(format!("--mandir={}", sanitize_sh(mandir)))
83        .arg("--disable-ldconfig");
84     build.run(&mut cmd);
85 }
86
87 fn add_destdir(path: &Path, destdir: &Option<PathBuf>) -> PathBuf {
88     let mut ret = match *destdir {
89         Some(ref dest) => dest.clone(),
90         None => return path.to_path_buf(),
91     };
92     for part in path.components() {
93         match part {
94             Component::Normal(s) => ret.push(s),
95             _ => {}
96         }
97     }
98     return ret
99 }