Skip to content

Commit 75c155b

Browse files
authored
Auto merge of #35641 - ahmedcharles:install, r=alexcrichton
rustbuild: Add install target. #34675 It just prints to the screen currently. r? @alexcrichton I'm working on the next commit to actually have it install.
2 parents ad19c32 + fa23082 commit 75c155b

File tree

6 files changed

+91
-7
lines changed

6 files changed

+91
-7
lines changed

src/bootstrap/config.rs

+12
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ pub struct Config {
7979
// Fallback musl-root for all targets
8080
pub musl_root: Option<PathBuf>,
8181
pub prefix: Option<String>,
82+
pub docdir: Option<String>,
83+
pub libdir: Option<String>,
84+
pub mandir: Option<String>,
8285
pub codegen_tests: bool,
8386
pub nodejs: Option<PathBuf>,
8487
}
@@ -359,6 +362,15 @@ impl Config {
359362
"CFG_PREFIX" => {
360363
self.prefix = Some(value.to_string());
361364
}
365+
"CFG_DOCDIR" => {
366+
self.docdir = Some(value.to_string());
367+
}
368+
"CFG_LIBDIR" => {
369+
self.libdir = Some(value.to_string());
370+
}
371+
"CFG_MANDIR" => {
372+
self.mandir = Some(value.to_string());
373+
}
362374
"CFG_LLVM_ROOT" if value.len() > 0 => {
363375
let target = self.target_config.entry(self.build.clone())
364376
.or_insert(Target::default());

src/bootstrap/dist.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use {Build, Compiler};
2727
use util::{cp_r, libdir, is_dylib, cp_filtered, copy};
2828
use regex::{RegexSet, quote};
2929

30-
fn package_vers(build: &Build) -> &str {
30+
pub fn package_vers(build: &Build) -> &str {
3131
match &build.config.channel[..] {
3232
"stable" => &build.release,
3333
"beta" => "beta",
@@ -40,7 +40,7 @@ fn distdir(build: &Build) -> PathBuf {
4040
build.out.join("dist")
4141
}
4242

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

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

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

src/bootstrap/install.rs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.
4+
//
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.
10+
11+
//! Implementation of the install aspects of the compiler.
12+
//!
13+
//! This module is responsible for installing the standard library,
14+
//! compiler, and documentation.
15+
16+
use std::fs;
17+
use std::borrow::Cow;
18+
use std::path::Path;
19+
use std::process::Command;
20+
21+
use Build;
22+
use dist::{package_vers, sanitize_sh, tmpdir};
23+
24+
/// Installs everything.
25+
pub fn install(build: &Build, stage: u32, host: &str) {
26+
let prefix = build.config.prefix.as_ref().clone().map(|x| Path::new(x))
27+
.unwrap_or(Path::new("/usr/local"));
28+
let docdir = build.config.docdir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x)))
29+
.unwrap_or(Cow::Owned(prefix.join("share/doc/rust")));
30+
let libdir = build.config.libdir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x)))
31+
.unwrap_or(Cow::Owned(prefix.join("lib")));
32+
let mandir = build.config.mandir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x)))
33+
.unwrap_or(Cow::Owned(prefix.join("share/man")));
34+
let empty_dir = build.out.join("tmp/empty_dir");
35+
t!(fs::create_dir_all(&empty_dir));
36+
if build.config.docs {
37+
install_sh(&build, "docs", "rust-docs", stage, host, prefix,
38+
&docdir, &libdir, &mandir, &empty_dir);
39+
}
40+
install_sh(&build, "std", "rust-std", stage, host, prefix,
41+
&docdir, &libdir, &mandir, &empty_dir);
42+
install_sh(&build, "rustc", "rustc", stage, host, prefix,
43+
&docdir, &libdir, &mandir, &empty_dir);
44+
t!(fs::remove_dir_all(&empty_dir));
45+
}
46+
47+
fn install_sh(build: &Build, package: &str, name: &str, stage: u32, host: &str,
48+
prefix: &Path, docdir: &Path, libdir: &Path, mandir: &Path, empty_dir: &Path) {
49+
println!("Install {} stage{} ({})", package, stage, host);
50+
let package_name = format!("{}-{}-{}", name, package_vers(build), host);
51+
52+
let mut cmd = Command::new("sh");
53+
cmd.current_dir(empty_dir)
54+
.arg(sanitize_sh(&tmpdir(build).join(&package_name).join("install.sh")))
55+
.arg(format!("--prefix={}", sanitize_sh(prefix)))
56+
.arg(format!("--docdir={}", sanitize_sh(docdir)))
57+
.arg(format!("--libdir={}", sanitize_sh(libdir)))
58+
.arg(format!("--mandir={}", sanitize_sh(mandir)))
59+
.arg("--disable-ldconfig");
60+
build.run(&mut cmd);
61+
}

src/bootstrap/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod config;
6262
mod dist;
6363
mod doc;
6464
mod flags;
65+
mod install;
6566
mod native;
6667
mod sanity;
6768
mod step;
@@ -453,6 +454,8 @@ impl Build {
453454
DistStd { compiler } => dist::std(self, &compiler, target.target),
454455
DistSrc { _dummy } => dist::rust_src(self),
455456

457+
Install { stage } => install::install(self, stage, target.target),
458+
456459
DebuggerScripts { stage } => {
457460
let compiler = Compiler::new(stage, target.target);
458461
dist::debugger_scripts(self,

src/bootstrap/mk/Makefile.in

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ check-cargotest:
5151
$(Q)$(BOOTSTRAP) --step check-cargotest
5252
dist:
5353
$(Q)$(BOOTSTRAP) --step dist
54+
install:
55+
$(Q)$(BOOTSTRAP) --step install
5456
tidy:
5557
$(Q)$(BOOTSTRAP) --step check-tidy --stage 0
5658

src/bootstrap/step.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ macro_rules! targets {
140140
(dist_std, DistStd { compiler: Compiler<'a> }),
141141
(dist_src, DistSrc { _dummy: () }),
142142

143+
// install target
144+
(install, Install { stage: u32 }),
145+
143146
// Misc targets
144147
(android_copy_libs, AndroidCopyLibs { compiler: Compiler<'a> }),
145148
}
@@ -249,8 +252,7 @@ fn top_level(build: &Build) -> Vec<Step> {
249252
}
250253
}
251254

252-
return targets
253-
255+
targets
254256
}
255257

256258
fn add_steps<'a>(build: &'a Build,
@@ -467,7 +469,7 @@ impl<'a> Step<'a> {
467469
self.dist(stage),
468470
]);
469471
}
470-
return base
472+
base
471473
}
472474
Source::CheckLinkcheck { stage } => {
473475
vec![self.tool_linkchecker(stage), self.doc(stage)]
@@ -590,7 +592,11 @@ impl<'a> Step<'a> {
590592
base.push(target.dist_std(compiler));
591593
}
592594
}
593-
return base
595+
base
596+
}
597+
598+
Source::Install { stage } => {
599+
vec![self.dist(stage)]
594600
}
595601

596602
Source::AndroidCopyLibs { compiler } => {

0 commit comments

Comments
 (0)