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