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