@@ -6,12 +6,24 @@ use std::path::PathBuf;
6
6
use std:: vec:: Vec ;
7
7
8
8
#[ derive( Clone ) ]
9
- pub ( crate ) struct CratePatch {
9
+ pub ( crate ) enum CratePatch {
10
+ Git ( GitCratePatch ) ,
11
+ Path ( PathCratePatch ) ,
12
+ }
13
+
14
+ #[ derive( Clone ) ]
15
+ pub ( crate ) struct GitCratePatch {
10
16
pub ( crate ) name : String ,
11
17
pub ( crate ) uri : String ,
12
18
pub ( crate ) branch : String ,
13
19
}
14
20
21
+ #[ derive( Clone ) ]
22
+ pub ( crate ) struct PathCratePatch {
23
+ pub ( crate ) name : String ,
24
+ pub ( crate ) path : String ,
25
+ }
26
+
15
27
/// Directory in the [`Workspace`](struct.Workspace.html) where builds can be executed.
16
28
///
17
29
/// The build directory contains the source code of the crate being built and the target directory
@@ -32,7 +44,7 @@ pub struct BuildBuilder<'a> {
32
44
}
33
45
34
46
impl < ' a > BuildBuilder < ' a > {
35
- /// Add a patch to this build.
47
+ /// Add a git-based patch to this build.
36
48
/// Patches get added to the crate's Cargo.toml in the `patch.crates-io` table.
37
49
/// # Example
38
50
///
@@ -54,11 +66,45 @@ impl<'a> BuildBuilder<'a> {
54
66
/// # Ok(())
55
67
/// # }
56
68
pub fn patch_with_git ( mut self , name : & str , uri : & str , branch : & str ) -> Self {
57
- self . patches . push ( CratePatch {
69
+ self . patches . push ( CratePatch :: Git ( GitCratePatch {
58
70
name : name. into ( ) ,
59
71
uri : uri. into ( ) ,
60
72
branch : branch. into ( ) ,
61
- } ) ;
73
+ } ) ) ;
74
+ self
75
+ }
76
+
77
+ /// Add a path-based patch to this build.
78
+ /// Patches get added to the crate's Cargo.toml in the `patch.crates-io` table.
79
+ /// # Example
80
+ ///
81
+ /// ```no_run
82
+ /// # use rustwide::{WorkspaceBuilder, Toolchain, Crate, cmd::{MountKind, SandboxBuilder}};
83
+ /// # use std::{error::Error, path::{Path, PathBuf}};
84
+ /// # fn main() -> Result<(), Box<dyn Error>> {
85
+ /// # let workspace = WorkspaceBuilder::new("".as_ref(), "").init()?;
86
+ /// # let toolchain = Toolchain::dist("");
87
+ /// # let krate = Crate::local("".as_ref());
88
+ /// # let manifest_dir = "/path/to/bar";
89
+ /// let sandbox = SandboxBuilder::new().mount(
90
+ /// Path::new(manifest_dir),
91
+ /// Path::new("/patch/bar"),
92
+ /// MountKind::ReadOnly,
93
+ /// );
94
+ /// let mut build_dir = workspace.build_dir("foo");
95
+ /// build_dir.build(&toolchain, &krate, sandbox)
96
+ /// .patch_with_path("bar", "/patch/bar")
97
+ /// .run(|build| {
98
+ /// build.cargo().args(&["test", "--all"]).run()?;
99
+ /// Ok(())
100
+ /// })?;
101
+ /// # Ok(())
102
+ /// # }
103
+ pub fn patch_with_path ( mut self , name : & str , path : & str ) -> Self {
104
+ self . patches . push ( CratePatch :: Path ( PathCratePatch {
105
+ name : name. into ( ) ,
106
+ path : path. into ( ) ,
107
+ } ) ) ;
62
108
self
63
109
}
64
110
0 commit comments