]> git.proxmox.com Git - rustc.git/blob - src/bootstrap/config.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / bootstrap / config.rs
1 // Copyright 2015 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 //! Serialized configuration of a build.
12 //!
13 //! This module implements parsing `config.mk` and `config.toml` configuration
14 //! files to tweak how the build runs.
15
16 use std::collections::HashMap;
17 use std::env;
18 use std::fs::{self, File};
19 use std::io::prelude::*;
20 use std::path::PathBuf;
21 use std::process;
22
23 use num_cpus;
24 use rustc_serialize::Decodable;
25 use toml::{Parser, Decoder, Value};
26 use util::{exe, push_exe_path};
27
28 /// Global configuration for the entire build and/or bootstrap.
29 ///
30 /// This structure is derived from a combination of both `config.toml` and
31 /// `config.mk`. As of the time of this writing it's unlikely that `config.toml`
32 /// is used all that much, so this is primarily filled out by `config.mk` which
33 /// is generated from `./configure`.
34 ///
35 /// Note that this structure is not decoded directly into, but rather it is
36 /// filled out from the decoded forms of the structs below. For documentation
37 /// each field, see the corresponding fields in
38 /// `src/bootstrap/config.toml.example`.
39 #[derive(Default)]
40 pub struct Config {
41 pub ccache: Option<String>,
42 pub ninja: bool,
43 pub verbose: usize,
44 pub submodules: bool,
45 pub compiler_docs: bool,
46 pub docs: bool,
47 pub locked_deps: bool,
48 pub vendor: bool,
49 pub target_config: HashMap<String, Target>,
50 pub full_bootstrap: bool,
51 pub extended: bool,
52 pub sanitizers: bool,
53
54 // llvm codegen options
55 pub llvm_assertions: bool,
56 pub llvm_optimize: bool,
57 pub llvm_release_debuginfo: bool,
58 pub llvm_version_check: bool,
59 pub llvm_static_stdcpp: bool,
60 pub llvm_link_shared: bool,
61 pub llvm_targets: Option<String>,
62 pub llvm_link_jobs: Option<u32>,
63 pub llvm_clean_rebuild: bool,
64
65 // rust codegen options
66 pub rust_optimize: bool,
67 pub rust_codegen_units: u32,
68 pub rust_debug_assertions: bool,
69 pub rust_debuginfo: bool,
70 pub rust_debuginfo_lines: bool,
71 pub rust_debuginfo_only_std: bool,
72 pub rust_rpath: bool,
73 pub rustc_default_linker: Option<String>,
74 pub rustc_default_ar: Option<String>,
75 pub rust_optimize_tests: bool,
76 pub rust_debuginfo_tests: bool,
77 pub rust_dist_src: bool,
78
79 pub build: String,
80 pub host: Vec<String>,
81 pub target: Vec<String>,
82 pub rustc: Option<PathBuf>,
83 pub cargo: Option<PathBuf>,
84 pub local_rebuild: bool,
85
86 // dist misc
87 pub dist_sign_folder: Option<PathBuf>,
88 pub dist_upload_addr: Option<String>,
89 pub dist_gpg_password_file: Option<PathBuf>,
90
91 // libstd features
92 pub debug_jemalloc: bool,
93 pub use_jemalloc: bool,
94 pub backtrace: bool, // support for RUST_BACKTRACE
95
96 // misc
97 pub low_priority: bool,
98 pub channel: String,
99 pub quiet_tests: bool,
100 // Fallback musl-root for all targets
101 pub musl_root: Option<PathBuf>,
102 pub prefix: Option<PathBuf>,
103 pub sysconfdir: Option<PathBuf>,
104 pub docdir: Option<PathBuf>,
105 pub bindir: Option<PathBuf>,
106 pub libdir: Option<PathBuf>,
107 pub libdir_relative: Option<PathBuf>,
108 pub mandir: Option<PathBuf>,
109 pub codegen_tests: bool,
110 pub nodejs: Option<PathBuf>,
111 pub gdb: Option<PathBuf>,
112 pub python: Option<PathBuf>,
113 pub configure_args: Vec<String>,
114 pub openssl_static: bool,
115 }
116
117 /// Per-target configuration stored in the global configuration structure.
118 #[derive(Default)]
119 pub struct Target {
120 pub llvm_config: Option<PathBuf>,
121 pub jemalloc: Option<PathBuf>,
122 pub cc: Option<PathBuf>,
123 pub cxx: Option<PathBuf>,
124 pub ndk: Option<PathBuf>,
125 pub musl_root: Option<PathBuf>,
126 pub qemu_rootfs: Option<PathBuf>,
127 }
128
129 /// Structure of the `config.toml` file that configuration is read from.
130 ///
131 /// This structure uses `Decodable` to automatically decode a TOML configuration
132 /// file into this format, and then this is traversed and written into the above
133 /// `Config` structure.
134 #[derive(RustcDecodable, Default)]
135 struct TomlConfig {
136 build: Option<Build>,
137 install: Option<Install>,
138 llvm: Option<Llvm>,
139 rust: Option<Rust>,
140 target: Option<HashMap<String, TomlTarget>>,
141 dist: Option<Dist>,
142 }
143
144 /// TOML representation of various global build decisions.
145 #[derive(RustcDecodable, Default, Clone)]
146 struct Build {
147 build: Option<String>,
148 host: Vec<String>,
149 target: Vec<String>,
150 cargo: Option<String>,
151 rustc: Option<String>,
152 low_priority: Option<bool>,
153 compiler_docs: Option<bool>,
154 docs: Option<bool>,
155 submodules: Option<bool>,
156 gdb: Option<String>,
157 locked_deps: Option<bool>,
158 vendor: Option<bool>,
159 nodejs: Option<String>,
160 python: Option<String>,
161 full_bootstrap: Option<bool>,
162 extended: Option<bool>,
163 verbose: Option<usize>,
164 sanitizers: Option<bool>,
165 openssl_static: Option<bool>,
166 }
167
168 /// TOML representation of various global install decisions.
169 #[derive(RustcDecodable, Default, Clone)]
170 struct Install {
171 prefix: Option<String>,
172 sysconfdir: Option<String>,
173 docdir: Option<String>,
174 bindir: Option<String>,
175 libdir: Option<String>,
176 mandir: Option<String>,
177 }
178
179 /// TOML representation of how the LLVM build is configured.
180 #[derive(RustcDecodable, Default)]
181 struct Llvm {
182 ccache: Option<StringOrBool>,
183 ninja: Option<bool>,
184 assertions: Option<bool>,
185 optimize: Option<bool>,
186 release_debuginfo: Option<bool>,
187 version_check: Option<bool>,
188 static_libstdcpp: Option<bool>,
189 targets: Option<String>,
190 link_jobs: Option<u32>,
191 clean_rebuild: Option<bool>,
192 }
193
194 #[derive(RustcDecodable, Default, Clone)]
195 struct Dist {
196 sign_folder: Option<String>,
197 gpg_password_file: Option<String>,
198 upload_addr: Option<String>,
199 src_tarball: Option<bool>,
200 }
201
202 #[derive(RustcDecodable)]
203 enum StringOrBool {
204 String(String),
205 Bool(bool),
206 }
207
208 impl Default for StringOrBool {
209 fn default() -> StringOrBool {
210 StringOrBool::Bool(false)
211 }
212 }
213
214 /// TOML representation of how the Rust build is configured.
215 #[derive(RustcDecodable, Default)]
216 struct Rust {
217 optimize: Option<bool>,
218 codegen_units: Option<u32>,
219 debug_assertions: Option<bool>,
220 debuginfo: Option<bool>,
221 debuginfo_lines: Option<bool>,
222 debuginfo_only_std: Option<bool>,
223 debug_jemalloc: Option<bool>,
224 use_jemalloc: Option<bool>,
225 backtrace: Option<bool>,
226 default_linker: Option<String>,
227 default_ar: Option<String>,
228 channel: Option<String>,
229 musl_root: Option<String>,
230 rpath: Option<bool>,
231 optimize_tests: Option<bool>,
232 debuginfo_tests: Option<bool>,
233 codegen_tests: Option<bool>,
234 }
235
236 /// TOML representation of how each build target is configured.
237 #[derive(RustcDecodable, Default)]
238 struct TomlTarget {
239 llvm_config: Option<String>,
240 jemalloc: Option<String>,
241 cc: Option<String>,
242 cxx: Option<String>,
243 android_ndk: Option<String>,
244 musl_root: Option<String>,
245 qemu_rootfs: Option<String>,
246 }
247
248 impl Config {
249 pub fn parse(build: &str, file: Option<PathBuf>) -> Config {
250 let mut config = Config::default();
251 config.llvm_optimize = true;
252 config.use_jemalloc = true;
253 config.backtrace = true;
254 config.rust_optimize = true;
255 config.rust_optimize_tests = true;
256 config.submodules = true;
257 config.docs = true;
258 config.rust_rpath = true;
259 config.rust_codegen_units = 1;
260 config.build = build.to_string();
261 config.channel = "dev".to_string();
262 config.codegen_tests = true;
263 config.rust_dist_src = true;
264
265 let toml = file.map(|file| {
266 let mut f = t!(File::open(&file));
267 let mut toml = String::new();
268 t!(f.read_to_string(&mut toml));
269 let mut p = Parser::new(&toml);
270 let table = match p.parse() {
271 Some(table) => table,
272 None => {
273 println!("failed to parse TOML configuration '{}':", file.to_str().unwrap());
274 for err in p.errors.iter() {
275 let (loline, locol) = p.to_linecol(err.lo);
276 let (hiline, hicol) = p.to_linecol(err.hi);
277 println!("{}:{}-{}:{}: {}", loline, locol, hiline,
278 hicol, err.desc);
279 }
280 process::exit(2);
281 }
282 };
283 let mut d = Decoder::new(Value::Table(table));
284 match Decodable::decode(&mut d) {
285 Ok(cfg) => cfg,
286 Err(e) => {
287 println!("failed to decode TOML: {}", e);
288 process::exit(2);
289 }
290 }
291 }).unwrap_or_else(|| TomlConfig::default());
292
293 let build = toml.build.clone().unwrap_or(Build::default());
294 set(&mut config.build, build.build.clone());
295 config.host.push(config.build.clone());
296 for host in build.host.iter() {
297 if !config.host.contains(host) {
298 config.host.push(host.clone());
299 }
300 }
301 for target in config.host.iter().chain(&build.target) {
302 if !config.target.contains(target) {
303 config.target.push(target.clone());
304 }
305 }
306 config.rustc = build.rustc.map(PathBuf::from);
307 config.cargo = build.cargo.map(PathBuf::from);
308 config.nodejs = build.nodejs.map(PathBuf::from);
309 config.gdb = build.gdb.map(PathBuf::from);
310 config.python = build.python.map(PathBuf::from);
311 set(&mut config.low_priority, build.low_priority);
312 set(&mut config.compiler_docs, build.compiler_docs);
313 set(&mut config.docs, build.docs);
314 set(&mut config.submodules, build.submodules);
315 set(&mut config.locked_deps, build.locked_deps);
316 set(&mut config.vendor, build.vendor);
317 set(&mut config.full_bootstrap, build.full_bootstrap);
318 set(&mut config.extended, build.extended);
319 set(&mut config.verbose, build.verbose);
320 set(&mut config.sanitizers, build.sanitizers);
321 set(&mut config.openssl_static, build.openssl_static);
322
323 if let Some(ref install) = toml.install {
324 config.prefix = install.prefix.clone().map(PathBuf::from);
325 config.sysconfdir = install.sysconfdir.clone().map(PathBuf::from);
326 config.docdir = install.docdir.clone().map(PathBuf::from);
327 config.bindir = install.bindir.clone().map(PathBuf::from);
328 config.libdir = install.libdir.clone().map(PathBuf::from);
329 config.mandir = install.mandir.clone().map(PathBuf::from);
330 }
331
332 if let Some(ref llvm) = toml.llvm {
333 match llvm.ccache {
334 Some(StringOrBool::String(ref s)) => {
335 config.ccache = Some(s.to_string())
336 }
337 Some(StringOrBool::Bool(true)) => {
338 config.ccache = Some("ccache".to_string());
339 }
340 Some(StringOrBool::Bool(false)) | None => {}
341 }
342 set(&mut config.ninja, llvm.ninja);
343 set(&mut config.llvm_assertions, llvm.assertions);
344 set(&mut config.llvm_optimize, llvm.optimize);
345 set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);
346 set(&mut config.llvm_version_check, llvm.version_check);
347 set(&mut config.llvm_static_stdcpp, llvm.static_libstdcpp);
348 set(&mut config.llvm_clean_rebuild, llvm.clean_rebuild);
349 config.llvm_targets = llvm.targets.clone();
350 config.llvm_link_jobs = llvm.link_jobs;
351 }
352
353 if let Some(ref rust) = toml.rust {
354 set(&mut config.rust_debug_assertions, rust.debug_assertions);
355 set(&mut config.rust_debuginfo, rust.debuginfo);
356 set(&mut config.rust_debuginfo_lines, rust.debuginfo_lines);
357 set(&mut config.rust_debuginfo_only_std, rust.debuginfo_only_std);
358 set(&mut config.rust_optimize, rust.optimize);
359 set(&mut config.rust_optimize_tests, rust.optimize_tests);
360 set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
361 set(&mut config.codegen_tests, rust.codegen_tests);
362 set(&mut config.rust_rpath, rust.rpath);
363 set(&mut config.debug_jemalloc, rust.debug_jemalloc);
364 set(&mut config.use_jemalloc, rust.use_jemalloc);
365 set(&mut config.backtrace, rust.backtrace);
366 set(&mut config.channel, rust.channel.clone());
367 config.rustc_default_linker = rust.default_linker.clone();
368 config.rustc_default_ar = rust.default_ar.clone();
369 config.musl_root = rust.musl_root.clone().map(PathBuf::from);
370
371 match rust.codegen_units {
372 Some(0) => config.rust_codegen_units = num_cpus::get() as u32,
373 Some(n) => config.rust_codegen_units = n,
374 None => {}
375 }
376 }
377
378 if let Some(ref t) = toml.target {
379 for (triple, cfg) in t {
380 let mut target = Target::default();
381
382 if let Some(ref s) = cfg.llvm_config {
383 target.llvm_config = Some(env::current_dir().unwrap().join(s));
384 }
385 if let Some(ref s) = cfg.jemalloc {
386 target.jemalloc = Some(env::current_dir().unwrap().join(s));
387 }
388 if let Some(ref s) = cfg.android_ndk {
389 target.ndk = Some(env::current_dir().unwrap().join(s));
390 }
391 target.cxx = cfg.cxx.clone().map(PathBuf::from);
392 target.cc = cfg.cc.clone().map(PathBuf::from);
393 target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
394 target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
395
396 config.target_config.insert(triple.clone(), target);
397 }
398 }
399
400 if let Some(ref t) = toml.dist {
401 config.dist_sign_folder = t.sign_folder.clone().map(PathBuf::from);
402 config.dist_gpg_password_file = t.gpg_password_file.clone().map(PathBuf::from);
403 config.dist_upload_addr = t.upload_addr.clone();
404 set(&mut config.rust_dist_src, t.src_tarball);
405 }
406
407
408 // compat with `./configure` while we're still using that
409 if fs::metadata("config.mk").is_ok() {
410 config.update_with_config_mk();
411 }
412
413 return config
414 }
415
416 /// "Temporary" routine to parse `config.mk` into this configuration.
417 ///
418 /// While we still have `./configure` this implements the ability to decode
419 /// that configuration into this. This isn't exactly a full-blown makefile
420 /// parser, but hey it gets the job done!
421 fn update_with_config_mk(&mut self) {
422 let mut config = String::new();
423 File::open("config.mk").unwrap().read_to_string(&mut config).unwrap();
424 for line in config.lines() {
425 let mut parts = line.splitn(2, ":=").map(|s| s.trim());
426 let key = parts.next().unwrap();
427 let value = match parts.next() {
428 Some(n) if n.starts_with('\"') => &n[1..n.len() - 1],
429 Some(n) => n,
430 None => continue
431 };
432
433 macro_rules! check {
434 ($(($name:expr, $val:expr),)*) => {
435 if value == "1" {
436 $(
437 if key == concat!("CFG_ENABLE_", $name) {
438 $val = true;
439 continue
440 }
441 if key == concat!("CFG_DISABLE_", $name) {
442 $val = false;
443 continue
444 }
445 )*
446 }
447 }
448 }
449
450 check! {
451 ("MANAGE_SUBMODULES", self.submodules),
452 ("COMPILER_DOCS", self.compiler_docs),
453 ("DOCS", self.docs),
454 ("LLVM_ASSERTIONS", self.llvm_assertions),
455 ("LLVM_RELEASE_DEBUGINFO", self.llvm_release_debuginfo),
456 ("OPTIMIZE_LLVM", self.llvm_optimize),
457 ("LLVM_VERSION_CHECK", self.llvm_version_check),
458 ("LLVM_STATIC_STDCPP", self.llvm_static_stdcpp),
459 ("LLVM_LINK_SHARED", self.llvm_link_shared),
460 ("LLVM_CLEAN_REBUILD", self.llvm_clean_rebuild),
461 ("OPTIMIZE", self.rust_optimize),
462 ("DEBUG_ASSERTIONS", self.rust_debug_assertions),
463 ("DEBUGINFO", self.rust_debuginfo),
464 ("DEBUGINFO_LINES", self.rust_debuginfo_lines),
465 ("DEBUGINFO_ONLY_STD", self.rust_debuginfo_only_std),
466 ("JEMALLOC", self.use_jemalloc),
467 ("DEBUG_JEMALLOC", self.debug_jemalloc),
468 ("RPATH", self.rust_rpath),
469 ("OPTIMIZE_TESTS", self.rust_optimize_tests),
470 ("DEBUGINFO_TESTS", self.rust_debuginfo_tests),
471 ("QUIET_TESTS", self.quiet_tests),
472 ("LOCAL_REBUILD", self.local_rebuild),
473 ("NINJA", self.ninja),
474 ("CODEGEN_TESTS", self.codegen_tests),
475 ("LOCKED_DEPS", self.locked_deps),
476 ("VENDOR", self.vendor),
477 ("FULL_BOOTSTRAP", self.full_bootstrap),
478 ("EXTENDED", self.extended),
479 ("SANITIZERS", self.sanitizers),
480 ("DIST_SRC", self.rust_dist_src),
481 ("CARGO_OPENSSL_STATIC", self.openssl_static),
482 }
483
484 match key {
485 "CFG_BUILD" if value.len() > 0 => self.build = value.to_string(),
486 "CFG_HOST" if value.len() > 0 => {
487 self.host.extend(value.split(" ").map(|s| s.to_string()));
488
489 }
490 "CFG_TARGET" if value.len() > 0 => {
491 self.target.extend(value.split(" ").map(|s| s.to_string()));
492 }
493 "CFG_MUSL_ROOT" if value.len() > 0 => {
494 self.musl_root = Some(parse_configure_path(value));
495 }
496 "CFG_MUSL_ROOT_X86_64" if value.len() > 0 => {
497 let target = "x86_64-unknown-linux-musl".to_string();
498 let target = self.target_config.entry(target)
499 .or_insert(Target::default());
500 target.musl_root = Some(parse_configure_path(value));
501 }
502 "CFG_MUSL_ROOT_I686" if value.len() > 0 => {
503 let target = "i686-unknown-linux-musl".to_string();
504 let target = self.target_config.entry(target)
505 .or_insert(Target::default());
506 target.musl_root = Some(parse_configure_path(value));
507 }
508 "CFG_MUSL_ROOT_ARM" if value.len() > 0 => {
509 let target = "arm-unknown-linux-musleabi".to_string();
510 let target = self.target_config.entry(target)
511 .or_insert(Target::default());
512 target.musl_root = Some(parse_configure_path(value));
513 }
514 "CFG_MUSL_ROOT_ARMHF" if value.len() > 0 => {
515 let target = "arm-unknown-linux-musleabihf".to_string();
516 let target = self.target_config.entry(target)
517 .or_insert(Target::default());
518 target.musl_root = Some(parse_configure_path(value));
519 }
520 "CFG_MUSL_ROOT_ARMV7" if value.len() > 0 => {
521 let target = "armv7-unknown-linux-musleabihf".to_string();
522 let target = self.target_config.entry(target)
523 .or_insert(Target::default());
524 target.musl_root = Some(parse_configure_path(value));
525 }
526 "CFG_DEFAULT_AR" if value.len() > 0 => {
527 self.rustc_default_ar = Some(value.to_string());
528 }
529 "CFG_DEFAULT_LINKER" if value.len() > 0 => {
530 self.rustc_default_linker = Some(value.to_string());
531 }
532 "CFG_GDB" if value.len() > 0 => {
533 self.gdb = Some(parse_configure_path(value));
534 }
535 "CFG_RELEASE_CHANNEL" => {
536 self.channel = value.to_string();
537 }
538 "CFG_PREFIX" => {
539 self.prefix = Some(PathBuf::from(value));
540 }
541 "CFG_SYSCONFDIR" => {
542 self.sysconfdir = Some(PathBuf::from(value));
543 }
544 "CFG_DOCDIR" => {
545 self.docdir = Some(PathBuf::from(value));
546 }
547 "CFG_BINDIR" => {
548 self.bindir = Some(PathBuf::from(value));
549 }
550 "CFG_LIBDIR" => {
551 self.libdir = Some(PathBuf::from(value));
552 }
553 "CFG_LIBDIR_RELATIVE" => {
554 self.libdir_relative = Some(PathBuf::from(value));
555 }
556 "CFG_MANDIR" => {
557 self.mandir = Some(PathBuf::from(value));
558 }
559 "CFG_LLVM_ROOT" if value.len() > 0 => {
560 let target = self.target_config.entry(self.build.clone())
561 .or_insert(Target::default());
562 let root = parse_configure_path(value);
563 target.llvm_config = Some(push_exe_path(root, &["bin", "llvm-config"]));
564 }
565 "CFG_JEMALLOC_ROOT" if value.len() > 0 => {
566 let target = self.target_config.entry(self.build.clone())
567 .or_insert(Target::default());
568 target.jemalloc = Some(parse_configure_path(value).join("libjemalloc_pic.a"));
569 }
570 "CFG_ARM_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
571 let target = "arm-linux-androideabi".to_string();
572 let target = self.target_config.entry(target)
573 .or_insert(Target::default());
574 target.ndk = Some(parse_configure_path(value));
575 }
576 "CFG_ARMV7_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
577 let target = "armv7-linux-androideabi".to_string();
578 let target = self.target_config.entry(target)
579 .or_insert(Target::default());
580 target.ndk = Some(parse_configure_path(value));
581 }
582 "CFG_I686_LINUX_ANDROID_NDK" if value.len() > 0 => {
583 let target = "i686-linux-android".to_string();
584 let target = self.target_config.entry(target)
585 .or_insert(Target::default());
586 target.ndk = Some(parse_configure_path(value));
587 }
588 "CFG_AARCH64_LINUX_ANDROID_NDK" if value.len() > 0 => {
589 let target = "aarch64-linux-android".to_string();
590 let target = self.target_config.entry(target)
591 .or_insert(Target::default());
592 target.ndk = Some(parse_configure_path(value));
593 }
594 "CFG_X86_64_LINUX_ANDROID_NDK" if value.len() > 0 => {
595 let target = "x86_64-linux-android".to_string();
596 let target = self.target_config.entry(target)
597 .or_insert(Target::default());
598 target.ndk = Some(parse_configure_path(value));
599 }
600 "CFG_LOCAL_RUST_ROOT" if value.len() > 0 => {
601 let path = parse_configure_path(value);
602 self.rustc = Some(push_exe_path(path.clone(), &["bin", "rustc"]));
603 self.cargo = Some(push_exe_path(path, &["bin", "cargo"]));
604 }
605 "CFG_PYTHON" if value.len() > 0 => {
606 let path = parse_configure_path(value);
607 self.python = Some(path);
608 }
609 "CFG_ENABLE_CCACHE" if value == "1" => {
610 self.ccache = Some(exe("ccache", &self.build));
611 }
612 "CFG_ENABLE_SCCACHE" if value == "1" => {
613 self.ccache = Some(exe("sccache", &self.build));
614 }
615 "CFG_CONFIGURE_ARGS" if value.len() > 0 => {
616 self.configure_args = value.split_whitespace()
617 .map(|s| s.to_string())
618 .collect();
619 }
620 "CFG_QEMU_ARMHF_ROOTFS" if value.len() > 0 => {
621 let target = "arm-unknown-linux-gnueabihf".to_string();
622 let target = self.target_config.entry(target)
623 .or_insert(Target::default());
624 target.qemu_rootfs = Some(parse_configure_path(value));
625 }
626 _ => {}
627 }
628 }
629 }
630
631 pub fn verbose(&self) -> bool {
632 self.verbose > 0
633 }
634
635 pub fn very_verbose(&self) -> bool {
636 self.verbose > 1
637 }
638 }
639
640 #[cfg(not(windows))]
641 fn parse_configure_path(path: &str) -> PathBuf {
642 path.into()
643 }
644
645 #[cfg(windows)]
646 fn parse_configure_path(path: &str) -> PathBuf {
647 // on windows, configure produces unix style paths e.g. /c/some/path but we
648 // only want real windows paths
649
650 use std::process::Command;
651 use build_helper;
652
653 // '/' is invalid in windows paths, so we can detect unix paths by the presence of it
654 if !path.contains('/') {
655 return path.into();
656 }
657
658 let win_path = build_helper::output(Command::new("cygpath").arg("-w").arg(path));
659 let win_path = win_path.trim();
660
661 win_path.into()
662 }
663
664 fn set<T>(field: &mut T, val: Option<T>) {
665 if let Some(v) = val {
666 *field = v;
667 }
668 }