1
1
use crate :: cmd:: { Command , MountKind , Runnable , SandboxBuilder } ;
2
2
use crate :: prepare:: Prepare ;
3
- use crate :: { Crate , Toolchain , Workspace } ;
3
+ use crate :: { Crate , Toolchain , Workspace , crates :: CratePatch } ;
4
4
use failure:: Error ;
5
5
use remove_dir_all:: remove_dir_all;
6
6
use std:: path:: PathBuf ;
7
+ use std:: vec:: Vec ;
7
8
8
9
/// Directory in the [`Workspace`](struct.Workspace.html) where builds can be executed.
9
10
///
@@ -18,17 +19,19 @@ pub struct BuildDirectory {
18
19
pub struct Builder < ' a > {
19
20
build_dir : & ' a mut BuildDirectory ,
20
21
toolchain : Option < & ' a Toolchain > ,
21
- krate : Option < & ' a Crate > ,
22
+ krate : Option < Crate > ,
22
23
sandbox : Option < SandboxBuilder > ,
24
+ patches : Vec < CratePatch > ,
23
25
}
24
26
25
27
impl < ' a > Builder < ' a > {
26
- pub fn new ( build_dir : & ' a mut BuildDirectory ) -> Self {
28
+ pub ( crate ) fn new ( build_dir : & ' a mut BuildDirectory ) -> Self {
27
29
Builder {
28
30
build_dir,
29
31
toolchain : None ,
30
32
krate : None ,
31
- sandbox : None
33
+ sandbox : None ,
34
+ patches : Vec :: new ( )
32
35
}
33
36
}
34
37
@@ -37,7 +40,7 @@ impl<'a> Builder<'a> {
37
40
self
38
41
}
39
42
40
- pub fn krate ( mut self , krate : & ' a Crate ) -> Self {
43
+ pub fn krate ( mut self , krate : Crate ) -> Self {
41
44
self . krate . replace ( krate) ;
42
45
self
43
46
}
@@ -47,21 +50,32 @@ impl<'a> Builder<'a> {
47
50
self
48
51
}
49
52
50
- pub fn build < R , F : FnOnce ( & Build ) -> Result < R , Error > > ( self , f : F ) -> Result < R , Error > {
53
+ pub fn patch ( mut self , patch : CratePatch ) -> Self {
54
+ self . patches . push ( patch) ;
55
+ self
56
+ }
57
+
58
+ pub fn build < R , F : FnOnce ( & Build ) -> Result < R , Error > > ( mut self , f : F ) -> Result < R , Error > {
51
59
let tc = match self . toolchain {
52
60
Some ( t) => t,
53
61
None => return Err ( failure:: err_msg ( "No tc" ) ) ,
54
62
} ;
63
+
55
64
let kr = match self . krate {
56
- Some ( k) => k,
57
- None => return Err ( failure:: err_msg ( "No crate" ) ) ,
65
+ Some ( mut k) => {
66
+ self . patches . drain ( ..) . for_each ( |p| k. add_patch ( p) ) ;
67
+ k
68
+ } ,
69
+ None => return Err ( failure:: err_msg ( "no krate" ) ) ,
58
70
} ;
71
+
59
72
let sn = match self . sandbox {
60
73
Some ( s) => s,
61
74
None => return Err ( failure:: err_msg ( "No sandbox" ) ) ,
62
75
} ;
63
76
64
- self . build_dir . build ( tc, kr, sn, f)
77
+
78
+ self . build_dir . build ( tc, & kr, sn, f)
65
79
}
66
80
}
67
81
0 commit comments