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