Skip to content

Commit c093629

Browse files
committed
add patches to crate
1 parent 9f0985d commit c093629

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

src/build.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::cmd::{Command, MountKind, Runnable, SandboxBuilder};
22
use crate::prepare::Prepare;
3-
use crate::{Crate, Toolchain, Workspace};
3+
use crate::{Crate, Toolchain, Workspace, crates::CratePatch};
44
use failure::Error;
55
use remove_dir_all::remove_dir_all;
66
use std::path::PathBuf;
7+
use std::vec::Vec;
78

89
/// Directory in the [`Workspace`](struct.Workspace.html) where builds can be executed.
910
///
@@ -18,17 +19,19 @@ pub struct BuildDirectory {
1819
pub struct Builder<'a> {
1920
build_dir: &'a mut BuildDirectory,
2021
toolchain: Option<&'a Toolchain>,
21-
krate: Option<&'a Crate>,
22+
krate: Option<Crate>,
2223
sandbox: Option<SandboxBuilder>,
24+
patches: Vec<CratePatch>,
2325
}
2426

2527
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 {
2729
Builder {
2830
build_dir,
2931
toolchain: None,
3032
krate: None,
31-
sandbox: None
33+
sandbox: None,
34+
patches: Vec::new()
3235
}
3336
}
3437

@@ -37,7 +40,7 @@ impl<'a> Builder<'a> {
3740
self
3841
}
3942

40-
pub fn krate(mut self, krate: &'a Crate) -> Self {
43+
pub fn krate(mut self, krate: Crate) -> Self {
4144
self.krate.replace(krate);
4245
self
4346
}
@@ -47,21 +50,32 @@ impl<'a> Builder<'a> {
4750
self
4851
}
4952

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> {
5159
let tc = match self.toolchain {
5260
Some(t) => t,
5361
None => return Err(failure::err_msg("No tc")),
5462
};
63+
5564
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")),
5870
};
71+
5972
let sn = match self.sandbox {
6073
Some(s) => s,
6174
None => return Err(failure::err_msg("No sandbox")),
6275
};
6376

64-
self.build_dir.build(tc, kr, sn, f)
77+
78+
self.build_dir.build(tc, &kr, sn, f)
6579
}
6680
}
6781

src/crates/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,32 @@ enum CrateType {
2020
Local(local::Local),
2121
}
2222

23+
pub struct CratePatch {
24+
name: String,
25+
uri: String,
26+
branch: String
27+
}
28+
2329
/// A Rust crate that can be used with rustwide.
24-
pub struct Crate(CrateType);
30+
pub struct Crate(CrateType, Option<Vec<CratePatch>>);
2531

2632
impl Crate {
2733
/// Load a crate from the [crates.io registry](https://crates.io).
2834
pub fn crates_io(name: &str, version: &str) -> Self {
2935
Crate(CrateType::CratesIO(cratesio::CratesIOCrate::new(
3036
name, version,
31-
)))
37+
)), None)
3238
}
3339

3440
/// Load a crate from a git repository. The full URL needed to clone the repo has to be
3541
/// provided.
3642
pub fn git(url: &str) -> Self {
37-
Crate(CrateType::Git(git::GitRepo::new(url)))
43+
Crate(CrateType::Git(git::GitRepo::new(url)), None)
3844
}
3945

4046
/// Load a crate from a directory in the local filesystem.
4147
pub fn local(path: &Path) -> Self {
42-
Crate(CrateType::Local(local::Local::new(path)))
48+
Crate(CrateType::Local(local::Local::new(path)), None)
4349
}
4450

4551
/// Fetch the crate's source code and cache it in the workspace. This method will reach out to
@@ -63,6 +69,11 @@ impl Crate {
6369
}
6470
}
6571

72+
pub(crate) fn add_patch(&mut self, patch: CratePatch) {
73+
let patches: &mut Vec<CratePatch> = self.1.get_or_insert(Vec::new());
74+
patches.push(patch);
75+
}
76+
6677
pub(crate) fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<(), Error> {
6778
if dest.exists() {
6879
info!(

0 commit comments

Comments
 (0)