Skip to content

rustbuild: Add install target. #34675 #35641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ pub struct Config {
// Fallback musl-root for all targets
pub musl_root: Option<PathBuf>,
pub prefix: Option<String>,
pub docdir: Option<String>,
pub libdir: Option<String>,
pub mandir: Option<String>,
pub codegen_tests: bool,
pub nodejs: Option<PathBuf>,
}
Expand Down Expand Up @@ -357,6 +360,15 @@ impl Config {
"CFG_PREFIX" => {
self.prefix = Some(value.to_string());
}
"CFG_DOCDIR" => {
self.docdir = Some(value.to_string());
}
"CFG_LIBDIR" => {
self.libdir = Some(value.to_string());
}
"CFG_MANDIR" => {
self.mandir = Some(value.to_string());
}
"CFG_LLVM_ROOT" if value.len() > 0 => {
let target = self.target_config.entry(self.build.clone())
.or_insert(Target::default());
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use {Build, Compiler};
use util::{cp_r, libdir, is_dylib, cp_filtered, copy};
use regex::{RegexSet, quote};

fn package_vers(build: &Build) -> &str {
pub fn package_vers(build: &Build) -> &str {
match &build.config.channel[..] {
"stable" => &build.release,
"beta" => "beta",
Expand All @@ -40,7 +40,7 @@ fn distdir(build: &Build) -> PathBuf {
build.out.join("dist")
}

fn tmpdir(build: &Build) -> PathBuf {
pub fn tmpdir(build: &Build) -> PathBuf {
build.out.join("tmp/dist")
}

Expand Down Expand Up @@ -418,7 +418,7 @@ fn chmod(_path: &Path, _perms: u32) {}

// We have to run a few shell scripts, which choke quite a bit on both `\`
// characters and on `C:\` paths, so normalize both of them away.
fn sanitize_sh(path: &Path) -> String {
pub fn sanitize_sh(path: &Path) -> String {
let path = path.to_str().unwrap().replace("\\", "/");
return change_drive(&path).unwrap_or(path);

Expand Down
61 changes: 61 additions & 0 deletions src/bootstrap/install.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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.

use std::fs;
use std::borrow::Cow;
use std::path::Path;
use std::process::Command;

use Build;
use dist::{package_vers, sanitize_sh, tmpdir};

/// Installs everything.
pub fn install(build: &Build, stage: u32, host: &str) {
let prefix = build.config.prefix.as_ref().clone().map(|x| Path::new(x))
.unwrap_or(Path::new("/usr/local"));
let docdir = build.config.docdir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x)))
.unwrap_or(Cow::Owned(prefix.join("share/doc/rust")));
let libdir = build.config.libdir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x)))
.unwrap_or(Cow::Owned(prefix.join("lib")));
let mandir = build.config.mandir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x)))
.unwrap_or(Cow::Owned(prefix.join("share/man")));
let empty_dir = build.out.join("tmp/empty_dir");
t!(fs::create_dir_all(&empty_dir));
if build.config.docs {
install_sh(&build, "docs", "rust-docs", stage, host, prefix,
&docdir, &libdir, &mandir, &empty_dir);
}
install_sh(&build, "std", "rust-std", stage, host, prefix,
&docdir, &libdir, &mandir, &empty_dir);
install_sh(&build, "rustc", "rustc", stage, host, prefix,
&docdir, &libdir, &mandir, &empty_dir);
t!(fs::remove_dir_all(&empty_dir));
}

fn install_sh(build: &Build, package: &str, name: &str, stage: u32, host: &str,
prefix: &Path, docdir: &Path, libdir: &Path, mandir: &Path, empty_dir: &Path) {
println!("Install {} stage{} ({})", package, stage, host);
let package_name = format!("{}-{}-{}", name, package_vers(build), host);

let mut cmd = Command::new("sh");
cmd.current_dir(empty_dir)
.arg(sanitize_sh(&tmpdir(build).join(&package_name).join("install.sh")))
.arg(format!("--prefix={}", sanitize_sh(prefix)))
.arg(format!("--docdir={}", sanitize_sh(docdir)))
.arg(format!("--libdir={}", sanitize_sh(libdir)))
.arg(format!("--mandir={}", sanitize_sh(mandir)))
.arg("--disable-ldconfig");
build.run(&mut cmd);
}
3 changes: 3 additions & 0 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ mod config;
mod dist;
mod doc;
mod flags;
mod install;
mod native;
mod sanity;
mod step;
Expand Down Expand Up @@ -453,6 +454,8 @@ impl Build {
DistStd { compiler } => dist::std(self, &compiler, target.target),
DistSrc { _dummy } => dist::rust_src(self),

Install { stage } => install::install(self, stage, target.target),

DebuggerScripts { stage } => {
let compiler = Compiler::new(stage, target.target);
dist::debugger_scripts(self,
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/mk/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ check-cargotest:
$(Q)$(BOOTSTRAP) --step check-cargotest
dist:
$(Q)$(BOOTSTRAP) --step dist
install:
$(Q)$(BOOTSTRAP) --step install
tidy:
$(Q)$(BOOTSTRAP) --step check-tidy --stage 0

Expand Down
14 changes: 10 additions & 4 deletions src/bootstrap/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ macro_rules! targets {
(dist_std, DistStd { compiler: Compiler<'a> }),
(dist_src, DistSrc { _dummy: () }),

// install target
(install, Install { stage: u32 }),

// Misc targets
(android_copy_libs, AndroidCopyLibs { compiler: Compiler<'a> }),
}
Expand Down Expand Up @@ -249,8 +252,7 @@ fn top_level(build: &Build) -> Vec<Step> {
}
}

return targets

targets
}

fn add_steps<'a>(build: &'a Build,
Expand Down Expand Up @@ -467,7 +469,7 @@ impl<'a> Step<'a> {
self.dist(stage),
]);
}
return base
base
}
Source::CheckLinkcheck { stage } => {
vec![self.tool_linkchecker(stage), self.doc(stage)]
Expand Down Expand Up @@ -590,7 +592,11 @@ impl<'a> Step<'a> {
base.push(target.dist_std(compiler));
}
}
return base
base
}

Source::Install { stage } => {
vec![self.dist(stage)]
}

Source::AndroidCopyLibs { compiler } => {
Expand Down