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.
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.
11 //! Command-line interface of the rustbuild build system.
13 //! This module implements the command-line parsing of the build system which
14 //! has various flags to configure how it's run.
17 use std
::path
::PathBuf
;
23 /// Deserialized version of all flags for this compile.
26 pub stage
: Option
<u32>,
30 pub step
: Vec
<String
>,
31 pub config
: Option
<PathBuf
>,
32 pub src
: Option
<PathBuf
>,
33 pub jobs
: Option
<u32>,
34 pub args
: Vec
<String
>,
43 pub fn parse(args
: &[String
]) -> Flags
{
44 let mut opts
= Options
::new();
45 opts
.optflag("v", "verbose", "use verbose output");
46 opts
.optopt("", "config", "TOML configuration file for build", "FILE");
47 opts
.optmulti("", "host", "host targets to build", "HOST");
48 opts
.reqopt("", "build", "build target of the stage0 compiler", "BUILD");
49 opts
.optmulti("", "target", "targets to build", "TARGET");
50 opts
.optmulti("s", "step", "build step to execute", "STEP");
51 opts
.optopt("", "stage", "stage to build", "N");
52 opts
.optopt("", "src", "path to repo root", "DIR");
53 opts
.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS");
54 opts
.optflag("", "clean", "clean output directory");
55 opts
.optflag("h", "help", "print this help message");
57 let usage
= |n
| -> ! {
58 let brief
= format
!("Usage: rust.py [options]");
59 print
!("{}", opts
.usage(&brief
));
63 let m
= opts
.parse(args
).unwrap_or_else(|e
| {
64 println
!("failed to parse options: {}", e
);
67 if m
.opt_present("h") {
71 let cfg_file
= m
.opt_str("config").map(PathBuf
::from
).or_else(|| {
72 if fs
::metadata("config.toml").is_ok() {
73 Some(PathBuf
::from("config.toml"))
80 verbose
: m
.opt_present("v"),
81 clean
: m
.opt_present("clean"),
82 stage
: m
.opt_str("stage").map(|j
| j
.parse().unwrap()),
83 build
: m
.opt_str("build").unwrap(),
84 host
: Filter { values: m.opt_strs("host") }
,
85 target
: Filter { values: m.opt_strs("target") }
,
86 step
: m
.opt_strs("step"),
88 src
: m
.opt_str("src").map(PathBuf
::from
),
89 jobs
: m
.opt_str("jobs").map(|j
| j
.parse().unwrap()),
96 pub fn contains(&self, name
: &str) -> bool
{
97 self.values
.len() == 0 || self.values
.iter().any(|s
| s
== name
)
100 pub fn iter(&self) -> slice
::Iter
<String
> {