1
1
use crate :: cmd:: { Command , MountKind , Runnable , SandboxBuilder } ;
2
2
use crate :: prepare:: Prepare ;
3
- use crate :: { Crate , Toolchain , Workspace , crates :: CratePatch } ;
3
+ use crate :: { Crate , Toolchain , Workspace } ;
4
4
use failure:: Error ;
5
5
use remove_dir_all:: remove_dir_all;
6
6
use std:: path:: PathBuf ;
7
7
use std:: vec:: Vec ;
8
8
9
+ /// Holds info for a patch to be added to a crate's Cargo.toml
10
+ #[ derive( Clone ) ]
11
+ pub struct CratePatch {
12
+ /// Crate name to patch
13
+ pub name : String ,
14
+ /// URL of the git repo
15
+ pub uri : String ,
16
+ /// Branch of the git repo
17
+ pub branch : String
18
+ }
19
+
9
20
/// Directory in the [`Workspace`](struct.Workspace.html) where builds can be executed.
10
21
///
11
22
/// The build directory contains the source code of the crate being built and the target directory
@@ -16,6 +27,7 @@ pub struct BuildDirectory {
16
27
name : String ,
17
28
}
18
29
30
+ /// Builder for configuring builds in a [`BuildDirectory`](struct.BuildDirectory.html).
19
31
pub struct Builder < ' a > {
20
32
build_dir : & ' a mut BuildDirectory ,
21
33
toolchain : & ' a Toolchain ,
@@ -26,11 +38,56 @@ pub struct Builder<'a> {
26
38
27
39
impl < ' a > Builder < ' a > {
28
40
41
+ /// Add a patch to this build.
42
+ /// Patches get added to the crate's Cargo.toml in the `patch.crates-io` table.
43
+ /// # Example
44
+ ///
45
+ /// ```no_run
46
+ /// # use rustwide::{WorkspaceBuilder, Toolchain, Crate, CratePatch, cmd::SandboxBuilder};
47
+ /// # use std::error::Error;
48
+ /// # fn main() -> Result<(), Box<dyn Error>> {
49
+ /// # let workspace = WorkspaceBuilder::new("".as_ref(), "").init()?;
50
+ /// # let toolchain = Toolchain::Dist { name: "".into() };
51
+ /// # let krate = Crate::local("".as_ref());
52
+ /// # let sandbox = SandboxBuilder::new();
53
+ /// let crate_patch = CratePatch { name: "bar".into(), uri: "https://github.com/foo/bar".into(), branch: "baz".into() };
54
+ /// let mut build_dir = workspace.build_dir("foo");
55
+ /// build_dir.build(&toolchain, &krate, sandbox)
56
+ /// .patch(crate_patch)
57
+ /// .run(|build| {
58
+ /// build.cargo().args(&["test", "--all"]).run()?;
59
+ /// Ok(())
60
+ /// })?;
61
+ /// # Ok(())
62
+ /// # }
29
63
pub fn patch ( mut self , patch : CratePatch ) -> Self {
30
64
self . patches . push ( patch) ;
31
65
self
32
66
}
33
67
68
+ /// Run a sandboxed build of the provided crate with the provided toolchain. The closure will
69
+ /// be provided an instance of [`Build`](struct.Build.html) that allows spawning new processes
70
+ /// inside the sandbox.
71
+ ///
72
+ /// All the state will be kept on disk as long as the closure doesn't exit: after that things
73
+ /// might be removed.
74
+ /// # Example
75
+ ///
76
+ /// ```no_run
77
+ /// # use rustwide::{WorkspaceBuilder, Toolchain, Crate, cmd::SandboxBuilder};
78
+ /// # use std::error::Error;
79
+ /// # fn main() -> Result<(), Box<dyn Error>> {
80
+ /// # let workspace = WorkspaceBuilder::new("".as_ref(), "").init()?;
81
+ /// # let toolchain = Toolchain::Dist { name: "".into() };
82
+ /// # let krate = Crate::local("".as_ref());
83
+ /// # let sandbox = SandboxBuilder::new();
84
+ /// let mut build_dir = workspace.build_dir("foo");
85
+ /// build_dir.build(&toolchain, &krate, sandbox).run(|build| {
86
+ /// build.cargo().args(&["test", "--all"]).run()?;
87
+ /// Ok(())
88
+ /// })?;
89
+ /// # Ok(())
90
+ /// # }
34
91
pub fn run < R , F : FnOnce ( & Build ) -> Result < R , Error > > ( self , f : F ) -> Result < R , Error > {
35
92
self . build_dir . run ( self . toolchain , self . krate , self . sandbox , self . patches , f)
36
93
}
@@ -44,22 +101,8 @@ impl BuildDirectory {
44
101
}
45
102
}
46
103
47
- pub fn build < ' a > ( & ' a mut self ,
48
- toolchain : & ' a Toolchain ,
49
- krate : & ' a Crate ,
50
- sandbox : SandboxBuilder ,
51
- ) -> Builder {
52
- Builder {
53
- build_dir : self , toolchain, krate, sandbox, patches : Vec :: new ( )
54
- }
55
- }
56
-
57
- /// Run a sandboxed build of the provided crate with the provided toolchain. The closure will
58
- /// be provided an instance of [`Build`](struct.Build.html) that allows spawning new processes
59
- /// inside the sandbox.
60
- ///
61
- /// All the state will be kept on disk as long as the closure doesn't exit: after that things
62
- /// might be removed.
104
+ /// Create a build in this build directory. Returns a builder that can be used
105
+ /// to configure the build and run it.
63
106
///
64
107
/// # Example
65
108
///
@@ -72,13 +115,23 @@ impl BuildDirectory {
72
115
/// # let krate = Crate::local("".as_ref());
73
116
/// # let sandbox = SandboxBuilder::new();
74
117
/// let mut build_dir = workspace.build_dir("foo");
75
- /// build_dir.build(&toolchain, &krate, sandbox, |build| {
118
+ /// build_dir.build(&toolchain, &krate, sandbox).run( |build| {
76
119
/// build.cargo().args(&["test", "--all"]).run()?;
77
120
/// Ok(())
78
121
/// })?;
79
122
/// # Ok(())
80
123
/// # }
81
124
/// ```
125
+ pub fn build < ' a > ( & ' a mut self ,
126
+ toolchain : & ' a Toolchain ,
127
+ krate : & ' a Crate ,
128
+ sandbox : SandboxBuilder ,
129
+ ) -> Builder {
130
+ Builder {
131
+ build_dir : self , toolchain, krate, sandbox, patches : Vec :: new ( )
132
+ }
133
+ }
134
+
82
135
pub ( crate ) fn run < R , F : FnOnce ( & Build ) -> Result < R , Error > > (
83
136
& mut self ,
84
137
toolchain : & Toolchain ,
@@ -155,7 +208,7 @@ impl Build<'_> {
155
208
/// # let krate = Crate::local("".as_ref());
156
209
/// # let sandbox = SandboxBuilder::new();
157
210
/// let mut build_dir = workspace.build_dir("foo");
158
- /// build_dir.build(&toolchain, &krate, sandbox, |build| {
211
+ /// build_dir.build(&toolchain, &krate, sandbox).run( |build| {
159
212
/// build.cmd("rustfmt").args(&["--check", "src/main.rs"]).run()?;
160
213
/// Ok(())
161
214
/// })?;
@@ -192,7 +245,7 @@ impl Build<'_> {
192
245
/// # let krate = Crate::local("".as_ref());
193
246
/// # let sandbox = SandboxBuilder::new();
194
247
/// let mut build_dir = workspace.build_dir("foo");
195
- /// build_dir.build(&toolchain, &krate, sandbox, |build| {
248
+ /// build_dir.build(&toolchain, &krate, sandbox).run( |build| {
196
249
/// build.cargo().args(&["test", "--all"]).run()?;
197
250
/// Ok(())
198
251
/// })?;
0 commit comments