1+ mod sources;
2+
13use anyhow:: { Context , Result , bail} ;
24use std:: {
35 fs,
46 path:: { Path , PathBuf } ,
57 process:: Command ,
68} ;
9+ use temp_dir:: TempDir ;
710
811use crate :: {
12+ build:: sources:: get_sources,
913 chunks:: save_tree,
1014 repo:: { self , Metadata , PackageManifest , insert_package, remove_package} ,
1115} ;
@@ -28,6 +32,18 @@ struct BuildManifest {
2832 edition : String ,
2933 /// Script to be run before packaging
3034 build_script : Option < PathBuf > ,
35+
36+ sources : Option < Vec < Source > > ,
37+ }
38+
39+ #[ derive( serde:: Deserialize , serde:: Serialize , Clone ) ]
40+ struct Source {
41+ /// Should either be git, tar or local
42+ kind : String ,
43+ /// URL to the source.
44+ url : String ,
45+ /// Path to extract.
46+ path : Option < String > ,
3147}
3248
3349/// Builds and inserts a package into a Repository from a `build_manifest`
@@ -37,6 +53,7 @@ struct BuildManifest {
3753/// - Filesystem (Out of Space, Permissions)
3854/// - Build Script Failure
3955pub fn build ( build_manifest_path : & Path , repo_path : & Path ) -> Result < PackageManifest > {
56+ let build_dir = TempDir :: new ( ) ?;
4057 let build_manifest_path = & build_manifest_path. canonicalize ( ) ?;
4158
4259 let build_manifest: BuildManifest =
@@ -49,11 +66,15 @@ pub fn build(build_manifest_path: &Path, repo_path: &Path) -> Result<PackageMani
4966 . parent ( )
5067 . unwrap_or_else ( || Path :: new ( "/" ) ) ;
5168
69+ if let Some ( sources) = build_manifest. sources {
70+ get_sources ( build_dir. path ( ) , build_manifest_parent, & sources) ?;
71+ }
72+
5273 if let Some ( script) = build_manifest. build_script {
5374 let result = Command :: new ( "sh" )
5475 . arg ( "-c" )
5576 . arg ( build_manifest_parent. join ( script) )
56- . current_dir ( build_manifest_parent )
77+ . current_dir ( build_dir . path ( ) )
5778 . status ( ) ?;
5879
5980 if !result. success ( ) {
@@ -62,7 +83,7 @@ pub fn build(build_manifest_path: &Path, repo_path: &Path) -> Result<PackageMani
6283 }
6384
6485 let chunks = save_tree (
65- & build_manifest_parent . join ( build_manifest. directory ) ,
86+ & build_dir . path ( ) . join ( & build_manifest. directory ) ,
6687 & repo_path. join ( "chunks" ) ,
6788 repo_manifest. hash_kind ,
6889 ) ?;
0 commit comments