Skip to content

Commit bc91927

Browse files
committed
Auto merge of #31591 - alexcrichton:make-clean-with-rustbuild, r=brson
At the same time also touch up the job management on Windows to be a little more resilient to failure.
2 parents 4b72450 + 07638b9 commit bc91927

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

src/bootstrap/build/clean.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2016 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.
4+
//
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.
10+
11+
use std::fs;
12+
use std::path::Path;
13+
14+
use build::Build;
15+
16+
pub fn clean(build: &Build) {
17+
for host in build.config.host.iter() {
18+
19+
let out = build.out.join(host);
20+
21+
rm_rf(build, &out.join("compiler-rt"));
22+
23+
for stage in 0..4 {
24+
rm_rf(build, &out.join(format!("stage{}", stage)));
25+
rm_rf(build, &out.join(format!("stage{}-std", stage)));
26+
rm_rf(build, &out.join(format!("stage{}-rustc", stage)));
27+
}
28+
}
29+
}
30+
31+
fn rm_rf(build: &Build, path: &Path) {
32+
if path.exists() {
33+
build.verbose(&format!("removing `{}`", path.display()));
34+
t!(fs::remove_dir_all(path));
35+
}
36+
}

src/bootstrap/build/flags.rs

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct Flags {
2626
pub src: Option<PathBuf>,
2727
pub jobs: Option<u32>,
2828
pub args: Vec<String>,
29+
pub clean: bool,
2930
}
3031

3132
pub struct Filter {
@@ -44,6 +45,7 @@ impl Flags {
4445
opts.optopt("", "stage", "stage to build", "N");
4546
opts.optopt("", "src", "path to repo root", "DIR");
4647
opts.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS");
48+
opts.optflag("", "clean", "clean output directory");
4749
opts.optflag("h", "help", "print this help message");
4850

4951
let usage = |n| -> ! {
@@ -75,6 +77,7 @@ impl Flags {
7577

7678
Flags {
7779
verbose: m.opt_present("v"),
80+
clean: m.opt_present("clean"),
7881
stage: m.opt_str("stage").map(|j| j.parse().unwrap()),
7982
build: m.opt_str("build").unwrap(),
8083
host: Filter { values: m.opt_strs("host") },

src/bootstrap/build/job.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,20 @@ pub unsafe fn setup() {
6464
mem::size_of_val(&info) as DWORD);
6565
assert!(r != 0, "{}", io::Error::last_os_error());
6666

67-
// Assign our process to this job object
67+
// Assign our process to this job object. Note that if this fails, one very
68+
// likely reason is that we are ourselves already in a job object! This can
69+
// happen on the build bots that we've got for Windows, or if just anyone
70+
// else is instrumenting the build. In this case we just bail out
71+
// immediately and assume that they take care of it.
72+
//
73+
// Also note that nested jobs (why this might fail) are supported in recent
74+
// versions of Windows, but the version of Windows that our bots are running
75+
// at least don't support nested job objects.
6876
let r = AssignProcessToJobObject(job, GetCurrentProcess());
69-
assert!(r != 0, "{}", io::Error::last_os_error());
77+
if r == 0 {
78+
CloseHandle(job);
79+
return
80+
}
7081

7182
// If we've got a parent process (e.g. the python script that called us)
7283
// then move ownership of this job object up to them. That way if the python

src/bootstrap/build/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ macro_rules! t {
3030

3131
mod cc;
3232
mod channel;
33+
mod clean;
3334
mod compile;
3435
mod config;
3536
mod flags;
@@ -122,6 +123,10 @@ impl Build {
122123
#[cfg(not(windows))] fn setup_job() {}
123124
setup_job();
124125

126+
if self.flags.clean {
127+
return clean::clean(self);
128+
}
129+
125130
cc::find(self);
126131
sanity::check(self);
127132
channel::collect(self);

src/bootstrap/mk/Makefile.in

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ BOOTSTRAP := $(CFG_PYTHON) $(CFG_SRC_DIR)src/bootstrap/bootstrap.py $(BOOTSTRAP_
2121

2222
all:
2323
$(Q)$(BOOTSTRAP)
24+
25+
clean:
26+
$(Q)$(BOOTSTRAP) --clean

0 commit comments

Comments
 (0)