2016-08-12 23:38:17 -07: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 09:18:54 -08:00
|
|
|
use std::env;
|
2016-10-05 21:19:01 -07:00
|
|
|
use std::fs;
|
2016-12-28 09:18:54 -08:00
|
|
|
use std::path::{Path, PathBuf, Component};
|
2016-10-05 21:19:01 -07:00
|
|
|
use std::process::Command;
|
|
|
|
|
2016-08-12 23:38:17 -07:00
|
|
|
use Build;
|
2017-05-18 22:48:14 +02:00
|
|
|
use dist::{pkgname, sanitize_sh, tmpdir};
|
2016-08-12 23:38:17 -07:00
|
|
|
|
2017-05-18 10:56:25 +02:00
|
|
|
pub struct Installer<'a> {
|
|
|
|
build: &'a Build,
|
|
|
|
prefix: PathBuf,
|
|
|
|
sysconfdir: PathBuf,
|
|
|
|
docdir: PathBuf,
|
|
|
|
bindir: PathBuf,
|
|
|
|
libdir: PathBuf,
|
|
|
|
mandir: PathBuf,
|
2017-05-18 22:48:14 +02:00
|
|
|
empty_dir: PathBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Drop for Installer<'a> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
t!(fs::remove_dir_all(&self.empty_dir));
|
|
|
|
}
|
2017-05-18 10:56:25 +02:00
|
|
|
}
|
2017-03-13 14:44:54 -03:00
|
|
|
|
2017-05-18 10:56:25 +02:00
|
|
|
impl<'a> Installer<'a> {
|
|
|
|
pub fn new(build: &'a Build) -> Installer<'a> {
|
|
|
|
let prefix_default = PathBuf::from("/usr/local");
|
|
|
|
let sysconfdir_default = PathBuf::from("/etc");
|
|
|
|
let docdir_default = PathBuf::from("share/doc/rust");
|
|
|
|
let bindir_default = PathBuf::from("bin");
|
|
|
|
let libdir_default = PathBuf::from("lib");
|
|
|
|
let mandir_default = PathBuf::from("share/man");
|
|
|
|
let prefix = build.config.prefix.as_ref().unwrap_or(&prefix_default);
|
|
|
|
let sysconfdir = build.config.sysconfdir.as_ref().unwrap_or(&sysconfdir_default);
|
|
|
|
let docdir = build.config.docdir.as_ref().unwrap_or(&docdir_default);
|
|
|
|
let bindir = build.config.bindir.as_ref().unwrap_or(&bindir_default);
|
|
|
|
let libdir = build.config.libdir.as_ref().unwrap_or(&libdir_default);
|
|
|
|
let mandir = build.config.mandir.as_ref().unwrap_or(&mandir_default);
|
|
|
|
|
|
|
|
let sysconfdir = prefix.join(sysconfdir);
|
|
|
|
let docdir = prefix.join(docdir);
|
|
|
|
let bindir = prefix.join(bindir);
|
|
|
|
let libdir = prefix.join(libdir);
|
|
|
|
let mandir = prefix.join(mandir);
|
|
|
|
|
|
|
|
let destdir = env::var_os("DESTDIR").map(PathBuf::from);
|
2017-04-27 11:53:18 +02:00
|
|
|
|
2017-05-18 10:56:25 +02:00
|
|
|
let prefix = add_destdir(&prefix, &destdir);
|
|
|
|
let sysconfdir = add_destdir(&sysconfdir, &destdir);
|
|
|
|
let docdir = add_destdir(&docdir, &destdir);
|
|
|
|
let bindir = add_destdir(&bindir, &destdir);
|
|
|
|
let libdir = add_destdir(&libdir, &destdir);
|
|
|
|
let mandir = add_destdir(&mandir, &destdir);
|
|
|
|
|
2017-05-18 22:48:14 +02:00
|
|
|
let empty_dir = build.out.join("tmp/empty_dir");
|
|
|
|
|
|
|
|
t!(fs::create_dir_all(&empty_dir));
|
|
|
|
|
2017-05-18 10:56:25 +02:00
|
|
|
Installer {
|
|
|
|
build,
|
|
|
|
prefix,
|
|
|
|
sysconfdir,
|
|
|
|
docdir,
|
|
|
|
bindir,
|
|
|
|
libdir,
|
|
|
|
mandir,
|
2017-05-18 22:48:14 +02:00
|
|
|
empty_dir,
|
2017-05-18 10:56:25 +02:00
|
|
|
}
|
2017-03-13 14:44:54 -03:00
|
|
|
}
|
|
|
|
|
2017-05-18 22:48:14 +02:00
|
|
|
pub fn install_docs(&self, stage: u32, host: &str) {
|
|
|
|
self.install_sh("docs", "rust-docs", stage, Some(host));
|
|
|
|
}
|
2016-10-05 21:19:01 -07:00
|
|
|
|
2017-05-18 22:48:14 +02:00
|
|
|
pub fn install_std(&self, stage: u32) {
|
2017-05-18 10:56:25 +02:00
|
|
|
for target in self.build.config.target.iter() {
|
2017-05-18 22:48:14 +02:00
|
|
|
self.install_sh("std", "rust-std", stage, Some(target));
|
2017-05-18 10:56:25 +02:00
|
|
|
}
|
2017-05-18 22:48:14 +02:00
|
|
|
}
|
2017-05-18 10:56:25 +02:00
|
|
|
|
2017-05-18 22:48:14 +02:00
|
|
|
pub fn install_cargo(&self, stage: u32, host: &str) {
|
|
|
|
self.install_sh("cargo", "cargo", stage, Some(host));
|
|
|
|
}
|
2017-05-18 10:56:25 +02:00
|
|
|
|
2017-05-18 22:48:14 +02:00
|
|
|
pub fn install_rls(&self, stage: u32, host: &str) {
|
|
|
|
self.install_sh("rls", "rls", stage, Some(host));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn install_analysis(&self, stage: u32, host: &str) {
|
|
|
|
self.install_sh("analysis", "rust-analysis", stage, Some(host));
|
|
|
|
}
|
2016-10-05 21:19:01 -07:00
|
|
|
|
2017-05-18 22:48:14 +02:00
|
|
|
pub fn install_src(&self, stage: u32) {
|
|
|
|
self.install_sh("src", "rust-src", stage, None);
|
|
|
|
}
|
|
|
|
pub fn install_rustc(&self, stage: u32, host: &str) {
|
|
|
|
self.install_sh("rustc", "rustc", stage, Some(host));
|
2017-05-18 10:56:25 +02:00
|
|
|
}
|
|
|
|
|
2017-05-18 22:48:14 +02:00
|
|
|
fn install_sh(&self, package: &str, name: &str, stage: u32, host: Option<&str>) {
|
2017-05-18 10:56:25 +02:00
|
|
|
println!("Install {} stage{} ({:?})", package, stage, host);
|
|
|
|
let package_name = if let Some(host) = host {
|
2017-05-18 22:48:14 +02:00
|
|
|
format!("{}-{}", pkgname(self.build, name), host)
|
2017-05-18 10:56:25 +02:00
|
|
|
} else {
|
2017-05-18 22:48:14 +02:00
|
|
|
pkgname(self.build, name)
|
2017-05-18 10:56:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut cmd = Command::new("sh");
|
2017-05-18 22:48:14 +02:00
|
|
|
cmd.current_dir(&self.empty_dir)
|
2017-05-18 10:56:25 +02:00
|
|
|
.arg(sanitize_sh(&tmpdir(self.build).join(&package_name).join("install.sh")))
|
|
|
|
.arg(format!("--prefix={}", sanitize_sh(&self.prefix)))
|
|
|
|
.arg(format!("--sysconfdir={}", sanitize_sh(&self.sysconfdir)))
|
|
|
|
.arg(format!("--docdir={}", sanitize_sh(&self.docdir)))
|
|
|
|
.arg(format!("--bindir={}", sanitize_sh(&self.bindir)))
|
|
|
|
.arg(format!("--libdir={}", sanitize_sh(&self.libdir)))
|
|
|
|
.arg(format!("--mandir={}", sanitize_sh(&self.mandir)))
|
|
|
|
.arg("--disable-ldconfig");
|
|
|
|
self.build.run(&mut cmd);
|
|
|
|
}
|
2016-08-12 23:38:17 -07:00
|
|
|
}
|
2016-12-28 09:18:54 -08: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),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2017-06-27 09:51:26 -06:00
|
|
|
ret
|
2016-12-28 09:18:54 -08:00
|
|
|
}
|
2017-07-04 17:53:53 -06:00
|
|
|
/*
|
|
|
|
rules.install("install-docs", "src/doc")
|
|
|
|
.default(build.config.docs)
|
|
|
|
.only_host_build(true)
|
|
|
|
.dep(|s| s.name("dist-docs"))
|
|
|
|
.run(move |s| install::Installer::new(build).install_docs(s.stage, s.target));
|
|
|
|
rules.install("install-std", "src/libstd")
|
|
|
|
.default(true)
|
|
|
|
.only_host_build(true)
|
|
|
|
.dep(|s| s.name("dist-std"))
|
|
|
|
.run(move |s| install::Installer::new(build).install_std(s.stage));
|
|
|
|
rules.install("install-cargo", "cargo")
|
|
|
|
.default(build.config.extended)
|
|
|
|
.host(true)
|
|
|
|
.only_host_build(true)
|
|
|
|
.dep(|s| s.name("dist-cargo"))
|
|
|
|
.run(move |s| install::Installer::new(build).install_cargo(s.stage, s.target));
|
|
|
|
rules.install("install-rls", "rls")
|
|
|
|
.default(build.config.extended)
|
|
|
|
.host(true)
|
|
|
|
.only_host_build(true)
|
|
|
|
.dep(|s| s.name("dist-rls"))
|
|
|
|
.run(move |s| install::Installer::new(build).install_rls(s.stage, s.target));
|
|
|
|
rules.install("install-analysis", "analysis")
|
|
|
|
.default(build.config.extended)
|
|
|
|
.only_host_build(true)
|
|
|
|
.dep(|s| s.name("dist-analysis"))
|
|
|
|
.run(move |s| install::Installer::new(build).install_analysis(s.stage, s.target));
|
|
|
|
rules.install("install-src", "src")
|
|
|
|
.default(build.config.extended)
|
|
|
|
.host(true)
|
|
|
|
.only_build(true)
|
|
|
|
.only_host_build(true)
|
|
|
|
.dep(|s| s.name("dist-src"))
|
|
|
|
.run(move |s| install::Installer::new(build).install_src(s.stage));
|
|
|
|
rules.install("install-rustc", "src/librustc")
|
|
|
|
.default(true)
|
|
|
|
.host(true)
|
|
|
|
.only_host_build(true)
|
|
|
|
.dep(|s| s.name("dist-rustc"))
|
|
|
|
.run(move |s| install::Installer::new(build).install_rustc(s.stage, s.target));
|
|
|
|
*/
|