File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -20,10 +20,11 @@ enum CrateType {
20
20
Local ( local:: Local ) ,
21
21
}
22
22
23
+ #[ derive( Clone ) ]
23
24
pub struct CratePatch {
24
- name : String ,
25
- uri : String ,
26
- branch : String
25
+ pub name : String ,
26
+ pub uri : String ,
27
+ pub branch : String
27
28
}
28
29
29
30
/// A Rust crate that can be used with rustwide.
@@ -74,6 +75,10 @@ impl Crate {
74
75
patches. push ( patch) ;
75
76
}
76
77
78
+ pub ( crate ) fn patches ( & self ) -> & Option < Vec < CratePatch > > {
79
+ & self . 1
80
+ }
81
+
77
82
pub ( crate ) fn copy_source_to ( & self , workspace : & Workspace , dest : & Path ) -> Result < ( ) , Error > {
78
83
if dest. exists ( ) {
79
84
info ! (
Original file line number Diff line number Diff line change @@ -174,6 +174,7 @@ impl<'a> TomlTweaker<'a> {
174
174
self . remove_workspaces ( ) ;
175
175
self . remove_unwanted_cargo_features ( ) ;
176
176
self . remove_dependencies ( ) ;
177
+ self . apply_patches ( ) ;
177
178
178
179
info ! ( "finished tweaking {}" , self . krate) ;
179
180
}
@@ -275,6 +276,23 @@ impl<'a> TomlTweaker<'a> {
275
276
}
276
277
}
277
278
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
+
278
296
// This is not a method to avoid borrow checker problems
279
297
fn remove_dependencies_from_table ( table : & mut Table , krate : & str ) {
280
298
// Convert path dependencies to registry dependencies
You can’t perform that action at this time.
0 commit comments