@@ -15,6 +15,56 @@ pub struct BuildDirectory {
15
15
name : String ,
16
16
}
17
17
18
+ pub struct Builder < ' a > {
19
+ build_dir : & ' a mut BuildDirectory ,
20
+ toolchain : Option < & ' a Toolchain > ,
21
+ krate : Option < & ' a Crate > ,
22
+ sandbox : Option < SandboxBuilder > ,
23
+ }
24
+
25
+ impl < ' a > Builder < ' a > {
26
+ pub fn new ( build_dir : & ' a mut BuildDirectory ) -> Self {
27
+ Builder {
28
+ build_dir,
29
+ toolchain : None ,
30
+ krate : None ,
31
+ sandbox : None
32
+ }
33
+ }
34
+
35
+ pub fn toolchain ( mut self , toolchain : & ' a Toolchain ) -> Self {
36
+ self . toolchain . replace ( toolchain) ;
37
+ self
38
+ }
39
+
40
+ pub fn krate ( mut self , krate : & ' a Crate ) -> Self {
41
+ self . krate . replace ( krate) ;
42
+ self
43
+ }
44
+
45
+ pub fn sandbox ( mut self , sandbox : SandboxBuilder ) -> Self {
46
+ self . sandbox . replace ( sandbox) ;
47
+ self
48
+ }
49
+
50
+ pub fn build < R , F : FnOnce ( & Build ) -> Result < R , Error > > ( self , f : F ) -> Result < R , Error > {
51
+ let tc = match self . toolchain {
52
+ Some ( t) => t,
53
+ None => return Err ( failure:: err_msg ( "No tc" ) ) ,
54
+ } ;
55
+ let kr = match self . krate {
56
+ Some ( k) => k,
57
+ None => return Err ( failure:: err_msg ( "No crate" ) ) ,
58
+ } ;
59
+ let sn = match self . sandbox {
60
+ Some ( s) => s,
61
+ None => return Err ( failure:: err_msg ( "No sandbox" ) ) ,
62
+ } ;
63
+
64
+ self . build_dir . build ( tc, kr, sn, f)
65
+ }
66
+ }
67
+
18
68
impl BuildDirectory {
19
69
pub ( crate ) fn new ( workspace : Workspace , name : & str ) -> Self {
20
70
Self {
@@ -23,6 +73,10 @@ impl BuildDirectory {
23
73
}
24
74
}
25
75
76
+ pub fn builder ( & mut self ) -> Builder {
77
+ Builder :: new ( self )
78
+ }
79
+
26
80
/// Run a sandboxed build of the provided crate with the provided toolchain. The closure will
27
81
/// be provided an instance of [`Build`](struct.Build.html) that allows spawning new processes
28
82
/// inside the sandbox.
0 commit comments