11pub mod bundle;
2+ pub mod hash;
23mod sources;
34
45use anyhow:: { Context , Result , bail} ;
@@ -11,10 +12,11 @@ use std::{
1112use temp_dir:: TempDir ;
1213
1314use crate :: {
14- build:: sources:: get_sources,
1515 chunks:: { load_tree, save_tree} ,
1616 repo:: { self , Metadata , PackageManifest , get_package, insert_package, read_manifest} ,
1717} ;
18+ use hash:: calc_build_hash;
19+ use sources:: get_sources;
1820
1921#[ derive( serde:: Deserialize , serde:: Serialize , Clone , Hash ) ]
2022struct BuildManifest {
@@ -71,6 +73,38 @@ pub async fn build(
7173 repo_path : & Path ,
7274 config_path : Option < & Path > ,
7375 chunk_store_path : & Path ,
76+ ) -> Result < PackageManifest > {
77+ let repo = read_manifest ( repo_path) ?;
78+ let build_manifest: BuildManifest =
79+ serde_yaml:: from_str ( & fs:: read_to_string ( build_manifest_path) ?) ?;
80+
81+ if let Ok ( package) = get_package ( & repo, & build_manifest. id ) {
82+ let next_build_hash = calc_build_hash ( build_manifest_path, repo_path) ?;
83+ if package. build_hash == next_build_hash {
84+ return Ok ( package) ;
85+ }
86+ }
87+
88+ force_build (
89+ build_manifest_path,
90+ repo_path,
91+ config_path,
92+ chunk_store_path,
93+ )
94+ . await
95+ }
96+
97+ /// Builds and inserts a package into a Repository from a `build_manifest`
98+ ///
99+ /// # Errors
100+ ///
101+ /// - Filesystem (Out of Space, Permissions)
102+ /// - Build Script Failure
103+ pub async fn force_build (
104+ build_manifest_path : & Path ,
105+ repo_path : & Path ,
106+ config_path : Option < & Path > ,
107+ chunk_store_path : & Path ,
74108) -> Result < PackageManifest > {
75109 let build_dir = TempDir :: new ( ) ?;
76110 let build_manifest_path = & build_manifest_path. canonicalize ( ) ?;
@@ -114,14 +148,13 @@ pub async fn build(
114148 }
115149
116150 if let Some ( script) = build_manifest. build_script {
117- run_script ( build_dir. path ( ) , build_manifest_path, & script)
118- . with_context ( || "build_script" ) ?;
151+ run_script ( build_dir. path ( ) , search_path, & script) . with_context ( || "build_script" ) ?;
119152 }
120153
121154 let out_dir = build_dir. path ( ) . join ( & build_manifest. directory ) ;
122155
123156 if let Some ( script) = build_manifest. post_script {
124- run_script ( & out_dir, build_manifest_path , & script) . with_context ( || "post_script" ) ?;
157+ run_script ( & out_dir, search_path , & script) . with_context ( || "post_script" ) ?;
125158 }
126159
127160 let mut included_chunks = Vec :: new ( ) ;
@@ -148,8 +181,7 @@ pub async fn build(
148181 metadata : build_manifest. metadata ,
149182 chunks : included_chunks,
150183 env : None ,
151- // TODO!
152- build_hash : "TODO" . to_string ( ) ,
184+ build_hash : calc_build_hash ( build_manifest_path, repo_path) ?,
153185 } ;
154186
155187 if !envs. is_empty ( ) {
0 commit comments