Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5c3d0e6

Browse files
committedJun 20, 2017
Switch to the crates.io getopts crate
This commit deletes the in-tree `getopts` crate in favor of the crates.io-based `getopts` crate. The main difference here is with a new builder-style API, but otherwise everything else remains relatively standard.
1 parent a4024c5 commit 5c3d0e6

File tree

14 files changed

+317
-277
lines changed

14 files changed

+317
-277
lines changed
 

‎src/Cargo.lock

Lines changed: 5 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/bootstrap/dist.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ pub fn rust_src(build: &Build) {
567567
"src/rustc/libc_shim",
568568
"src/libtest",
569569
"src/libterm",
570-
"src/libgetopts",
571570
"src/compiler-rt",
572571
"src/jemalloc",
573572
"src/libprofiler_builtins",

‎src/libgetopts/Cargo.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎src/librustc/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#![feature(discriminant_value)]
4242
#![feature(sort_unstable)]
4343
#![feature(trace_macros)]
44+
#![feature(test)]
4445

4546
#![recursion_limit="256"]
4647

@@ -63,7 +64,10 @@ extern crate syntax_pos;
6364

6465
extern crate serialize as rustc_serialize; // used by deriving
6566

67+
// Note that librustc doesn't actually depend on these crates, see the note in
68+
// `Cargo.toml` for this crate about why these are here.
6669
extern crate flate2;
70+
extern crate test;
6771

6872
#[macro_use]
6973
mod macros;

‎src/librustc/session/config.rs

Lines changed: 72 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,9 +1135,9 @@ pub enum OptionStability {
11351135
Unstable,
11361136
}
11371137

1138-
#[derive(Clone, PartialEq, Eq)]
11391138
pub struct RustcOptGroup {
1140-
pub opt_group: getopts::OptGroup,
1139+
pub apply: Box<Fn(&mut getopts::Options) -> &mut getopts::Options>,
1140+
pub name: &'static str,
11411141
pub stability: OptionStability,
11421142
}
11431143

@@ -1146,12 +1146,24 @@ impl RustcOptGroup {
11461146
self.stability == OptionStability::Stable
11471147
}
11481148

1149-
pub fn stable(g: getopts::OptGroup) -> RustcOptGroup {
1150-
RustcOptGroup { opt_group: g, stability: OptionStability::Stable }
1149+
pub fn stable<F>(name: &'static str, f: F) -> RustcOptGroup
1150+
where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
1151+
{
1152+
RustcOptGroup {
1153+
name: name,
1154+
apply: Box::new(f),
1155+
stability: OptionStability::Stable,
1156+
}
11511157
}
11521158

1153-
pub fn unstable(g: getopts::OptGroup) -> RustcOptGroup {
1154-
RustcOptGroup { opt_group: g, stability: OptionStability::Unstable }
1159+
pub fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup
1160+
where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
1161+
{
1162+
RustcOptGroup {
1163+
name: name,
1164+
apply: Box::new(f),
1165+
stability: OptionStability::Unstable,
1166+
}
11551167
}
11561168
}
11571169

@@ -1170,55 +1182,65 @@ mod opt {
11701182
use super::RustcOptGroup;
11711183

11721184
pub type R = RustcOptGroup;
1173-
pub type S<'a> = &'a str;
1185+
pub type S = &'static str;
1186+
1187+
fn stable<F>(name: S, f: F) -> R
1188+
where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static
1189+
{
1190+
RustcOptGroup::stable(name, f)
1191+
}
11741192

1175-
fn stable(g: getopts::OptGroup) -> R { RustcOptGroup::stable(g) }
1176-
fn unstable(g: getopts::OptGroup) -> R { RustcOptGroup::unstable(g) }
1193+
fn unstable<F>(name: S, f: F) -> R
1194+
where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static
1195+
{
1196+
RustcOptGroup::unstable(name, f)
1197+
}
1198+
1199+
fn longer(a: S, b: S) -> S {
1200+
if a.len() > b.len() {
1201+
a
1202+
} else {
1203+
b
1204+
}
1205+
}
11771206

11781207
pub fn opt_s(a: S, b: S, c: S, d: S) -> R {
1179-
stable(getopts::optopt(a, b, c, d))
1208+
stable(longer(a, b), move |opts| opts.optopt(a, b, c, d))
11801209
}
11811210
pub fn multi_s(a: S, b: S, c: S, d: S) -> R {
1182-
stable(getopts::optmulti(a, b, c, d))
1211+
stable(longer(a, b), move |opts| opts.optmulti(a, b, c, d))
11831212
}
11841213
pub fn flag_s(a: S, b: S, c: S) -> R {
1185-
stable(getopts::optflag(a, b, c))
1214+
stable(longer(a, b), move |opts| opts.optflag(a, b, c))
11861215
}
11871216
pub fn flagopt_s(a: S, b: S, c: S, d: S) -> R {
1188-
stable(getopts::optflagopt(a, b, c, d))
1217+
stable(longer(a, b), move |opts| opts.optflagopt(a, b, c, d))
11891218
}
11901219
pub fn flagmulti_s(a: S, b: S, c: S) -> R {
1191-
stable(getopts::optflagmulti(a, b, c))
1220+
stable(longer(a, b), move |opts| opts.optflagmulti(a, b, c))
11921221
}
11931222

11941223
pub fn opt(a: S, b: S, c: S, d: S) -> R {
1195-
unstable(getopts::optopt(a, b, c, d))
1224+
unstable(longer(a, b), move |opts| opts.optopt(a, b, c, d))
11961225
}
11971226
pub fn multi(a: S, b: S, c: S, d: S) -> R {
1198-
unstable(getopts::optmulti(a, b, c, d))
1227+
unstable(longer(a, b), move |opts| opts.optmulti(a, b, c, d))
11991228
}
12001229
pub fn flag(a: S, b: S, c: S) -> R {
1201-
unstable(getopts::optflag(a, b, c))
1230+
unstable(longer(a, b), move |opts| opts.optflag(a, b, c))
12021231
}
12031232
pub fn flagopt(a: S, b: S, c: S, d: S) -> R {
1204-
unstable(getopts::optflagopt(a, b, c, d))
1233+
unstable(longer(a, b), move |opts| opts.optflagopt(a, b, c, d))
12051234
}
12061235
pub fn flagmulti(a: S, b: S, c: S) -> R {
1207-
unstable(getopts::optflagmulti(a, b, c))
1236+
unstable(longer(a, b), move |opts| opts.optflagmulti(a, b, c))
12081237
}
12091238
}
12101239

12111240
/// Returns the "short" subset of the rustc command line options,
12121241
/// including metadata for each option, such as whether the option is
12131242
/// part of the stable long-term interface for rustc.
12141243
pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
1215-
let mut print_opts = vec!["crate-name", "file-names", "sysroot", "cfg",
1216-
"target-list", "target-cpus", "target-features",
1217-
"relocation-models", "code-models"];
1218-
if nightly_options::is_nightly_build() {
1219-
print_opts.push("target-spec-json");
1220-
}
1221-
12221244
vec![
12231245
opt::flag_s("h", "help", "Display this message"),
12241246
opt::multi_s("", "cfg", "Configure the compilation environment", "SPEC"),
@@ -1238,8 +1260,10 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
12381260
the compiler to emit",
12391261
"[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]"),
12401262
opt::multi_s("", "print", "Comma separated list of compiler information to \
1241-
print on stdout", &format!("[{}]",
1242-
&print_opts.join("|"))),
1263+
print on stdout",
1264+
"[crate-name|file-names|sysroot|cfg|target-list|\
1265+
target-cpus|target-features|relocation-models|\
1266+
code-models|target-spec-json]"),
12431267
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
12441268
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
12451269
opt::opt_s("o", "", "Write output to <filename>", "FILENAME"),
@@ -1267,7 +1291,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
12671291
/// long-term interface for rustc.
12681292
pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
12691293
let mut opts = rustc_short_optgroups();
1270-
opts.extend_from_slice(&[
1294+
opts.extend(vec![
12711295
opt::multi_s("", "extern", "Specify where an external rust library is located",
12721296
"NAME=PATH"),
12731297
opt::opt_s("", "sysroot", "Override the system root", "PATH"),
@@ -1680,27 +1704,22 @@ pub mod nightly_options {
16801704
if opt.stability == OptionStability::Stable {
16811705
continue
16821706
}
1683-
let opt_name = if opt.opt_group.long_name.is_empty() {
1684-
&opt.opt_group.short_name
1685-
} else {
1686-
&opt.opt_group.long_name
1687-
};
1688-
if !matches.opt_present(opt_name) {
1707+
if !matches.opt_present(opt.name) {
16891708
continue
16901709
}
1691-
if opt_name != "Z" && !has_z_unstable_option {
1710+
if opt.name != "Z" && !has_z_unstable_option {
16921711
early_error(ErrorOutputType::default(),
16931712
&format!("the `-Z unstable-options` flag must also be passed to enable \
16941713
the flag `{}`",
1695-
opt_name));
1714+
opt.name));
16961715
}
16971716
if really_allows_unstable_options {
16981717
continue
16991718
}
17001719
match opt.stability {
17011720
OptionStability::Unstable => {
17021721
let msg = format!("the option `{}` is only accepted on the \
1703-
nightly compiler", opt_name);
1722+
nightly compiler", opt.name);
17041723
early_error(ErrorOutputType::default(), &msg);
17051724
}
17061725
OptionStability::Stable => {}
@@ -1869,7 +1888,7 @@ mod dep_tracking {
18691888
mod tests {
18701889
use dep_graph::DepGraph;
18711890
use errors;
1872-
use getopts::{getopts, OptGroup};
1891+
use getopts;
18731892
use lint;
18741893
use middle::cstore::{self, DummyCrateStore};
18751894
use session::config::{build_configuration, build_session_options_and_crate_config};
@@ -1882,10 +1901,12 @@ mod tests {
18821901
use rustc_back::PanicStrategy;
18831902
use syntax::symbol::Symbol;
18841903

1885-
fn optgroups() -> Vec<OptGroup> {
1886-
super::rustc_optgroups().into_iter()
1887-
.map(|a| a.opt_group)
1888-
.collect()
1904+
fn optgroups() -> getopts::Options {
1905+
let mut opts = getopts::Options::new();
1906+
for group in super::rustc_optgroups() {
1907+
(group.apply)(&mut opts);
1908+
}
1909+
return opts
18891910
}
18901911

18911912
fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> {
@@ -1901,7 +1922,7 @@ mod tests {
19011922
fn test_switch_implies_cfg_test() {
19021923
let dep_graph = DepGraph::new(false);
19031924
let matches =
1904-
&match getopts(&["--test".to_string()], &optgroups()) {
1925+
&match optgroups().parse(&["--test".to_string()]) {
19051926
Ok(m) => m,
19061927
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
19071928
};
@@ -1918,8 +1939,7 @@ mod tests {
19181939
fn test_switch_implies_cfg_test_unless_cfg_test() {
19191940
let dep_graph = DepGraph::new(false);
19201941
let matches =
1921-
&match getopts(&["--test".to_string(), "--cfg=test".to_string()],
1922-
&optgroups()) {
1942+
&match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
19231943
Ok(m) => m,
19241944
Err(f) => {
19251945
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
@@ -1939,9 +1959,9 @@ mod tests {
19391959
fn test_can_print_warnings() {
19401960
let dep_graph = DepGraph::new(false);
19411961
{
1942-
let matches = getopts(&[
1962+
let matches = optgroups().parse(&[
19431963
"-Awarnings".to_string()
1944-
], &optgroups()).unwrap();
1964+
]).unwrap();
19451965
let registry = errors::registry::Registry::new(&[]);
19461966
let (sessopts, _) = build_session_options_and_crate_config(&matches);
19471967
let sess = build_session(sessopts, &dep_graph, None, registry,
@@ -1950,10 +1970,10 @@ mod tests {
19501970
}
19511971

19521972
{
1953-
let matches = getopts(&[
1973+
let matches = optgroups().parse(&[
19541974
"-Awarnings".to_string(),
19551975
"-Dwarnings".to_string()
1956-
], &optgroups()).unwrap();
1976+
]).unwrap();
19571977
let registry = errors::registry::Registry::new(&[]);
19581978
let (sessopts, _) = build_session_options_and_crate_config(&matches);
19591979
let sess = build_session(sessopts, &dep_graph, None, registry,
@@ -1962,9 +1982,9 @@ mod tests {
19621982
}
19631983

19641984
{
1965-
let matches = getopts(&[
1985+
let matches = optgroups().parse(&[
19661986
"-Adead_code".to_string()
1967-
], &optgroups()).unwrap();
1987+
]).unwrap();
19681988
let registry = errors::registry::Registry::new(&[]);
19691989
let (sessopts, _) = build_session_options_and_crate_config(&matches);
19701990
let sess = build_session(sessopts, &dep_graph, None, registry,

‎src/librustc_driver/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,10 @@ fn usage(verbose: bool, include_unstable_options: bool) {
725725
} else {
726726
config::rustc_short_optgroups()
727727
};
728-
let groups: Vec<_> = groups.into_iter()
729-
.filter(|x| include_unstable_options || x.is_stable())
730-
.map(|x| x.opt_group)
731-
.collect();
728+
let mut options = getopts::Options::new();
729+
for option in groups.iter().filter(|x| include_unstable_options || x.is_stable()) {
730+
(option.apply)(&mut options);
731+
}
732732
let message = format!("Usage: rustc [OPTIONS] INPUT");
733733
let extra_help = if verbose {
734734
""
@@ -741,7 +741,7 @@ fn usage(verbose: bool, include_unstable_options: bool) {
741741
Print 'lint' options and default settings
742742
-Z help Print internal \
743743
options for debugging rustc{}\n",
744-
getopts::usage(&message, &groups),
744+
options.usage(&message),
745745
extra_help);
746746
}
747747

@@ -955,11 +955,11 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
955955

956956
// Parse with *all* options defined in the compiler, we don't worry about
957957
// option stability here we just want to parse as much as possible.
958-
let all_groups: Vec<getopts::OptGroup> = config::rustc_optgroups()
959-
.into_iter()
960-
.map(|x| x.opt_group)
961-
.collect();
962-
let matches = match getopts::getopts(&args, &all_groups) {
958+
let mut options = getopts::Options::new();
959+
for option in config::rustc_optgroups() {
960+
(option.apply)(&mut options);
961+
}
962+
let matches = match options.parse(args) {
963963
Ok(m) => m,
964964
Err(f) => early_error(ErrorOutputType::default(), &f.to_string()),
965965
};

‎src/librustdoc/lib.rs

Lines changed: 133 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -116,94 +116,149 @@ fn get_args() -> Option<Vec<String>> {
116116
.collect()
117117
}
118118

119-
fn stable(g: getopts::OptGroup) -> RustcOptGroup { RustcOptGroup::stable(g) }
120-
fn unstable(g: getopts::OptGroup) -> RustcOptGroup { RustcOptGroup::unstable(g) }
119+
fn stable<F>(name: &'static str, f: F) -> RustcOptGroup
120+
where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static
121+
{
122+
RustcOptGroup::stable(name, f)
123+
}
124+
125+
fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup
126+
where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static
127+
{
128+
RustcOptGroup::unstable(name, f)
129+
}
121130

122131
pub fn opts() -> Vec<RustcOptGroup> {
123-
use getopts::*;
124132
vec![
125-
stable(optflag("h", "help", "show this help message")),
126-
stable(optflag("V", "version", "print rustdoc's version")),
127-
stable(optflag("v", "verbose", "use verbose output")),
128-
stable(optopt("r", "input-format", "the input type of the specified file",
129-
"[rust]")),
130-
stable(optopt("w", "output-format", "the output type to write",
131-
"[html]")),
132-
stable(optopt("o", "output", "where to place the output", "PATH")),
133-
stable(optopt("", "crate-name", "specify the name of this crate", "NAME")),
134-
stable(optmulti("L", "library-path", "directory to add to crate search path",
135-
"DIR")),
136-
stable(optmulti("", "cfg", "pass a --cfg to rustc", "")),
137-
stable(optmulti("", "extern", "pass an --extern to rustc", "NAME=PATH")),
138-
stable(optmulti("", "plugin-path", "directory to load plugins from", "DIR")),
139-
stable(optmulti("", "passes",
140-
"list of passes to also run, you might want \
141-
to pass it multiple times; a value of `list` \
142-
will print available passes",
143-
"PASSES")),
144-
stable(optmulti("", "plugins", "space separated list of plugins to also load",
145-
"PLUGINS")),
146-
stable(optflag("", "no-defaults", "don't run the default passes")),
147-
stable(optflag("", "test", "run code examples as tests")),
148-
stable(optmulti("", "test-args", "arguments to pass to the test runner",
149-
"ARGS")),
150-
stable(optopt("", "target", "target triple to document", "TRIPLE")),
151-
stable(optmulti("", "markdown-css",
152-
"CSS files to include via <link> in a rendered Markdown file",
153-
"FILES")),
154-
stable(optmulti("", "html-in-header",
155-
"files to include inline in the <head> section of a rendered Markdown file \
156-
or generated documentation",
157-
"FILES")),
158-
stable(optmulti("", "html-before-content",
159-
"files to include inline between <body> and the content of a rendered \
160-
Markdown file or generated documentation",
161-
"FILES")),
162-
stable(optmulti("", "html-after-content",
163-
"files to include inline between the content and </body> of a rendered \
164-
Markdown file or generated documentation",
165-
"FILES")),
166-
unstable(optmulti("", "markdown-before-content",
167-
"files to include inline between <body> and the content of a rendered \
168-
Markdown file or generated documentation",
169-
"FILES")),
170-
unstable(optmulti("", "markdown-after-content",
171-
"files to include inline between the content and </body> of a rendered \
172-
Markdown file or generated documentation",
173-
"FILES")),
174-
stable(optopt("", "markdown-playground-url",
175-
"URL to send code snippets to", "URL")),
176-
stable(optflag("", "markdown-no-toc", "don't include table of contents")),
177-
stable(optopt("e", "extend-css",
178-
"To add some CSS rules with a given file to generate doc with your \
179-
own theme. However, your theme might break if the rustdoc's generated HTML \
180-
changes, so be careful!", "PATH")),
181-
unstable(optmulti("Z", "",
182-
"internal and debugging options (only on nightly build)", "FLAG")),
183-
stable(optopt("", "sysroot", "Override the system root", "PATH")),
184-
unstable(optopt("", "playground-url",
185-
"URL to send code snippets to, may be reset by --markdown-playground-url \
186-
or `#![doc(html_playground_url=...)]`",
187-
"URL")),
188-
unstable(optflag("", "enable-commonmark", "to enable commonmark doc rendering/testing")),
189-
unstable(optflag("", "display-warnings", "to print code warnings when testing doc")),
133+
stable("h", |o| o.optflag("h", "help", "show this help message")),
134+
stable("V", |o| o.optflag("V", "version", "print rustdoc's version")),
135+
stable("v", |o| o.optflag("v", "verbose", "use verbose output")),
136+
stable("r", |o| {
137+
o.optopt("r", "input-format", "the input type of the specified file",
138+
"[rust]")
139+
}),
140+
stable("w", |o| {
141+
o.optopt("w", "output-format", "the output type to write", "[html]")
142+
}),
143+
stable("o", |o| o.optopt("o", "output", "where to place the output", "PATH")),
144+
stable("crate-name", |o| {
145+
o.optopt("", "crate-name", "specify the name of this crate", "NAME")
146+
}),
147+
stable("L", |o| {
148+
o.optmulti("L", "library-path", "directory to add to crate search path",
149+
"DIR")
150+
}),
151+
stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")),
152+
stable("extern", |o| {
153+
o.optmulti("", "extern", "pass an --extern to rustc", "NAME=PATH")
154+
}),
155+
stable("plugin-path", |o| {
156+
o.optmulti("", "plugin-path", "directory to load plugins from", "DIR")
157+
}),
158+
stable("passes", |o| {
159+
o.optmulti("", "passes",
160+
"list of passes to also run, you might want \
161+
to pass it multiple times; a value of `list` \
162+
will print available passes",
163+
"PASSES")
164+
}),
165+
stable("plugins", |o| {
166+
o.optmulti("", "plugins", "space separated list of plugins to also load",
167+
"PLUGINS")
168+
}),
169+
stable("no-default", |o| {
170+
o.optflag("", "no-defaults", "don't run the default passes")
171+
}),
172+
stable("test", |o| o.optflag("", "test", "run code examples as tests")),
173+
stable("test-args", |o| {
174+
o.optmulti("", "test-args", "arguments to pass to the test runner",
175+
"ARGS")
176+
}),
177+
stable("target", |o| o.optopt("", "target", "target triple to document", "TRIPLE")),
178+
stable("markdown-css", |o| {
179+
o.optmulti("", "markdown-css",
180+
"CSS files to include via <link> in a rendered Markdown file",
181+
"FILES")
182+
}),
183+
stable("html-in-header", |o| {
184+
o.optmulti("", "html-in-header",
185+
"files to include inline in the <head> section of a rendered Markdown file \
186+
or generated documentation",
187+
"FILES")
188+
}),
189+
stable("html-before-content", |o| {
190+
o.optmulti("", "html-before-content",
191+
"files to include inline between <body> and the content of a rendered \
192+
Markdown file or generated documentation",
193+
"FILES")
194+
}),
195+
stable("html-after-content", |o| {
196+
o.optmulti("", "html-after-content",
197+
"files to include inline between the content and </body> of a rendered \
198+
Markdown file or generated documentation",
199+
"FILES")
200+
}),
201+
unstable("markdown-before-content", |o| {
202+
o.optmulti("", "markdown-before-content",
203+
"files to include inline between <body> and the content of a rendered \
204+
Markdown file or generated documentation",
205+
"FILES")
206+
}),
207+
unstable("markdown-after-content", |o| {
208+
o.optmulti("", "markdown-after-content",
209+
"files to include inline between the content and </body> of a rendered \
210+
Markdown file or generated documentation",
211+
"FILES")
212+
}),
213+
stable("markdown-playground-url", |o| {
214+
o.optopt("", "markdown-playground-url",
215+
"URL to send code snippets to", "URL")
216+
}),
217+
stable("markdown-no-toc", |o| {
218+
o.optflag("", "markdown-no-toc", "don't include table of contents")
219+
}),
220+
stable("e", |o| {
221+
o.optopt("e", "extend-css",
222+
"To add some CSS rules with a given file to generate doc with your \
223+
own theme. However, your theme might break if the rustdoc's generated HTML \
224+
changes, so be careful!", "PATH")
225+
}),
226+
unstable("Z", |o| {
227+
o.optmulti("Z", "",
228+
"internal and debugging options (only on nightly build)", "FLAG")
229+
}),
230+
stable("sysroot", |o| {
231+
o.optopt("", "sysroot", "Override the system root", "PATH")
232+
}),
233+
unstable("playground-url", |o| {
234+
o.optopt("", "playground-url",
235+
"URL to send code snippets to, may be reset by --markdown-playground-url \
236+
or `#![doc(html_playground_url=...)]`",
237+
"URL")
238+
}),
239+
unstable("enable-commonmark", |o| {
240+
o.optflag("", "enable-commonmark", "to enable commonmark doc rendering/testing")
241+
}),
242+
unstable("display-warnings", |o| {
243+
o.optflag("", "display-warnings", "to print code warnings when testing doc")
244+
}),
190245
]
191246
}
192247

193248
pub fn usage(argv0: &str) {
194-
println!("{}",
195-
getopts::usage(&format!("{} [options] <input>", argv0),
196-
&opts().into_iter()
197-
.map(|x| x.opt_group)
198-
.collect::<Vec<getopts::OptGroup>>()));
249+
let mut options = getopts::Options::new();
250+
for option in opts() {
251+
(option.apply)(&mut options);
252+
}
253+
println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
199254
}
200255

201256
pub fn main_args(args: &[String]) -> isize {
202-
let all_groups: Vec<getopts::OptGroup> = opts()
203-
.into_iter()
204-
.map(|x| x.opt_group)
205-
.collect();
206-
let matches = match getopts::getopts(&args[1..], &all_groups) {
257+
let mut options = getopts::Options::new();
258+
for option in opts() {
259+
(option.apply)(&mut options);
260+
}
261+
let matches = match options.parse(&args[1..]) {
207262
Ok(m) => m,
208263
Err(err) => {
209264
print_error(err);

‎src/libtest/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ path = "lib.rs"
99
crate-type = ["dylib", "rlib"]
1010

1111
[dependencies]
12-
getopts = { path = "../libgetopts" }
12+
getopts = "0.2"
1313
term = { path = "../libterm" }

‎src/libtest/lib.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -372,30 +372,31 @@ impl TestOpts {
372372
/// Result of parsing the options.
373373
pub type OptRes = Result<TestOpts, String>;
374374

375-
#[cfg_attr(rustfmt, rustfmt_skip)]
376-
fn optgroups() -> Vec<getopts::OptGroup> {
377-
vec![getopts::optflag("", "ignored", "Run ignored tests"),
378-
getopts::optflag("", "test", "Run tests and not benchmarks"),
379-
getopts::optflag("", "bench", "Run benchmarks instead of tests"),
380-
getopts::optflag("", "list", "List all tests and benchmarks"),
381-
getopts::optflag("h", "help", "Display this message (longer with --help)"),
382-
getopts::optopt("", "logfile", "Write logs to the specified file instead \
383-
of stdout", "PATH"),
384-
getopts::optflag("", "nocapture", "don't capture stdout/stderr of each \
385-
task, allow printing directly"),
386-
getopts::optopt("", "test-threads", "Number of threads used for running tests \
387-
in parallel", "n_threads"),
388-
getopts::optmulti("", "skip", "Skip tests whose names contain FILTER (this flag can \
389-
be used multiple times)","FILTER"),
390-
getopts::optflag("q", "quiet", "Display one character per test instead of one line"),
391-
getopts::optflag("", "exact", "Exactly match filters rather than by substring"),
392-
getopts::optopt("", "color", "Configure coloring of output:
375+
fn optgroups() -> getopts::Options {
376+
let mut opts = getopts::Options::new();
377+
opts.optflag("", "ignored", "Run ignored tests")
378+
.optflag("", "test", "Run tests and not benchmarks")
379+
.optflag("", "bench", "Run benchmarks instead of tests")
380+
.optflag("", "list", "List all tests and benchmarks")
381+
.optflag("h", "help", "Display this message (longer with --help)")
382+
.optopt("", "logfile", "Write logs to the specified file instead \
383+
of stdout", "PATH")
384+
.optflag("", "nocapture", "don't capture stdout/stderr of each \
385+
task, allow printing directly")
386+
.optopt("", "test-threads", "Number of threads used for running tests \
387+
in parallel", "n_threads")
388+
.optmulti("", "skip", "Skip tests whose names contain FILTER (this flag can \
389+
be used multiple times)","FILTER")
390+
.optflag("q", "quiet", "Display one character per test instead of one line")
391+
.optflag("", "exact", "Exactly match filters rather than by substring")
392+
.optopt("", "color", "Configure coloring of output:
393393
auto = colorize if stdout is a tty and tests are run on serially (default);
394394
always = always colorize output;
395-
never = never colorize output;", "auto|always|never")]
395+
never = never colorize output;", "auto|always|never");
396+
return opts
396397
}
397398

398-
fn usage(binary: &str) {
399+
fn usage(binary: &str, options: &getopts::Options) {
399400
let message = format!("Usage: {} [OPTIONS] [FILTER]", binary);
400401
println!(r#"{usage}
401402
@@ -424,19 +425,19 @@ Test Attributes:
424425
test, then the test runner will ignore these tests during
425426
normal test runs. Running with --ignored will run these
426427
tests."#,
427-
usage = getopts::usage(&message, &optgroups()));
428+
usage = options.usage(&message));
428429
}
429430

430431
// Parses command line arguments into test options
431432
pub fn parse_opts(args: &[String]) -> Option<OptRes> {
432-
let args_ = &args[1..];
433-
let matches = match getopts::getopts(args_, &optgroups()) {
433+
let opts = optgroups();
434+
let matches = match opts.parse(&args[1..]) {
434435
Ok(m) => m,
435436
Err(f) => return Some(Err(f.to_string())),
436437
};
437438

438439
if matches.opt_present("h") {
439-
usage(&args[0]);
440+
usage(&args[0], &opts);
440441
return None;
441442
}
442443

‎src/test/run-pass/auxiliary/allocator-dummy.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,48 @@
1010

1111
// no-prefer-dynamic
1212

13-
#![feature(allocator, core_intrinsics, libc)]
13+
#![feature(allocator, core_intrinsics)]
1414
#![allocator]
1515
#![crate_type = "rlib"]
1616
#![no_std]
1717

18-
extern crate libc;
19-
2018
pub static mut HITS: usize = 0;
2119

20+
type size_t = usize;
21+
22+
extern {
23+
fn malloc(size: usize) -> *mut u8;
24+
fn free(ptr: *mut u8);
25+
fn calloc(size: usize, amt: usize) -> *mut u8;
26+
fn realloc(ptr: *mut u8, size: usize) -> *mut u8;
27+
}
28+
2229
#[no_mangle]
2330
pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
2431
unsafe {
2532
HITS += 1;
26-
libc::malloc(size as libc::size_t) as *mut u8
33+
malloc(size as size_t) as *mut u8
2734
}
2835
}
2936

3037
#[no_mangle]
3138
pub extern fn __rust_allocate_zeroed(size: usize, _align: usize) -> *mut u8 {
32-
unsafe { libc::calloc(size as libc::size_t, 1) as *mut u8 }
39+
unsafe { calloc(size as size_t, 1) as *mut u8 }
3340
}
3441

3542
#[no_mangle]
3643
pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
3744
unsafe {
3845
HITS += 1;
39-
libc::free(ptr as *mut _)
46+
free(ptr as *mut _)
4047
}
4148
}
4249

4350
#[no_mangle]
4451
pub extern fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize,
4552
align: usize) -> *mut u8 {
4653
unsafe {
47-
libc::realloc(ptr as *mut _, size as libc::size_t) as *mut u8
54+
realloc(ptr as *mut _, size as size_t) as *mut u8
4855
}
4956
}
5057

‎src/test/run-pass/getopts_ref.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎src/test/run-pass/smallest-hello-world.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// Smallest "hello world" with a libc runtime
1212

1313
// pretty-expanded FIXME #23616
14+
// ignore-windows
1415

1516
#![feature(intrinsics, lang_items, start, no_core, alloc_system)]
1617
#![no_core]

‎src/tools/compiletest/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ name = "compiletest"
44
version = "0.0.0"
55

66
[dependencies]
7-
log = "0.3"
7+
diff = "0.1.10"
88
env_logger = { version = "0.4", default-features = false }
9-
rustc-serialize = "0.3"
109
filetime = "0.1"
11-
diff = "0.1.10"
10+
getopts = "0.2"
11+
log = "0.3"
12+
rustc-serialize = "0.3"

‎src/tools/compiletest/src/main.rs

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![crate_name = "compiletest"]
1212

1313
#![feature(box_syntax)]
14-
#![feature(rustc_private)]
1514
#![feature(test)]
1615
#![feature(libc)]
1716

@@ -34,7 +33,7 @@ use std::io;
3433
use std::path::{Path, PathBuf};
3534
use std::process::Command;
3635
use filetime::FileTime;
37-
use getopts::{optopt, optflag, reqopt};
36+
use getopts::Options;
3837
use common::Config;
3938
use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Mode};
4039
use test::{TestPaths, ColorConfig};
@@ -66,68 +65,68 @@ fn main() {
6665

6766
pub fn parse_config(args: Vec<String> ) -> Config {
6867

69-
let groups : Vec<getopts::OptGroup> =
70-
vec![reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"),
71-
reqopt("", "run-lib-path", "path to target shared libraries", "PATH"),
72-
reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH"),
73-
reqopt("", "rustdoc-path", "path to rustdoc to use for compiling", "PATH"),
74-
reqopt("", "lldb-python", "path to python to use for doc tests", "PATH"),
75-
reqopt("", "docck-python", "path to python to use for doc tests", "PATH"),
76-
optopt("", "valgrind-path", "path to Valgrind executable for Valgrind tests", "PROGRAM"),
77-
optflag("", "force-valgrind", "fail if Valgrind tests cannot be run under Valgrind"),
78-
optopt("", "llvm-filecheck", "path to LLVM's FileCheck binary", "DIR"),
79-
reqopt("", "src-base", "directory to scan for test files", "PATH"),
80-
reqopt("", "build-base", "directory to deposit test outputs", "PATH"),
81-
reqopt("", "stage-id", "the target-stage identifier", "stageN-TARGET"),
82-
reqopt("", "mode", "which sort of compile tests to run",
83-
"(compile-fail|parse-fail|run-fail|run-pass|\
84-
run-pass-valgrind|pretty|debug-info|incremental|mir-opt)"),
85-
optflag("", "ignored", "run tests marked as ignored"),
86-
optflag("", "exact", "filters match exactly"),
87-
optopt("", "runtool", "supervisor program to run tests under \
88-
(eg. emulator, valgrind)", "PROGRAM"),
89-
optopt("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS"),
90-
optopt("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS"),
91-
optflag("", "verbose", "run tests verbosely, showing all output"),
92-
optflag("", "quiet", "print one character per test instead of one line"),
93-
optopt("", "color", "coloring: auto, always, never", "WHEN"),
94-
optopt("", "logfile", "file to log test execution to", "FILE"),
95-
optopt("", "target", "the target to build for", "TARGET"),
96-
optopt("", "host", "the host to build for", "HOST"),
97-
optopt("", "gdb", "path to GDB to use for GDB debuginfo tests", "PATH"),
98-
optopt("", "lldb-version", "the version of LLDB used", "VERSION STRING"),
99-
optopt("", "llvm-version", "the version of LLVM used", "VERSION STRING"),
100-
optflag("", "system-llvm", "is LLVM the system LLVM"),
101-
optopt("", "android-cross-path", "Android NDK standalone path", "PATH"),
102-
optopt("", "adb-path", "path to the android debugger", "PATH"),
103-
optopt("", "adb-test-dir", "path to tests for the android debugger", "PATH"),
104-
optopt("", "lldb-python-dir", "directory containing LLDB's python module", "PATH"),
105-
reqopt("", "cc", "path to a C compiler", "PATH"),
106-
reqopt("", "cxx", "path to a C++ compiler", "PATH"),
107-
reqopt("", "cflags", "flags for the C compiler", "FLAGS"),
108-
reqopt("", "llvm-components", "list of LLVM components built in", "LIST"),
109-
reqopt("", "llvm-cxxflags", "C++ flags for LLVM", "FLAGS"),
110-
optopt("", "nodejs", "the name of nodejs", "PATH"),
111-
optopt("", "remote-test-client", "path to the remote test client", "PATH"),
112-
optflag("h", "help", "show this message")];
68+
let mut opts = Options::new();
69+
opts.reqopt("", "compile-lib-path", "path to host shared libraries", "PATH")
70+
.reqopt("", "run-lib-path", "path to target shared libraries", "PATH")
71+
.reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH")
72+
.reqopt("", "rustdoc-path", "path to rustdoc to use for compiling", "PATH")
73+
.reqopt("", "lldb-python", "path to python to use for doc tests", "PATH")
74+
.reqopt("", "docck-python", "path to python to use for doc tests", "PATH")
75+
.optopt("", "valgrind-path", "path to Valgrind executable for Valgrind tests", "PROGRAM")
76+
.optflag("", "force-valgrind", "fail if Valgrind tests cannot be run under Valgrind")
77+
.optopt("", "llvm-filecheck", "path to LLVM's FileCheck binary", "DIR")
78+
.reqopt("", "src-base", "directory to scan for test files", "PATH")
79+
.reqopt("", "build-base", "directory to deposit test outputs", "PATH")
80+
.reqopt("", "stage-id", "the target-stage identifier", "stageN-TARGET")
81+
.reqopt("", "mode", "which sort of compile tests to run",
82+
"(compile-fail|parse-fail|run-fail|run-pass|\
83+
run-pass-valgrind|pretty|debug-info|incremental|mir-opt)")
84+
.optflag("", "ignored", "run tests marked as ignored")
85+
.optflag("", "exact", "filters match exactly")
86+
.optopt("", "runtool", "supervisor program to run tests under \
87+
(eg. emulator, valgrind)", "PROGRAM")
88+
.optopt("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
89+
.optopt("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
90+
.optflag("", "verbose", "run tests verbosely, showing all output")
91+
.optflag("", "quiet", "print one character per test instead of one line")
92+
.optopt("", "color", "coloring: auto, always, never", "WHEN")
93+
.optopt("", "logfile", "file to log test execution to", "FILE")
94+
.optopt("", "target", "the target to build for", "TARGET")
95+
.optopt("", "host", "the host to build for", "HOST")
96+
.optopt("", "gdb", "path to GDB to use for GDB debuginfo tests", "PATH")
97+
.optopt("", "lldb-version", "the version of LLDB used", "VERSION STRING")
98+
.optopt("", "llvm-version", "the version of LLVM used", "VERSION STRING")
99+
.optflag("", "system-llvm", "is LLVM the system LLVM")
100+
.optopt("", "android-cross-path", "Android NDK standalone path", "PATH")
101+
.optopt("", "adb-path", "path to the android debugger", "PATH")
102+
.optopt("", "adb-test-dir", "path to tests for the android debugger", "PATH")
103+
.optopt("", "lldb-python-dir", "directory containing LLDB's python module", "PATH")
104+
.reqopt("", "cc", "path to a C compiler", "PATH")
105+
.reqopt("", "cxx", "path to a C++ compiler", "PATH")
106+
.reqopt("", "cflags", "flags for the C compiler", "FLAGS")
107+
.reqopt("", "llvm-components", "list of LLVM components built in", "LIST")
108+
.reqopt("", "llvm-cxxflags", "C++ flags for LLVM", "FLAGS")
109+
.optopt("", "nodejs", "the name of nodejs", "PATH")
110+
.optopt("", "remote-test-client", "path to the remote test client", "PATH")
111+
.optflag("h", "help", "show this message");
113112

114113
let (argv0, args_) = args.split_first().unwrap();
115114
if args.len() == 1 || args[1] == "-h" || args[1] == "--help" {
116115
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
117-
println!("{}", getopts::usage(&message, &groups));
116+
println!("{}", opts.usage(&message));
118117
println!("");
119118
panic!()
120119
}
121120

122121
let matches =
123-
&match getopts::getopts(args_, &groups) {
122+
&match opts.parse(args_) {
124123
Ok(m) => m,
125124
Err(f) => panic!("{:?}", f)
126125
};
127126

128127
if matches.opt_present("h") || matches.opt_present("help") {
129128
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
130-
println!("{}", getopts::usage(&message, &groups));
129+
println!("{}", opts.usage(&message));
131130
println!("");
132131
panic!()
133132
}

0 commit comments

Comments
 (0)
Please sign in to comment.