Skip to content

Commit edb5e94

Browse files
committed
Post install commands
1 parent 8eca69a commit edb5e94

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

src/module.rs

+44-7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ pub struct Module {
4949
/// A list of commands to run before building
5050
pub pre_build: Option<Vec<String>>,
5151

52+
/// A list of commands to run after installing
53+
pub post_install: Option<Vec<String>>,
54+
5255
/// Downloader to download the source code
5356
pub downloader: Option<Downloader>,
5457

@@ -188,7 +191,32 @@ impl Module {
188191
if let Some(builder) = &self.builder {
189192
let (_, build_path, install_path, modules) = self.parse(&flavour);
190193

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(())
192220
} else {
193221
log::warn(&format!(
194222
"Module '{}' does not have a Builder",
@@ -287,12 +315,6 @@ impl Module {
287315
})
288316
.collect::<Result<Vec<(String, Environment)>, String>>()?;
289317

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-
296318
let builder: Result<Option<Builder>, String> = match object.getattr("build") {
297319
Ok(download) => Ok(Some(Builder::from_py(&download.call0().map_err(
298320
|err| format!("Failed to call `build` in module class: {err}"),
@@ -315,6 +337,20 @@ impl Module {
315337
Err(_) => None,
316338
};
317339

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+
318354
let source_path = format!(
319355
"{}{PATH_SEP}{}{PATH_SEP}{}",
320356
config.build_root, name, version
@@ -335,6 +371,7 @@ impl Module {
335371
environment,
336372
metadata,
337373
pre_build,
374+
post_install,
338375
downloader,
339376
builder,
340377
source_path,

0 commit comments

Comments
 (0)