@@ -49,6 +49,9 @@ pub struct Module {
49
49
/// A list of commands to run before building
50
50
pub pre_build : Option < Vec < String > > ,
51
51
52
+ /// A list of commands to run after installing
53
+ pub post_install : Option < Vec < String > > ,
54
+
52
55
/// Downloader to download the source code
53
56
pub downloader : Option < Downloader > ,
54
57
@@ -188,7 +191,32 @@ impl Module {
188
191
if let Some ( builder) = & self . builder {
189
192
let ( _, build_path, install_path, modules) = self . parse ( & flavour) ;
190
193
191
- builder. install ( & self . source_path , & build_path, & install_path, & modules)
194
+ builder. install ( & self . source_path , & build_path, & install_path, & modules) ?;
195
+
196
+ if let Some ( commands) = & self . post_install {
197
+ log:: status ( & "Running post-install commands" ) ;
198
+ let mut shell = Shell :: default ( ) ;
199
+ shell. set_current_dir ( & install_path) ;
200
+ for cmd in commands {
201
+ shell. add_command ( & cmd) ;
202
+ }
203
+
204
+ let ( result, stdout, stderr) = shell. exec ( ) ;
205
+
206
+ let result = result. map_err ( |_| "Failed to run post-install commands" ) ?;
207
+
208
+ if !result. success ( ) {
209
+ return Err ( format ! (
210
+ "Failed to execute command. Output:\n {}\n {}" ,
211
+ stdout. join( "\n " ) ,
212
+ stderr. join( "\n " )
213
+ ) ) ;
214
+ }
215
+
216
+ log:: status ( & "Building..." ) ;
217
+ }
218
+
219
+ Ok ( ( ) )
192
220
} else {
193
221
log:: warn ( & format ! (
194
222
"Module '{}' does not have a Builder" ,
@@ -287,12 +315,6 @@ impl Module {
287
315
} )
288
316
. collect :: < Result < Vec < ( String , Environment ) > , String > > ( ) ?;
289
317
290
- // let builder = Builder::from_py(
291
- // &extract_object(object, "build")?
292
- // .call0()
293
- // .map_err(|err| format!("Failed to call `build` in module class: {err}"))?,
294
- // )?;
295
-
296
318
let builder: Result < Option < Builder > , String > = match object. getattr ( "build" ) {
297
319
Ok ( download) => Ok ( Some ( Builder :: from_py ( & download. call0 ( ) . map_err (
298
320
|err| format ! ( "Failed to call `build` in module class: {err}" ) ,
@@ -315,6 +337,20 @@ impl Module {
315
337
Err ( _) => None ,
316
338
} ;
317
339
340
+ let post_install: Option < Vec < String > > = match extract_object ( object, "post_install" ) {
341
+ Ok ( obj) => Some (
342
+ obj. call0 ( )
343
+ . map_err ( |err| {
344
+ format ! ( "Failed to call 'post_install()` in module class: {err}" )
345
+ } ) ?
346
+ . extract ( )
347
+ . map_err ( |err| {
348
+ format ! ( "Failed to convert object to Rust Vec<String>: {err}" )
349
+ } ) ?,
350
+ ) ,
351
+ Err ( _) => None ,
352
+ } ;
353
+
318
354
let source_path = format ! (
319
355
"{}{PATH_SEP}{}{PATH_SEP}{}" ,
320
356
config. build_root, name, version
@@ -335,6 +371,7 @@ impl Module {
335
371
environment,
336
372
metadata,
337
373
pre_build,
374
+ post_install,
338
375
downloader,
339
376
builder,
340
377
source_path,
0 commit comments