1- use anyhow:: Result ;
1+ use anyhow:: { Context , Result } ;
22use std:: {
33 fs,
44 path:: { Path , PathBuf } ,
55} ;
66
77use crate :: {
88 chunks:: save_tree,
9- crypto:: signing:: sign,
10- repo:: { self , Metadata , PackageManifest , update_manifest} ,
9+ repo:: { self , Metadata , PackageManifest , insert_package} ,
1110} ;
1211
1312#[ derive( serde:: Deserialize , serde:: Serialize , Clone ) ]
1413struct BuildManifest {
1514 /// ID of this package, the main alias
1615 id : String ,
1716 /// Aliases for installation
17+ #[ serde( default ) ]
1818 aliases : Vec < String > ,
1919 /// Package Metadata
2020 metadata : Metadata ,
2121 /// A list of commands that this will give access to
22+ #[ serde( default ) ]
2223 commands : Vec < String > ,
2324 /// Directory relative to the manifest
2425 directory : PathBuf ,
2526}
2627
2728pub fn build ( build_manifest_path : & Path , repo_path : & Path ) -> Result < PackageManifest > {
29+ let build_manifest_path = & build_manifest_path. canonicalize ( ) ?;
30+
2831 let build_manifest: BuildManifest =
2932 serde_yaml:: from_str ( & fs:: read_to_string ( build_manifest_path) ?) ?;
3033
31- let repo_manifest = repo:: read_manifest ( repo_path) ?;
34+ let repo_manifest =
35+ repo:: read_manifest ( repo_path) . with_context ( || "The target Repostiory does not exist" ) ?;
36+
37+ let build_manifest_parent = & build_manifest_path
38+ . parent ( )
39+ . unwrap_or_else ( || Path :: new ( "/" ) ) ;
3240
3341 let chunks = save_tree (
34- & build_manifest_path . join ( build_manifest. directory ) ,
42+ & build_manifest_parent . join ( build_manifest. directory ) ,
3543 & repo_path. join ( "chunks" ) ,
3644 repo_manifest. hash_kind ,
3745 ) ?;
@@ -44,13 +52,7 @@ pub fn build(build_manifest_path: &Path, repo_path: &Path) -> Result<PackageMani
4452 chunks,
4553 } ;
4654
47- let package_manifest_serialized = & serde_yaml:: to_string ( & package_manifest) ?;
48-
49- update_manifest (
50- repo_path,
51- package_manifest_serialized,
52- & sign ( repo_path, package_manifest_serialized) ?. to_bytes ( ) ,
53- ) ?;
55+ insert_package ( & package_manifest, repo_path) ?;
5456
5557 Ok ( package_manifest)
5658}
0 commit comments