Skip to content

Commit 1c10e6a

Browse files
committed
Add buildscript support, editions
1 parent 736e323 commit 1c10e6a

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/build/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
use anyhow::{Context, Result};
1+
use anyhow::{Context, Result, bail};
22
use std::{
33
fs,
44
path::{Path, PathBuf},
5+
process::Command,
56
};
67

78
use crate::{
89
chunks::save_tree,
9-
repo::{self, Metadata, PackageManifest, insert_package},
10+
repo::{self, Metadata, PackageManifest, insert_package, remove_package},
1011
};
1112

1213
#[derive(serde::Deserialize, serde::Serialize, Clone)]
@@ -23,8 +24,18 @@ struct BuildManifest {
2324
commands: Vec<String>,
2425
/// Directory relative to the manifest
2526
directory: PathBuf,
27+
/// Edition
28+
edition: String,
29+
/// Script to be run before packaging
30+
build_script: Option<PathBuf>,
2631
}
2732

33+
/// Builds and inserts a package into a Repository from a `build_manifest`
34+
///
35+
/// # Errors
36+
///
37+
/// - Filesystem (Out of Space, Permissions)
38+
/// - Build Script Failure
2839
pub fn build(build_manifest_path: &Path, repo_path: &Path) -> Result<PackageManifest> {
2940
let build_manifest_path = &build_manifest_path.canonicalize()?;
3041

@@ -38,6 +49,18 @@ pub fn build(build_manifest_path: &Path, repo_path: &Path) -> Result<PackageMani
3849
.parent()
3950
.unwrap_or_else(|| Path::new("/"));
4051

52+
if let Some(script) = build_manifest.build_script {
53+
let result = Command::new("sh")
54+
.arg("-c")
55+
.arg(build_manifest_parent.join(script))
56+
.current_dir(build_manifest_parent)
57+
.status()?;
58+
59+
if !result.success() {
60+
bail!("Build script failed.")
61+
}
62+
}
63+
4164
let chunks = save_tree(
4265
&build_manifest_parent.join(build_manifest.directory),
4366
&repo_path.join("chunks"),
@@ -52,6 +75,7 @@ pub fn build(build_manifest_path: &Path, repo_path: &Path) -> Result<PackageMani
5275
chunks,
5376
};
5477

78+
let _ = remove_package(&package_manifest.id, repo_path);
5579
insert_package(&package_manifest, repo_path)?;
5680

5781
Ok(package_manifest)

0 commit comments

Comments
 (0)