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.
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.
11 //! Implementation of the install aspects of the compiler.
13 //! This module is responsible for installing the standard library,
14 //! compiler, and documentation.
18 use std::path::{Path, PathBuf, Component};
19 use std::process::Command;
22 use dist::{sanitize_sh, tmpdir};
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);
35 let docdir = prefix.join(docdir);
36 let libdir = prefix.join(libdir);
37 let mandir = prefix.join(mandir);
39 let destdir = env::var_os("DESTDIR").map(PathBuf::from);
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);
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", stage, host, &prefix,
50 &docdir, &libdir, &mandir, &empty_dir);
53 for target in build.config.target.iter() {
54 install_sh(&build, "std", "rust-std", stage, target, &prefix,
55 &docdir, &libdir, &mandir, &empty_dir);
58 install_sh(&build, "rustc", "rustc", stage, host, &prefix,
59 &docdir, &libdir, &mandir, &empty_dir);
60 t!(fs::remove_dir_all(&empty_dir));
63 fn install_sh(build: &Build, package: &str, name: &str, stage: u32, host: &str,
64 prefix: &Path, docdir: &Path, libdir: &Path, mandir: &Path, empty_dir: &Path) {
65 println!("Install {} stage{} ({})", package, stage, host);
66 let package_name = format!("{}-{}-{}", name, build.rust_package_vers(), host);
68 let mut cmd = Command::new("sh");
69 cmd.current_dir(empty_dir)
70 .arg(sanitize_sh(&tmpdir(build).join(&package_name).join("install.sh")))
71 .arg(format!("--prefix={}", sanitize_sh(prefix)))
72 .arg(format!("--docdir={}", sanitize_sh(docdir)))
73 .arg(format!("--libdir={}", sanitize_sh(libdir)))
74 .arg(format!("--mandir={}", sanitize_sh(mandir)))
75 .arg("--disable-ldconfig");
79 fn add_destdir(path: &Path, destdir: &Option<PathBuf>) -> PathBuf {
80 let mut ret = match *destdir {
81 Some(ref dest) => dest.clone(),
82 None => return path.to_path_buf(),
84 for part in path.components() {
86 Component::Normal(s) => ret.push(s),