From e6985b2a6daa5acb84f364f6e6ddfdf170c28f2b Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Fri, 12 Aug 2016 23:38:17 -0700 Subject: [PATCH 1/3] rustbuild: Add install target. #34675 It just prints to the screen currently. --- src/bootstrap/install.rs | 22 ++++++++++++++++++++++ src/bootstrap/lib.rs | 3 +++ src/bootstrap/mk/Makefile.in | 2 ++ src/bootstrap/step.rs | 14 ++++++++++---- 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 src/bootstrap/install.rs diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs new file mode 100644 index 00000000000..8bad3dfb41e --- /dev/null +++ b/src/bootstrap/install.rs @@ -0,0 +1,22 @@ +// 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 or the MIT license +// , 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 Build; + +/// Installs everything. +pub fn install(_: &Build, stage: u32, host: &str) { + println!("Install everything stage{} ({})", stage, host); + println!("Note: install currently does nothing."); +} diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index b4f61605d47..9ffc433cd78 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -62,6 +62,7 @@ mod config; mod dist; mod doc; mod flags; +mod install; mod native; mod sanity; mod step; @@ -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, diff --git a/src/bootstrap/mk/Makefile.in b/src/bootstrap/mk/Makefile.in index cc44d45c2cc..61d0e254074 100644 --- a/src/bootstrap/mk/Makefile.in +++ b/src/bootstrap/mk/Makefile.in @@ -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 diff --git a/src/bootstrap/step.rs b/src/bootstrap/step.rs index e3567107884..22539b31ef2 100644 --- a/src/bootstrap/step.rs +++ b/src/bootstrap/step.rs @@ -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> }), } @@ -249,8 +252,7 @@ fn top_level(build: &Build) -> Vec { } } - return targets - + targets } fn add_steps<'a>(build: &'a Build, @@ -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)] @@ -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 } => { From a580f8f80d0563dc849529cb5908c4c618f272df Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Wed, 5 Oct 2016 21:19:01 -0700 Subject: [PATCH 2/3] Install docs, std and rustc using results from dist. --- src/bootstrap/dist.rs | 6 +++--- src/bootstrap/install.rs | 32 +++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 31b7db168b4..465abf15750 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -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", @@ -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") } @@ -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); diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 8bad3dfb41e..1c714620a01 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -13,10 +13,36 @@ //! This module is responsible for installing the standard library, //! compiler, and documentation. +use std::fs; +use std::path::Path; +use std::process::Command; + use Build; +use dist::{package_vers, sanitize_sh, tmpdir}; /// Installs everything. -pub fn install(_: &Build, stage: u32, host: &str) { - println!("Install everything stage{} ({})", stage, host); - println!("Note: install currently does nothing."); +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 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, &empty_dir); + } + install_sh(&build, "std", "rust-std", stage, host, prefix, &empty_dir); + install_sh(&build, "rustc", "rustc", stage, host, prefix, &empty_dir); + t!(fs::remove_dir_all(&empty_dir)); +} + +fn install_sh(build: &Build, package: &str, name: &str, stage: u32, host: &str, + prefix: &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("--disable-ldconfig"); + build.run(&mut cmd); } From fa230825c1da8605d51a2ef8d6b672b60baeb692 Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Wed, 5 Oct 2016 22:42:19 -0700 Subject: [PATCH 3/3] Add support for docdir, libdir and mandir. --- src/bootstrap/config.rs | 12 ++++++++++++ src/bootstrap/install.rs | 23 ++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index a8434c3efb3..e441d8d5ca7 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -79,6 +79,9 @@ pub struct Config { // Fallback musl-root for all targets pub musl_root: Option, pub prefix: Option, + pub docdir: Option, + pub libdir: Option, + pub mandir: Option, pub codegen_tests: bool, pub nodejs: Option, } @@ -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()); diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 1c714620a01..9bc5a7c00ab 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -14,6 +14,7 @@ //! compiler, and documentation. use std::fs; +use std::borrow::Cow; use std::path::Path; use std::process::Command; @@ -24,25 +25,37 @@ use dist::{package_vers, sanitize_sh, tmpdir}; 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, &empty_dir); + install_sh(&build, "docs", "rust-docs", stage, host, prefix, + &docdir, &libdir, &mandir, &empty_dir); } - install_sh(&build, "std", "rust-std", stage, host, prefix, &empty_dir); - install_sh(&build, "rustc", "rustc", stage, host, prefix, &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, empty_dir: &Path) { + 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!("--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); }