Skip to content

Commit af3e4d8

Browse files
dubiousjimlu-zero
authored andcommitted
use Kind::Arbitrary instead of new config_options Vec
1 parent a3f3033 commit af3e4d8

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

src/lib.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ enum Kind {
5252
Disable,
5353
With,
5454
Without,
55+
Arbitrary,
5556
}
5657

5758
/// Builder style configuration for a pending autotools build.
@@ -63,7 +64,6 @@ pub struct Config {
6364
cxxflags: OsString,
6465
ldflags: OsString,
6566
options: Vec<(Kind, OsString, Option<OsString>)>,
66-
config_options: Vec<(OsString, Option<OsString>)>,
6767
target: Option<String>,
6868
make_args: Option<Vec<String>>,
6969
make_targets: Option<Vec<String>>,
@@ -108,7 +108,6 @@ impl Config {
108108
cxxflags: OsString::new(),
109109
ldflags: OsString::new(),
110110
options: Vec::new(),
111-
config_options: Vec::new(),
112111
make_args: None,
113112
make_targets: None,
114113
out_dir: None,
@@ -159,10 +158,7 @@ impl Config {
159158

160159
/// Passes `--<opt><=optarg>` to configure.
161160
pub fn config_option<P: AsRef<OsStr>>(&mut self, opt: P, optarg: Option<P>) -> &mut Config {
162-
let optarg = optarg.as_ref().map(|v| v.as_ref().to_owned());
163-
self.config_options.push((opt.as_ref().to_owned(),
164-
optarg));
165-
self
161+
self.set_opt(Kind::Arbitrary, opt, optarg)
166162
}
167163

168164
/// Passes `--enable-<opt><=optarg>` to configure.
@@ -377,30 +373,21 @@ impl Config {
377373
};
378374
}
379375

376+
let mut config_host = false;
377+
380378
for &(ref kind, ref k, ref v) in &self.options {
381379
let mut os = OsString::from("--");
382380
match *kind {
383-
Kind::Enable => os.push("enable"),
384-
Kind::Disable => os.push("disable"),
385-
Kind::With => os.push("with"),
386-
Kind::Without => os.push("without")
381+
Kind::Enable => os.push("enable-"),
382+
Kind::Disable => os.push("disable-"),
383+
Kind::With => os.push("with-"),
384+
Kind::Without => os.push("without-"),
385+
Kind::Arbitrary => {
386+
if k == "host" {
387+
config_host = true;
388+
}
389+
}
387390
};
388-
os.push("-");
389-
os.push(k);
390-
if let &Some(ref v) = v {
391-
os.push("=");
392-
os.push(v);
393-
}
394-
cmd.arg(os);
395-
}
396-
397-
let mut config_host = false;
398-
399-
for &(ref k, ref v) in &self.config_options {
400-
let mut os = OsString::from("--");
401-
if k == "host" {
402-
config_host = true;
403-
}
404391
os.push(k);
405392
if let &Some(ref v) = v {
406393
os.push("=");

0 commit comments

Comments
 (0)