1
1
use crate :: ErrorMessage ;
2
- use std:: path:: PathBuf ;
2
+ use std:: path:: Path ;
3
3
use toml:: Value ;
4
4
5
5
#[ derive( Debug , Clone ) ]
6
6
pub struct Config {
7
- pub manifest_path : PathBuf ,
8
7
pub default_target : Option < String > ,
9
8
pub run_command : Vec < String > ,
10
9
pub run_args : Option < Vec < String > > ,
11
10
pub test_timeout : u32 ,
12
11
}
13
12
14
- pub ( crate ) fn read_config ( manifest_path : PathBuf ) -> Result < Config , ErrorMessage > {
13
+ pub ( crate ) fn read_config ( manifest_path : & Path ) -> Result < Config , ErrorMessage > {
15
14
let config = read_config_inner ( manifest_path)
16
15
. map_err ( |err| format ! ( "Failed to read bootimage configuration: {:?}" , err) ) ?;
17
16
Ok ( config)
18
17
}
19
18
20
- pub ( crate ) fn read_config_inner ( manifest_path : PathBuf ) -> Result < Config , ErrorMessage > {
19
+ pub ( crate ) fn read_config_inner ( manifest_path : & Path ) -> Result < Config , ErrorMessage > {
21
20
use std:: { fs:: File , io:: Read } ;
22
21
let cargo_toml: Value = {
23
22
let mut content = String :: new ( ) ;
24
- File :: open ( & manifest_path)
23
+ File :: open ( manifest_path)
25
24
. map_err ( |e| format ! ( "Failed to open Cargo.toml: {}" , e) ) ?
26
25
. read_to_string ( & mut content)
27
26
. map_err ( |e| format ! ( "Failed to read Cargo.toml: {}" , e) ) ?;
@@ -36,21 +35,14 @@ pub(crate) fn read_config_inner(manifest_path: PathBuf) -> Result<Config, ErrorM
36
35
. and_then ( |table| table. get ( "bootimage" ) ) ;
37
36
let metadata = match metadata {
38
37
None => {
39
- return Ok ( ConfigBuilder {
40
- manifest_path : Some ( manifest_path) ,
41
- ..Default :: default ( )
42
- }
43
- . into ( ) ) ;
38
+ return Ok ( ConfigBuilder :: default ( ) . into ( ) ) ;
44
39
}
45
40
Some ( metadata) => metadata
46
41
. as_table ( )
47
42
. ok_or ( format ! ( "Bootimage configuration invalid: {:?}" , metadata) ) ?,
48
43
} ;
49
44
50
- let mut config = ConfigBuilder {
51
- manifest_path : Some ( manifest_path) ,
52
- ..Default :: default ( )
53
- } ;
45
+ let mut config = ConfigBuilder :: default ( ) ;
54
46
55
47
for ( key, value) in metadata {
56
48
match ( key. as_str ( ) , value. clone ( ) ) {
@@ -93,7 +85,6 @@ pub(crate) fn read_config_inner(manifest_path: PathBuf) -> Result<Config, ErrorM
93
85
94
86
#[ derive( Default ) ]
95
87
struct ConfigBuilder {
96
- manifest_path : Option < PathBuf > ,
97
88
default_target : Option < String > ,
98
89
run_command : Option < Vec < String > > ,
99
90
run_args : Option < Vec < String > > ,
@@ -103,7 +94,6 @@ struct ConfigBuilder {
103
94
impl Into < Config > for ConfigBuilder {
104
95
fn into ( self ) -> Config {
105
96
Config {
106
- manifest_path : self . manifest_path . expect ( "manifest path must be set" ) ,
107
97
default_target : self . default_target ,
108
98
run_command : self . run_command . unwrap_or ( vec ! [
109
99
"qemu-system-x86_64" . into( ) ,
0 commit comments