@@ -6,12 +6,24 @@ use std::path::PathBuf;
66use std:: vec:: Vec ;
77
88#[ 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 {
1016 pub ( crate ) name : String ,
1117 pub ( crate ) uri : String ,
1218 pub ( crate ) branch : String ,
1319}
1420
21+ #[ derive( Clone ) ]
22+ pub ( crate ) struct PathCratePatch {
23+ pub ( crate ) name : String ,
24+ pub ( crate ) path : String ,
25+ }
26+
1527/// Directory in the [`Workspace`](struct.Workspace.html) where builds can be executed.
1628///
1729/// The build directory contains the source code of the crate being built and the target directory
@@ -32,7 +44,7 @@ pub struct BuildBuilder<'a> {
3244}
3345
3446impl < ' a > BuildBuilder < ' a > {
35- /// Add a patch to this build.
47+ /// Add a git-based patch to this build.
3648 /// Patches get added to the crate's Cargo.toml in the `patch.crates-io` table.
3749 /// # Example
3850 ///
@@ -54,11 +66,45 @@ impl<'a> BuildBuilder<'a> {
5466 /// # Ok(())
5567 /// # }
5668 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 {
5870 name : name. into ( ) ,
5971 uri : uri. into ( ) ,
6072 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+ } ) ) ;
62108 self
63109 }
64110
0 commit comments