1- use colored :: Colorize ;
2- use log:: error;
1+ use anyhow :: Context ;
2+ use log:: { error, info } ;
33use versions:: { Requirement , Versioning } ;
44
55use crate :: util:: sha1dir;
@@ -10,6 +10,7 @@ use std::fs::File;
1010use std:: io:: Write ;
1111use std:: path:: { Path , PathBuf } ;
1212use std:: str:: FromStr ;
13+ use std:: time:: Instant ;
1314use url:: { ParseError , Url } ;
1415
1516use crate :: package:: lock:: { PackageLockSource , PackageLockSourceType } ;
@@ -75,8 +76,12 @@ impl PackageDetails {
7576 ) -> anyhow:: Result < ( ) > {
7677 match & self . mutual_exclusive {
7778 ProjectSource :: Path ( path_buf) => {
78- let src = fs:: canonicalize ( path_buf) ?;
79- let dst = fs:: canonicalize ( library_path) ?;
79+ let src = fs:: canonicalize ( path_buf) . with_context ( || {
80+ format ! ( "dependency path not found: {}" , path_buf. display( ) )
81+ } ) ?;
82+ let dst = fs:: canonicalize ( library_path) . with_context ( || {
83+ format ! ( "library path not found: {}" , library_path. display( ) )
84+ } ) ?;
8085 Ok ( copy_dir_all ( src, dst) ?)
8186 }
8287 ProjectSource :: Git ( git_url) => {
@@ -98,22 +103,39 @@ impl DependencyManager {
98103 target_path : & Path ,
99104 git_clone_and_checkout_cap : & GitCloneAndCheckoutCap ,
100105 ) -> anyhow:: Result < DependencyManager > {
106+ info ! (
107+ "Build step: resolving dependencies in {}" ,
108+ target_path. display( )
109+ ) ;
101110 // create library folder
102111 let library_path = target_path. join ( LIBRARY_DIRECTORY ) ;
103- fs:: create_dir_all ( & library_path) ?;
112+ fs:: create_dir_all ( & library_path) . with_context ( || {
113+ format ! (
114+ "failed to create library directory: {}" ,
115+ library_path. display( )
116+ )
117+ } ) ?;
104118
105119 let mut manager;
106120 let mut lock: DependencyLock ;
107121 let lock_file = target_path. join ( "../Lingo.lock" ) ;
108122
109123 // checks if a Lingo.lock file exists
110124 if lock_file. exists ( ) {
125+ info ! ( "Build step: loading lock file {}" , lock_file. display( ) ) ;
111126 // reads and parses Lockfile
112- lock = toml:: from_str :: < DependencyLock > ( & fs:: read_to_string ( lock_file) ?)
127+ lock =
128+ toml:: from_str :: < DependencyLock > ( & fs:: read_to_string ( & lock_file) . with_context (
129+ || format ! ( "failed to read lock file: {}" , lock_file. display( ) ) ,
130+ ) ?)
113131 . expect ( "cannot parse lock" ) ;
114132
115133 // if a lock file is present it will load the dependencies from it and checks
116134 // integrity of the build directory
135+ info ! (
136+ "Build step: validating lock dependencies in {}" ,
137+ target_path. join( "lfc_include" ) . display( )
138+ ) ;
117139 if let Ok ( ( ) ) = lock. init ( & target_path. join ( "lfc_include" ) , git_clone_and_checkout_cap)
118140 {
119141 return Ok ( DependencyManager {
@@ -140,9 +162,14 @@ impl DependencyManager {
140162 lock = DependencyLock :: create ( selection) ;
141163
142164 // writes the lock file down
143- let mut lock_file = File :: create ( target_path. join ( "../Lingo.lock" ) ) ?;
144-
145- println ! ( "{:?}" , lock. dependencies) ;
165+ let lock_file_path = target_path. join ( "../Lingo.lock" ) ;
166+ let mut lock_file = File :: create ( & lock_file_path)
167+ . with_context ( || format ! ( "failed to create lock file: {}" , lock_file_path. display( ) ) ) ?;
168+
169+ info ! (
170+ "Build step: selected lock dependencies: {:?}" ,
171+ lock. dependencies
172+ ) ;
146173 let serialized_toml = toml:: to_string ( & lock) . expect ( "cannot generate toml" ) ;
147174
148175 lock_file. write_all ( serialized_toml. as_ref ( ) ) ?;
@@ -168,11 +195,16 @@ impl DependencyManager {
168195 self . pulling_queue . append ( & mut dependencies) ;
169196 let sub_dependency_path = root_path. join ( "libraries" ) ;
170197 //fs::remove_dir_all(&sub_dependency_path)?;
171- fs:: create_dir_all ( & sub_dependency_path) ?;
198+ fs:: create_dir_all ( & sub_dependency_path) . with_context ( || {
199+ format ! (
200+ "failed to create directory: {}" ,
201+ sub_dependency_path. display( )
202+ )
203+ } ) ?;
172204
173205 while !self . pulling_queue . is_empty ( ) {
174206 if let Some ( ( package_name, package_details) ) = self . pulling_queue . pop ( ) {
175- print ! ( "{} {} ..." , "Cloning" . green ( ) . bold ( ) , package_name) ;
207+ info ! ( "Cloning {} ..." , package_name) ;
176208 let node = match self . non_recursive_fetching (
177209 & package_name,
178210 package_details,
@@ -216,15 +248,32 @@ impl DependencyManager {
216248 fs:: create_dir_all ( & temporary_path) ?;
217249
218250 // cloning the specified package
251+ info ! (
252+ "Build step: fetching dependency {} into {}" ,
253+ name,
254+ temporary_path. display( )
255+ ) ;
219256 package. fetch ( & temporary_path, git_clone_and_checkout_cap) ?;
220257
258+ info ! (
259+ "Build step: computing checksum for {}" ,
260+ temporary_path. display( )
261+ ) ;
262+ let checksum_started_at = Instant :: now ( ) ;
221263 let hash = sha1dir:: checksum_current_dir ( & temporary_path, false ) ;
264+ info ! (
265+ "Build step: checksum complete for {} in {:?}" ,
266+ temporary_path. display( ) ,
267+ checksum_started_at. elapsed( )
268+ ) ;
222269 let include_path = library_path. join ( hash. to_string ( ) ) ;
223270
224- let lingo_toml_text = fs:: read_to_string ( temporary_path. clone ( ) . join ( "Lingo.toml" ) ) ?;
271+ let lingo_toml_path = temporary_path. join ( "Lingo.toml" ) ;
272+ let lingo_toml_text = fs:: read_to_string ( & lingo_toml_path)
273+ . with_context ( || format ! ( "failed to read {}" , lingo_toml_path. display( ) ) ) ?;
225274 let read_toml = toml:: from_str :: < ConfigFile > ( & lingo_toml_text) ?. to_config ( & temporary_path) ;
226275
227- println ! ( " {}" , read_toml. package. version) ;
276+ info ! ( "Resolved dependency version {}" , read_toml. package. version) ;
228277
229278 let config = match read_toml. library {
230279 Some ( value) => value,
0 commit comments