2016-08-13 08:38:17 +02:00
|
|
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! Implementation of the install aspects of the compiler.
|
|
|
|
//!
|
|
|
|
//! This module is responsible for installing the standard library,
|
|
|
|
//! compiler, and documentation.
|
|
|
|
|
2016-12-28 18:18:54 +01:00
|
|
|
use std::env;
|
2016-10-06 06:19:01 +02:00
|
|
|
use std::fs;
|
2016-12-28 18:18:54 +01:00
|
|
|
use std::path::{Path, PathBuf, Component};
|
2016-10-06 06:19:01 +02:00
|
|
|
use std::process::Command;
|
|
|
|
|
2016-08-13 08:38:17 +02:00
|
|
|
use Build;
|
2017-02-16 00:57:06 +01:00
|
|
|
use dist::{sanitize_sh, tmpdir};
|
2016-08-13 08:38:17 +02:00
|
|
|
|
|
|
|
/// Installs everything.
|
2016-10-06 06:19:01 +02:00
|
|
|
pub fn install(build: &Build, stage: u32, host: &str) {
|
2016-12-28 18:18:54 +01:00
|
|
|
let prefix_default = PathBuf::from("/usr/local");
|
2017-04-28 11:08:47 +02:00
|
|
|
let sysconfdir_default = PathBuf::from("/etc");
|
2016-12-28 18:18:54 +01:00
|
|
|
let docdir_default = PathBuf::from("share/doc/rust");
|
2017-04-28 10:58:46 +02:00
|
|
|
let bindir_default = PathBuf::from("bin");
|
2016-12-28 18:18:54 +01:00
|
|
|
let libdir_default = PathBuf::from("lib");
|
2017-04-28 10:58:46 +02:00
|
|
|
let mandir_default = PathBuf::from("share/man");
|
2016-12-28 18:18:54 +01:00
|
|
|
let prefix = build.config.prefix.as_ref().unwrap_or(&prefix_default);
|
2017-04-28 11:08:47 +02:00
|
|
|
let sysconfdir = build.config.sysconfdir.as_ref().unwrap_or(&sysconfdir_default);
|
2016-12-28 18:18:54 +01:00
|
|
|
let docdir = build.config.docdir.as_ref().unwrap_or(&docdir_default);
|
2017-04-28 10:58:46 +02:00
|
|
|
let bindir = build.config.bindir.as_ref().unwrap_or(&bindir_default);
|
2016-12-28 18:18:54 +01:00
|
|
|
let libdir = build.config.libdir.as_ref().unwrap_or(&libdir_default);
|
|
|
|
let mandir = build.config.mandir.as_ref().unwrap_or(&mandir_default);
|
|
|
|
|
2017-04-28 11:08:47 +02:00
|
|
|
let sysconfdir = prefix.join(sysconfdir);
|
2016-12-28 18:18:54 +01:00
|
|
|
let docdir = prefix.join(docdir);
|
2017-04-28 10:58:46 +02:00
|
|
|
let bindir = prefix.join(bindir);
|
2016-12-28 18:18:54 +01:00
|
|
|
let libdir = prefix.join(libdir);
|
|
|
|
let mandir = prefix.join(mandir);
|
|
|
|
|
|
|
|
let destdir = env::var_os("DESTDIR").map(PathBuf::from);
|
|
|
|
|
|
|
|
let prefix = add_destdir(&prefix, &destdir);
|
2017-04-28 11:08:47 +02:00
|
|
|
let sysconfdir = add_destdir(&sysconfdir, &destdir);
|
2016-12-28 18:18:54 +01:00
|
|
|
let docdir = add_destdir(&docdir, &destdir);
|
2017-04-28 10:58:46 +02:00
|
|
|
let bindir = add_destdir(&bindir, &destdir);
|
2016-12-28 18:18:54 +01:00
|
|
|
let libdir = add_destdir(&libdir, &destdir);
|
|
|
|
let mandir = add_destdir(&mandir, &destdir);
|
|
|
|
|
2016-10-06 06:19:01 +02:00
|
|
|
let empty_dir = build.out.join("tmp/empty_dir");
|
|
|
|
t!(fs::create_dir_all(&empty_dir));
|
|
|
|
if build.config.docs {
|
2017-04-27 11:52:48 +02:00
|
|
|
install_sh(&build, "docs", "rust-docs", &build.rust_package_vers(),
|
2017-05-17 12:15:15 +02:00
|
|
|
stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir,
|
2017-04-28 11:08:47 +02:00
|
|
|
&mandir, &empty_dir);
|
2016-10-06 06:19:01 +02:00
|
|
|
}
|
2017-03-13 18:44:54 +01:00
|
|
|
|
|
|
|
for target in build.config.target.iter() {
|
2017-04-27 11:53:18 +02:00
|
|
|
install_sh(&build, "std", "rust-std", &build.rust_package_vers(),
|
2017-05-17 12:15:15 +02:00
|
|
|
stage, Some(target), &prefix, &sysconfdir, &docdir, &bindir, &libdir,
|
2017-04-28 11:08:47 +02:00
|
|
|
&mandir, &empty_dir);
|
2017-04-27 11:53:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if build.config.extended {
|
|
|
|
install_sh(&build, "cargo", "cargo", &build.cargo_package_vers(),
|
2017-05-17 12:15:15 +02:00
|
|
|
stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir,
|
2017-04-28 11:08:47 +02:00
|
|
|
&mandir, &empty_dir);
|
2017-04-27 11:53:18 +02:00
|
|
|
install_sh(&build, "rls", "rls", &build.rls_package_vers(),
|
2017-05-17 12:15:15 +02:00
|
|
|
stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir,
|
|
|
|
&mandir, &empty_dir);
|
|
|
|
install_sh(&build, "analysis", "rust-analysis", &build.rust_package_vers(),
|
|
|
|
stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir,
|
|
|
|
&mandir, &empty_dir);
|
|
|
|
install_sh(&build, "src", "rust-src", &build.rust_package_vers(),
|
|
|
|
stage, None, &prefix, &sysconfdir, &docdir, &bindir, &libdir,
|
2017-04-28 11:08:47 +02:00
|
|
|
&mandir, &empty_dir);
|
2017-03-13 18:44:54 +01:00
|
|
|
}
|
|
|
|
|
2017-04-27 15:05:29 +02:00
|
|
|
install_sh(&build, "rustc", "rustc", &build.rust_package_vers(),
|
2017-05-17 12:15:15 +02:00
|
|
|
stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir,
|
2017-04-28 11:08:47 +02:00
|
|
|
&mandir, &empty_dir);
|
2017-04-27 15:05:29 +02:00
|
|
|
|
2016-10-06 06:19:01 +02:00
|
|
|
t!(fs::remove_dir_all(&empty_dir));
|
|
|
|
}
|
|
|
|
|
2017-05-17 12:15:15 +02:00
|
|
|
fn install_sh(build: &Build, package: &str, name: &str, version: &str, stage: u32, host: Option<&str>,
|
2017-04-28 11:08:47 +02:00
|
|
|
prefix: &Path, sysconfdir: &Path, docdir: &Path, bindir: &Path, libdir: &Path,
|
|
|
|
mandir: &Path, empty_dir: &Path) {
|
2017-05-17 12:15:15 +02:00
|
|
|
println!("Install {} stage{} ({:?})", package, stage, host);
|
|
|
|
let package_name = if let Some(host) = host {
|
|
|
|
format!("{}-{}-{}", name, version, host)
|
|
|
|
} else {
|
|
|
|
format!("{}-{}", name, version)
|
|
|
|
};
|
2016-10-06 06:19:01 +02:00
|
|
|
|
|
|
|
let mut cmd = Command::new("sh");
|
|
|
|
cmd.current_dir(empty_dir)
|
|
|
|
.arg(sanitize_sh(&tmpdir(build).join(&package_name).join("install.sh")))
|
2016-10-06 07:42:19 +02:00
|
|
|
.arg(format!("--prefix={}", sanitize_sh(prefix)))
|
2017-04-28 11:08:47 +02:00
|
|
|
.arg(format!("--sysconfdir={}", sanitize_sh(sysconfdir)))
|
2016-10-06 07:42:19 +02:00
|
|
|
.arg(format!("--docdir={}", sanitize_sh(docdir)))
|
2017-04-28 10:58:46 +02:00
|
|
|
.arg(format!("--bindir={}", sanitize_sh(bindir)))
|
2016-10-06 07:42:19 +02:00
|
|
|
.arg(format!("--libdir={}", sanitize_sh(libdir)))
|
|
|
|
.arg(format!("--mandir={}", sanitize_sh(mandir)))
|
2016-10-06 06:19:01 +02:00
|
|
|
.arg("--disable-ldconfig");
|
|
|
|
build.run(&mut cmd);
|
2016-08-13 08:38:17 +02:00
|
|
|
}
|
2016-12-28 18:18:54 +01:00
|
|
|
|
|
|
|
fn add_destdir(path: &Path, destdir: &Option<PathBuf>) -> PathBuf {
|
|
|
|
let mut ret = match *destdir {
|
|
|
|
Some(ref dest) => dest.clone(),
|
|
|
|
None => return path.to_path_buf(),
|
|
|
|
};
|
|
|
|
for part in path.components() {
|
|
|
|
match part {
|
|
|
|
Component::Normal(s) => ret.push(s),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|