]>
Commit | Line | Data |
---|---|---|
c30ab7b3 SL |
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 | ||
32a655c1 | 16 | use std::env; |
c30ab7b3 | 17 | use std::fs; |
32a655c1 | 18 | use std::path::{Path, PathBuf, Component}; |
c30ab7b3 SL |
19 | use std::process::Command; |
20 | ||
3b2f2976 | 21 | use dist::{self, pkgname, sanitize_sh, tmpdir}; |
7cac9316 | 22 | |
3b2f2976 XL |
23 | use builder::{Builder, RunConfig, ShouldRun, Step}; |
24 | use cache::Interned; | |
7cac9316 | 25 | |
3b2f2976 XL |
26 | pub fn install_docs(builder: &Builder, stage: u32, host: Interned<String>) { |
27 | install_sh(builder, "docs", "rust-docs", stage, Some(host)); | |
28 | } | |
cc61c64b | 29 | |
3b2f2976 XL |
30 | pub fn install_std(builder: &Builder, stage: u32) { |
31 | for target in &builder.build.targets { | |
32 | install_sh(builder, "std", "rust-std", stage, Some(*target)); | |
7cac9316 | 33 | } |
3b2f2976 | 34 | } |
c30ab7b3 | 35 | |
3b2f2976 XL |
36 | pub fn install_cargo(builder: &Builder, stage: u32, host: Interned<String>) { |
37 | install_sh(builder, "cargo", "cargo", stage, Some(host)); | |
38 | } | |
7cac9316 | 39 | |
3b2f2976 XL |
40 | pub fn install_rls(builder: &Builder, stage: u32, host: Interned<String>) { |
41 | install_sh(builder, "rls", "rls", stage, Some(host)); | |
42 | } | |
7cac9316 | 43 | |
3b2f2976 XL |
44 | pub fn install_analysis(builder: &Builder, stage: u32, host: Interned<String>) { |
45 | install_sh(builder, "analysis", "rust-analysis", stage, Some(host)); | |
46 | } | |
7cac9316 | 47 | |
3b2f2976 XL |
48 | pub fn install_src(builder: &Builder, stage: u32) { |
49 | install_sh(builder, "src", "rust-src", stage, None); | |
50 | } | |
51 | pub fn install_rustc(builder: &Builder, stage: u32, host: Interned<String>) { | |
52 | install_sh(builder, "rustc", "rustc", stage, Some(host)); | |
53 | } | |
7cac9316 | 54 | |
3b2f2976 XL |
55 | fn install_sh( |
56 | builder: &Builder, | |
57 | package: &str, | |
58 | name: &str, | |
59 | stage: u32, | |
60 | host: Option<Interned<String>> | |
61 | ) { | |
62 | let build = builder.build; | |
63 | println!("Install {} stage{} ({:?})", package, stage, host); | |
64 | ||
65 | let prefix_default = PathBuf::from("/usr/local"); | |
66 | let sysconfdir_default = PathBuf::from("/etc"); | |
67 | let docdir_default = PathBuf::from("share/doc/rust"); | |
68 | let bindir_default = PathBuf::from("bin"); | |
69 | let libdir_default = PathBuf::from("lib"); | |
70 | let mandir_default = PathBuf::from("share/man"); | |
71 | let prefix = build.config.prefix.as_ref().unwrap_or(&prefix_default); | |
72 | let sysconfdir = build.config.sysconfdir.as_ref().unwrap_or(&sysconfdir_default); | |
73 | let docdir = build.config.docdir.as_ref().unwrap_or(&docdir_default); | |
74 | let bindir = build.config.bindir.as_ref().unwrap_or(&bindir_default); | |
75 | let libdir = build.config.libdir.as_ref().unwrap_or(&libdir_default); | |
76 | let mandir = build.config.mandir.as_ref().unwrap_or(&mandir_default); | |
77 | ||
78 | let sysconfdir = prefix.join(sysconfdir); | |
79 | let docdir = prefix.join(docdir); | |
80 | let bindir = prefix.join(bindir); | |
81 | let libdir = prefix.join(libdir); | |
82 | let mandir = prefix.join(mandir); | |
83 | ||
84 | let destdir = env::var_os("DESTDIR").map(PathBuf::from); | |
85 | ||
86 | let prefix = add_destdir(&prefix, &destdir); | |
87 | let sysconfdir = add_destdir(&sysconfdir, &destdir); | |
88 | let docdir = add_destdir(&docdir, &destdir); | |
89 | let bindir = add_destdir(&bindir, &destdir); | |
90 | let libdir = add_destdir(&libdir, &destdir); | |
91 | let mandir = add_destdir(&mandir, &destdir); | |
92 | ||
93 | let empty_dir = build.out.join("tmp/empty_dir"); | |
94 | ||
95 | t!(fs::create_dir_all(&empty_dir)); | |
96 | let package_name = if let Some(host) = host { | |
97 | format!("{}-{}", pkgname(build, name), host) | |
98 | } else { | |
99 | pkgname(build, name) | |
100 | }; | |
7cac9316 | 101 | |
3b2f2976 XL |
102 | let mut cmd = Command::new("sh"); |
103 | cmd.current_dir(&empty_dir) | |
104 | .arg(sanitize_sh(&tmpdir(build).join(&package_name).join("install.sh"))) | |
105 | .arg(format!("--prefix={}", sanitize_sh(&prefix))) | |
106 | .arg(format!("--sysconfdir={}", sanitize_sh(&sysconfdir))) | |
107 | .arg(format!("--docdir={}", sanitize_sh(&docdir))) | |
108 | .arg(format!("--bindir={}", sanitize_sh(&bindir))) | |
109 | .arg(format!("--libdir={}", sanitize_sh(&libdir))) | |
110 | .arg(format!("--mandir={}", sanitize_sh(&mandir))) | |
111 | .arg("--disable-ldconfig"); | |
112 | build.run(&mut cmd); | |
113 | t!(fs::remove_dir_all(&empty_dir)); | |
c30ab7b3 | 114 | } |
32a655c1 SL |
115 | |
116 | fn add_destdir(path: &Path, destdir: &Option<PathBuf>) -> PathBuf { | |
117 | let mut ret = match *destdir { | |
118 | Some(ref dest) => dest.clone(), | |
119 | None => return path.to_path_buf(), | |
120 | }; | |
121 | for part in path.components() { | |
122 | match part { | |
123 | Component::Normal(s) => ret.push(s), | |
124 | _ => {} | |
125 | } | |
126 | } | |
041b39d2 | 127 | ret |
32a655c1 | 128 | } |
3b2f2976 XL |
129 | |
130 | macro_rules! install { | |
131 | (($sel:ident, $builder:ident, $_config:ident), | |
132 | $($name:ident, | |
133 | $path:expr, | |
134 | $default_cond:expr, | |
135 | only_hosts: $only_hosts:expr, | |
136 | $run_item:block $(, $c:ident)*;)+) => { | |
137 | $( | |
138 | #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] | |
139 | pub struct $name { | |
140 | pub stage: u32, | |
141 | pub target: Interned<String>, | |
142 | pub host: Interned<String>, | |
143 | } | |
144 | ||
145 | impl Step for $name { | |
146 | type Output = (); | |
147 | const DEFAULT: bool = true; | |
148 | const ONLY_BUILD_TARGETS: bool = true; | |
149 | const ONLY_HOSTS: bool = $only_hosts; | |
150 | $(const $c: bool = true;)* | |
151 | ||
152 | fn should_run(run: ShouldRun) -> ShouldRun { | |
153 | let $_config = &run.builder.config; | |
154 | run.path($path).default_condition($default_cond) | |
155 | } | |
156 | ||
157 | fn make_run(run: RunConfig) { | |
158 | run.builder.ensure($name { | |
159 | stage: run.builder.top_stage, | |
160 | target: run.target, | |
161 | host: run.host, | |
162 | }); | |
163 | } | |
164 | ||
165 | fn run($sel, $builder: &Builder) { | |
166 | $run_item | |
167 | } | |
168 | })+ | |
169 | } | |
170 | } | |
171 | ||
172 | install!((self, builder, _config), | |
173 | Docs, "src/doc", _config.docs, only_hosts: false, { | |
174 | builder.ensure(dist::Docs { stage: self.stage, host: self.target }); | |
175 | install_docs(builder, self.stage, self.target); | |
176 | }; | |
177 | Std, "src/libstd", true, only_hosts: true, { | |
178 | builder.ensure(dist::Std { | |
179 | compiler: builder.compiler(self.stage, self.host), | |
180 | target: self.target | |
181 | }); | |
182 | install_std(builder, self.stage); | |
183 | }; | |
184 | Cargo, "cargo", _config.extended, only_hosts: true, { | |
185 | builder.ensure(dist::Cargo { stage: self.stage, target: self.target }); | |
186 | install_cargo(builder, self.stage, self.target); | |
187 | }; | |
188 | Rls, "rls", _config.extended, only_hosts: true, { | |
189 | builder.ensure(dist::Rls { stage: self.stage, target: self.target }); | |
190 | install_rls(builder, self.stage, self.target); | |
191 | }; | |
192 | Analysis, "analysis", _config.extended, only_hosts: false, { | |
193 | builder.ensure(dist::Analysis { | |
194 | compiler: builder.compiler(self.stage, self.host), | |
195 | target: self.target | |
196 | }); | |
197 | install_analysis(builder, self.stage, self.target); | |
198 | }; | |
199 | Src, "src", _config.extended, only_hosts: true, { | |
200 | builder.ensure(dist::Src); | |
201 | install_src(builder, self.stage); | |
202 | }, ONLY_BUILD; | |
203 | Rustc, "src/librustc", true, only_hosts: true, { | |
204 | builder.ensure(dist::Rustc { | |
205 | compiler: builder.compiler(self.stage, self.target), | |
206 | }); | |
207 | install_rustc(builder, self.stage, self.target); | |
208 | }; | |
209 | ); |