Skip to content

Commit e72f01c

Browse files
committed
crate patches get applied during toml tweak
1 parent c093629 commit e72f01c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/crates/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ enum CrateType {
2020
Local(local::Local),
2121
}
2222

23+
#[derive(Clone)]
2324
pub struct CratePatch {
24-
name: String,
25-
uri: String,
26-
branch: String
25+
pub name: String,
26+
pub uri: String,
27+
pub branch: String
2728
}
2829

2930
/// A Rust crate that can be used with rustwide.
@@ -74,6 +75,10 @@ impl Crate {
7475
patches.push(patch);
7576
}
7677

78+
pub(crate) fn patches(&self) -> &Option<Vec<CratePatch>> {
79+
&self.1
80+
}
81+
7782
pub(crate) fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<(), Error> {
7883
if dest.exists() {
7984
info!(

src/prepare.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ impl<'a> TomlTweaker<'a> {
174174
self.remove_workspaces();
175175
self.remove_unwanted_cargo_features();
176176
self.remove_dependencies();
177+
self.apply_patches();
177178

178179
info!("finished tweaking {}", self.krate);
179180
}
@@ -275,6 +276,23 @@ impl<'a> TomlTweaker<'a> {
275276
}
276277
}
277278

279+
fn apply_patches(&mut self) {
280+
if let Some(krate_patches) = self.krate.patches() {
281+
if !self.table.contains_key("patch.crates-io") {
282+
self.table.insert("patch.crates-io".into(), Value::Table(Table::new()));
283+
}
284+
285+
if let Some(&mut Value::Table(ref mut patches)) = self.table.get_mut("patch.crates-io") {
286+
for patch in krate_patches.iter().cloned() {
287+
let mut patch_table = Table::new();
288+
patch_table.insert("git".into(), Value::String(patch.uri));
289+
patch_table.insert("branch".into(), Value::String(patch.branch));
290+
patches.insert(patch.name, Value::Table(patch_table));
291+
}
292+
}
293+
}
294+
}
295+
278296
// This is not a method to avoid borrow checker problems
279297
fn remove_dependencies_from_table(table: &mut Table, krate: &str) {
280298
// Convert path dependencies to registry dependencies

0 commit comments

Comments
 (0)