@@ -5,9 +5,36 @@ use std::{collections::BTreeMap, path::Path};
5
5
use spin_manifest:: { schema:: v2, ManifestVersion } ;
6
6
7
7
/// Returns a map of component IDs to [`v2::ComponentBuildConfig`]s for the
8
- /// given (v1 or v2) manifest path.
8
+ /// given (v1 or v2) manifest path. If the manifest cannot be loaded, the
9
+ /// function attempts fallback: if fallback succeeds, result is Ok but the load error
10
+ /// is also returned via the second part of the return value tuple.
9
11
pub async fn component_build_configs (
10
12
manifest_file : impl AsRef < Path > ,
13
+ ) -> Result < ( Vec < ComponentBuildInfo > , Option < spin_manifest:: Error > ) > {
14
+ let manifest = spin_manifest:: manifest_from_file ( & manifest_file) ;
15
+ match manifest {
16
+ Ok ( manifest) => Ok ( ( build_configs_from_manifest ( manifest) , None ) ) ,
17
+ Err ( e) => fallback_load_build_configs ( & manifest_file)
18
+ . await
19
+ . map ( |bc| ( bc, Some ( e) ) ) ,
20
+ }
21
+ }
22
+
23
+ fn build_configs_from_manifest (
24
+ manifest : spin_manifest:: schema:: v2:: AppManifest ,
25
+ ) -> Vec < ComponentBuildInfo > {
26
+ manifest
27
+ . components
28
+ . into_iter ( )
29
+ . map ( |( id, c) | ComponentBuildInfo {
30
+ id : id. to_string ( ) ,
31
+ build : c. build ,
32
+ } )
33
+ . collect ( )
34
+ }
35
+
36
+ async fn fallback_load_build_configs (
37
+ manifest_file : impl AsRef < Path > ,
11
38
) -> Result < Vec < ComponentBuildInfo > > {
12
39
let manifest_text = tokio:: fs:: read_to_string ( manifest_file) . await ?;
13
40
Ok ( match ManifestVersion :: detect ( & manifest_text) ? {
0 commit comments