File tree 5 files changed +60
-2
lines changed
5 files changed +60
-2
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ pub struct Flags {
26
26
pub src : Option < PathBuf > ,
27
27
pub jobs : Option < u32 > ,
28
28
pub args : Vec < String > ,
29
+ pub clean : bool ,
29
30
}
30
31
31
32
pub struct Filter {
@@ -44,6 +45,7 @@ impl Flags {
44
45
opts. optopt ( "" , "stage" , "stage to build" , "N" ) ;
45
46
opts. optopt ( "" , "src" , "path to repo root" , "DIR" ) ;
46
47
opts. optopt ( "j" , "jobs" , "number of jobs to run in parallel" , "JOBS" ) ;
48
+ opts. optflag ( "" , "clean" , "clean output directory" ) ;
47
49
opts. optflag ( "h" , "help" , "print this help message" ) ;
48
50
49
51
let usage = |n| -> ! {
@@ -75,6 +77,7 @@ impl Flags {
75
77
76
78
Flags {
77
79
verbose : m. opt_present ( "v" ) ,
80
+ clean : m. opt_present ( "clean" ) ,
78
81
stage : m. opt_str ( "stage" ) . map ( |j| j. parse ( ) . unwrap ( ) ) ,
79
82
build : m. opt_str ( "build" ) . unwrap ( ) ,
80
83
host : Filter { values : m. opt_strs ( "host" ) } ,
Original file line number Diff line number Diff line change @@ -64,9 +64,20 @@ pub unsafe fn setup() {
64
64
mem:: size_of_val ( & info) as DWORD ) ;
65
65
assert ! ( r != 0 , "{}" , io:: Error :: last_os_error( ) ) ;
66
66
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.
68
76
let r = AssignProcessToJobObject ( job, GetCurrentProcess ( ) ) ;
69
- assert ! ( r != 0 , "{}" , io:: Error :: last_os_error( ) ) ;
77
+ if r == 0 {
78
+ CloseHandle ( job) ;
79
+ return
80
+ }
70
81
71
82
// If we've got a parent process (e.g. the python script that called us)
72
83
// then move ownership of this job object up to them. That way if the python
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ macro_rules! t {
30
30
31
31
mod cc;
32
32
mod channel;
33
+ mod clean;
33
34
mod compile;
34
35
mod config;
35
36
mod flags;
@@ -122,6 +123,10 @@ impl Build {
122
123
#[ cfg( not( windows) ) ] fn setup_job ( ) { }
123
124
setup_job ( ) ;
124
125
126
+ if self . flags . clean {
127
+ return clean:: clean ( self ) ;
128
+ }
129
+
125
130
cc:: find ( self ) ;
126
131
sanity:: check ( self ) ;
127
132
channel:: collect ( self ) ;
Original file line number Diff line number Diff line change @@ -21,3 +21,6 @@ BOOTSTRAP := $(CFG_PYTHON) $(CFG_SRC_DIR)src/bootstrap/bootstrap.py $(BOOTSTRAP_
21
21
22
22
all :
23
23
$(Q )$(BOOTSTRAP )
24
+
25
+ clean :
26
+ $(Q )$(BOOTSTRAP ) --clean
You can’t perform that action at this time.
0 commit comments