Skip to content

Commit efdc266

Browse files
committed
--all-features launch argument
Fix #48
1 parent eb03755 commit efdc266

File tree

8 files changed

+64
-40
lines changed

8 files changed

+64
-40
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bacon"
3-
version = "1.1.5"
3+
version = "1.1.6-dev"
44
authors = ["dystroy <[email protected]>"]
55
repository = "https://github.com/Canop/bacon"
66
description = "background rust compiler"

src/args.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ pub struct Args {
5353
#[argh(switch)]
5454
pub no_default_features: bool,
5555

56+
/// activate all available features
57+
#[argh(switch)]
58+
pub all_features: bool,
59+
5660
/// comma separated list of features to ask cargo to compile with
5761
/// (if the job defines some, they're merged)
5862
#[argh(option)]
@@ -91,7 +95,7 @@ impl Args {
9195
}
9296
}
9397
(Some(_), Some(_), _, _) => {
94-
return Err(anyhow!("Too many arguments"));
98+
bail!("Too many arguments");
9599
}
96100
(Some(a), None, true, false) => {
97101
self.job = Some(a);
@@ -100,7 +104,7 @@ impl Args {
100104
self.path = Some(a);
101105
}
102106
(Some(a), None, false, false) => {
103-
return Err(anyhow!("Unexpected argument {:?}", a));
107+
bail!("Unexpected argument {:?}", a);
104108
}
105109
_ => {}
106110
}

src/executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ impl Executor {
156156
}
157157
});
158158
Ok(Self {
159+
line_receiver,
159160
task_sender,
160161
stop_sender,
161-
line_receiver,
162162
thread,
163163
})
164164
}

src/mission.rs

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ impl MissionLocation {
3838
package_directory = match package_directory.parent() {
3939
Some(dir) => dir.to_path_buf(),
4040
None => {
41-
return Err(anyhow!(
41+
bail!(
4242
"Cargo.toml file not found.\n\
4343
bacon must be launched \n\
4444
* in a rust project directory\n\
4545
* or with a rust project directory given in argument\n\
4646
(a rust project directory contains a Cargo.toml file or has such parent)\n\
4747
"
48-
));
48+
);
4949
}
5050
};
5151
};
@@ -88,6 +88,7 @@ impl Mission {
8888
job_name: Option<&str>,
8989
settings: Settings,
9090
) -> Result<Self> {
91+
let package_name = location.package_name();
9192
let add_all_src = location.intended_is_package;
9293
let (job_name, job) = package_config
9394
.get_job(job_name)
@@ -126,12 +127,11 @@ impl Mission {
126127
}
127128
}
128129

129-
let cargo_execution_directory = location.package_directory.to_path_buf();
130-
let package_name = location.package_name();
130+
let cargo_execution_directory = location.package_directory;
131131
Ok(Mission {
132132
package_name,
133-
cargo_execution_directory,
134133
job_name,
134+
cargo_execution_directory,
135135
job,
136136
files_to_watch,
137137
directories_to_watch,
@@ -162,43 +162,58 @@ impl Mission {
162162
let mut features_done = false;
163163
let mut last_is_features = false;
164164
for arg in tokens {
165-
let mut arg = arg.to_string();
166165
if last_is_features {
167-
// arg is expected there to be the list of features
168-
features_done = true;
169-
match (&self.settings.features, self.settings.no_default_features) {
170-
(Some(features), false) => {
171-
// we take the features of both the job and the args
172-
arg = merge_features(&arg, &features);
173-
}
174-
(Some(features), true) => {
175-
// arg add features and remove the job ones
176-
arg = features.clone();
177-
}
178-
(None, true) => {
179-
// arg just remove the job features
180-
arg = "".to_string()
181-
}
182-
(None, false) => {
183-
// nothing to change
166+
if self.settings.all_features {
167+
debug!("ignoring features given along --all-features");
168+
} else {
169+
features_done = true;
170+
// arg is expected there to be the list of features
171+
match (&self.settings.features, self.settings.no_default_features) {
172+
(Some(features), false) => {
173+
// we take the features of both the job and the args
174+
command.arg("--features");
175+
command.arg(merge_features(arg, &features));
176+
}
177+
(Some(features), true) => {
178+
// arg add features and remove the job ones
179+
command.arg("--features");
180+
command.arg(&features);
181+
}
182+
(None, true) => {
183+
// we pass no feature
184+
}
185+
(None, false) => {
186+
// nothing to change
187+
command.arg("--features");
188+
command.arg(arg);
189+
}
184190
}
185191
}
186192
last_is_features = false;
187193
} else if arg == "--no-default-features" {
188194
no_default_features_done = true;
189195
last_is_features = false;
196+
command.arg(arg);
190197
} else if arg == "--features" {
191198
last_is_features = true;
199+
} else {
200+
command.arg(arg);
192201
}
193-
command.arg(arg);
194202
}
195203
if self.settings.no_default_features && !no_default_features_done {
196204
command.arg("--no-default-features");
197205
}
206+
if self.settings.all_features {
207+
command.arg("--all-features");
208+
}
198209
if !features_done {
199210
if let Some(features) = &self.settings.features {
200-
command.arg("--features");
201-
command.arg(features);
211+
if self.settings.all_features {
212+
debug!("not using features because of --all-features");
213+
} else {
214+
command.arg("--features");
215+
command.arg(features);
216+
}
202217
}
203218
}
204219
command.current_dir(&self.cargo_execution_directory);
@@ -220,5 +235,5 @@ fn merge_features(a: &str, b: &str) -> String {
220235
for feature in b.split(',') {
221236
features.insert(feature);
222237
}
223-
features.iter().map(|&s|s).collect::<Vec<&str>>().join(",")
238+
features.iter().copied().collect::<Vec<&str>>().join(",")
224239
}

src/package_config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@ impl PackageConfig {
2424
pub fn from_path(path: &Path) -> Result<Self> {
2525
let conf = toml::from_str::<PackageConfig>(&fs::read_to_string(path)?)?;
2626
if conf.jobs.is_empty() {
27-
return Err(anyhow!("Invalid bacon.toml : no job found"));
27+
bail!("Invalid bacon.toml : no job found");
2828
}
2929
for (name, job) in &conf.jobs {
3030
if name.is_empty() || name.contains('.') || name.contains('/') {
31-
return Err(anyhow!(
31+
bail!(
3232
"Invalid bacon.toml : Illegal job name : {:?}",
3333
name
34-
));
34+
);
3535
}
3636
if job.command.is_empty() {
37-
return Err(anyhow!(
37+
bail!(
3838
"Invalid bacon.toml : empty command for job {:?}",
3939
name
40-
));
40+
);
4141
}
4242
}
4343
if !conf.jobs.contains_key(&conf.default_job) {
44-
return Err(anyhow!(
44+
bail!(
4545
"Invalid bacon.toml : default job not found in jobs"
46-
));
46+
);
4747
}
4848
Ok(conf)
4949
}

src/report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ impl Report {
125125
// have been read but not added (at start or end)
126126
let mut stats = Stats::from(&lines);
127127
stats.passed_tests = passed_tests;
128-
Ok(Report { stats, lines })
128+
Ok(Report { lines, stats })
129129
}
130130
}

src/settings.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub struct Settings {
77
pub reverse: bool,
88
pub vim_keys: bool,
99
pub no_default_features: bool,
10+
pub all_features: bool,
1011
pub features: Option<String>, // comma separated list
1112
}
1213

@@ -47,6 +48,9 @@ impl Settings {
4748
if args.no_default_features {
4849
self.no_default_features = true;
4950
}
51+
if args.all_features {
52+
self.all_features = true;
53+
}
5054
if args.features.is_some() {
5155
self.features = args.features.clone();
5256
}
@@ -61,6 +65,7 @@ impl Default for Settings {
6165
reverse: false,
6266
vim_keys: false,
6367
no_default_features: false,
68+
all_features: false,
6469
features: None,
6570
}
6671
}

0 commit comments

Comments
 (0)