Skip to content

Commit 8c506f9

Browse files
Implement excluding a build-step via --exclude
1 parent 45fba43 commit 8c506f9

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/bootstrap/builder.rs

+26-5
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,28 @@ impl StepDescription {
119119
}
120120
}
121121

122-
fn maybe_run(&self, builder: &Builder, path: Option<&Path>) {
122+
fn maybe_run(&self, builder: &Builder, should_run: &ShouldRun, path: Option<&Path>) {
123+
if let Some(path) = path {
124+
if builder.config.exclude.iter().any(|e| e == path) {
125+
eprintln!("Skipping {:?} because this path is excluded", path);
126+
return;
127+
} else if !builder.config.exclude.is_empty() {
128+
eprintln!("{:?} not skipped -- not in {:?}", path, builder.config.exclude);
129+
}
130+
} else {
131+
if !should_run.paths.is_empty() {
132+
if should_run.paths.iter().all(|p| builder.config.exclude.contains(&p)) {
133+
eprintln!("Skipping because all of its paths ({:?}) are excluded",
134+
should_run.paths);
135+
return;
136+
} else if should_run.paths.len() > 1 {
137+
for path in &should_run.paths {
138+
self.maybe_run(builder, should_run, Some(path));
139+
}
140+
return;
141+
}
142+
}
143+
}
123144
let build = builder.build;
124145
let hosts = if self.only_build_targets || self.only_build {
125146
build.build_triple()
@@ -160,7 +181,7 @@ impl StepDescription {
160181
if paths.is_empty() {
161182
for (desc, should_run) in v.iter().zip(should_runs) {
162183
if desc.default && should_run.is_really_default {
163-
desc.maybe_run(builder, None);
184+
desc.maybe_run(builder, &should_run, None);
164185
}
165186
}
166187
} else {
@@ -169,7 +190,7 @@ impl StepDescription {
169190
for (desc, should_run) in v.iter().zip(&should_runs) {
170191
if should_run.run(path) {
171192
attempted_run = true;
172-
desc.maybe_run(builder, Some(path));
193+
desc.maybe_run(builder, &should_run, Some(path));
173194
}
174195
}
175196

@@ -208,13 +229,13 @@ impl<'a> ShouldRun<'a> {
208229

209230
pub fn krate(mut self, name: &str) -> Self {
210231
for (_, krate_path) in self.builder.crates(name) {
211-
self.paths.insert(PathBuf::from(krate_path));
232+
self.paths.insert(t!(env::current_dir()).join(krate_path));
212233
}
213234
self
214235
}
215236

216237
pub fn path(mut self, path: &str) -> Self {
217-
self.paths.insert(PathBuf::from(path));
238+
self.paths.insert(t!(env::current_dir()).join(path));
218239
self
219240
}
220241

src/bootstrap/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct Config {
5656
pub sanitizers: bool,
5757
pub profiler: bool,
5858
pub ignore_git: bool,
59+
pub exclude: Vec<PathBuf>,
5960

6061
pub run_host_only: bool,
6162

@@ -311,6 +312,7 @@ impl Config {
311312
let flags = Flags::parse(&args);
312313
let file = flags.config.clone();
313314
let mut config = Config::default();
315+
config.exclude = flags.exclude;
314316
config.llvm_enabled = true;
315317
config.llvm_optimize = true;
316318
config.llvm_version_check = true;

src/bootstrap/flags.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct Flags {
4242
pub jobs: Option<u32>,
4343
pub cmd: Subcommand,
4444
pub incremental: bool,
45+
pub exclude: Vec<PathBuf>,
4546
}
4647

4748
pub enum Subcommand {
@@ -109,6 +110,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
109110
opts.optopt("", "build", "build target of the stage0 compiler", "BUILD");
110111
opts.optmulti("", "host", "host targets to build", "HOST");
111112
opts.optmulti("", "target", "target targets to build", "TARGET");
113+
opts.optmulti("", "exclude", "build paths to exclude", "PATH");
112114
opts.optopt("", "on-fail", "command to run on failure", "CMD");
113115
opts.optopt("", "stage", "stage to build", "N");
114116
opts.optopt("", "keep-stage", "stage to keep without recompiling", "N");
@@ -358,10 +360,9 @@ Arguments:
358360
stage = Some(1);
359361
}
360362

361-
let cwd = t!(env::current_dir());
362363
let src = matches.opt_str("src").map(PathBuf::from)
363364
.or_else(|| env::var_os("SRC").map(PathBuf::from))
364-
.unwrap_or(cwd);
365+
.unwrap_or(cwd.clone());
365366

366367
Flags {
367368
verbose: matches.opt_count("verbose"),
@@ -378,6 +379,8 @@ Arguments:
378379
jobs: matches.opt_str("jobs").map(|j| j.parse().unwrap()),
379380
cmd,
380381
incremental: matches.opt_present("incremental"),
382+
exclude: split(matches.opt_strs("exclude"))
383+
.into_iter().map(|p| cwd.join(p)).collect::<Vec<_>>(),
381384
}
382385
}
383386
}

0 commit comments

Comments
 (0)