1
1
//! Download management for external tools and applications. Locate and automatically download
2
2
//! applications (if needed) to use them in the build pipeline.
3
3
4
- use std:: collections:: HashMap ;
5
- use std:: path:: PathBuf ;
6
-
4
+ use self :: archive:: Archive ;
5
+ use crate :: common:: { is_executable, path_exists, path_exists_and} ;
7
6
use anyhow:: { anyhow, bail, ensure, Context , Result } ;
8
7
use directories:: ProjectDirs ;
9
8
use futures_util:: stream:: StreamExt ;
10
9
use once_cell:: sync:: Lazy ;
10
+ use std:: collections:: HashMap ;
11
+ use std:: path:: PathBuf ;
11
12
use tokio:: fs:: File ;
12
13
use tokio:: io:: AsyncWriteExt ;
13
14
use tokio:: process:: Command ;
14
15
use tokio:: sync:: { Mutex , OnceCell } ;
15
16
16
- use self :: archive:: Archive ;
17
- use crate :: common:: { is_executable, path_exists, path_exists_and} ;
18
-
19
17
/// The application to locate and eventually download when calling [`get`].
20
18
#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash , strum:: EnumIter ) ]
21
19
pub enum Application {
@@ -34,7 +32,7 @@ pub enum Application {
34
32
pub struct HttpClientOptions {
35
33
/// Use this specific root certificate to validate the certificate chain. Optional.
36
34
///
37
- /// Usefull when behind a corporate proxy that uses a self-signed root certificate.
35
+ /// Useful when behind a corporate proxy that uses a self-signed root certificate.
38
36
pub root_certificate : Option < PathBuf > ,
39
37
/// Allows Trunk to accept certificates that can't be verified when fetching dependencies. Defaults to false.
40
38
///
@@ -247,21 +245,23 @@ impl AppCache {
247
245
}
248
246
249
247
/// Locate the given application and download it if missing.
250
- #[ tracing:: instrument( level = "trace " ) ]
248
+ #[ tracing:: instrument( level = "debug " ) ]
251
249
pub async fn get (
252
250
app : Application ,
253
251
version : Option < & str > ,
254
252
offline : bool ,
255
253
client_options : & HttpClientOptions ,
256
254
) -> Result < PathBuf > {
255
+ tracing:: debug!( "Getting tool" ) ;
256
+
257
257
if let Some ( ( path, detected_version) ) = find_system ( app) . await {
258
258
// consider system installed version
259
259
260
260
if let Some ( required_version) = version {
261
261
// we have a version requirement
262
262
if required_version == detected_version {
263
263
// and a match, so return early
264
- tracing:: info! ( app = %app . name ( ) , %detected_version, "using system installed binary: {}" , path. display( ) ) ;
264
+ tracing:: debug! ( %detected_version, "using system installed binary: {}" , path. display( ) ) ;
265
265
return Ok ( path) ;
266
266
} else if offline {
267
267
// a mismatch, in offline mode, we can't help here
@@ -271,7 +271,7 @@ pub async fn get(
271
271
)
272
272
} else {
273
273
// a mismatch, so we need to download
274
- tracing:: debug! ( app = %app . name ( ) , "tool version mismatch (required: {required_version}, system: {detected_version})" ) ;
274
+ tracing:: info! ( "tool version mismatch (required: {required_version}, system: {detected_version})" ) ;
275
275
}
276
276
} else {
277
277
// we don't require any specific version
@@ -281,8 +281,9 @@ pub async fn get(
281
281
282
282
if offline {
283
283
return Err ( anyhow ! (
284
- "couldn't find application {}, unable to download in offline mode" ,
285
- & app. name( )
284
+ "couldn't find application {name} (version: {version}), unable to download in offline mode" ,
285
+ name = & app. name( ) ,
286
+ version = version. unwrap_or( "<any>" )
286
287
) ) ;
287
288
}
288
289
@@ -309,8 +310,9 @@ pub async fn get(
309
310
}
310
311
311
312
/// Try to find a global system installed version of the application.
312
- #[ tracing:: instrument( level = "trace " ) ]
313
+ #[ tracing:: instrument( level = "debug " ) ]
313
314
pub async fn find_system ( app : Application ) -> Option < ( PathBuf , String ) > {
315
+ // we wrap this into an fn to easier deal with result -> option conversion
314
316
let result = || async {
315
317
let path = which:: which ( app. name ( ) ) ?;
316
318
let output = Command :: new ( & path) . arg ( app. version_test ( ) ) . output ( ) . await ?;
@@ -329,7 +331,13 @@ pub async fn find_system(app: Application) -> Option<(PathBuf, String)> {
329
331
Ok ( ( path, system_version) )
330
332
} ;
331
333
332
- result ( ) . await . ok ( )
334
+ match result ( ) . await {
335
+ Ok ( result) => Some ( result) ,
336
+ Err ( err) => {
337
+ tracing:: debug!( "failed to detect system tool: {err}" ) ;
338
+ None
339
+ }
340
+ }
333
341
}
334
342
335
343
/// Download a file from its remote location in the given version, extract it and make it ready for
0 commit comments