@@ -23,12 +23,8 @@ impl Channel {
23
23
}
24
24
}
25
25
26
- fn failed_config_parsing ( err : & str ) -> Result < ConfigFile , String > {
27
- Err ( format ! (
28
- "Failed to parse `{}`: {}" ,
29
- ConfigFile :: CONFIG_FILE ,
30
- err
31
- ) )
26
+ fn failed_config_parsing ( config_file : & str , err : & str ) -> Result < ConfigFile , String > {
27
+ Err ( format ! ( "Failed to parse `{}`: {}" , config_file, err) )
32
28
}
33
29
34
30
#[ derive( Default ) ]
@@ -38,13 +34,12 @@ pub struct ConfigFile {
38
34
}
39
35
40
36
impl ConfigFile {
41
- pub const CONFIG_FILE : & ' static str = "config.toml" ;
42
-
43
- pub fn new ( ) -> Result < Self , String > {
44
- let content = fs:: read_to_string ( Self :: CONFIG_FILE ) . map_err ( |_| {
37
+ pub fn new ( config_file : Option < & str > ) -> Result < Self , String > {
38
+ let config_file = config_file. unwrap_or ( "config.toml" ) ;
39
+ let content = fs:: read_to_string ( config_file) . map_err ( |_| {
45
40
format ! (
46
41
"Failed to read `{}`. Take a look at `Readme.md` to see how to set up the project" ,
47
- Self :: CONFIG_FILE ,
42
+ config_file ,
48
43
)
49
44
} ) ?;
50
45
let toml = Toml :: parse ( & content) . map_err ( |err| {
@@ -61,19 +56,23 @@ impl ConfigFile {
61
56
config. gcc_path = Some ( value. as_str ( ) . to_string ( ) )
62
57
}
63
58
( "gcc-path" , _) => {
64
- return failed_config_parsing ( "Expected a string for `gcc-path`" )
59
+ return failed_config_parsing ( config_file , "Expected a string for `gcc-path`" )
65
60
}
66
61
( "download-gccjit" , TomlValue :: Boolean ( value) ) => {
67
62
config. download_gccjit = Some ( * value)
68
63
}
69
64
( "download-gccjit" , _) => {
70
- return failed_config_parsing ( "Expected a boolean for `download-gccjit`" )
65
+ return failed_config_parsing (
66
+ config_file,
67
+ "Expected a boolean for `download-gccjit`" ,
68
+ )
71
69
}
72
- _ => return failed_config_parsing ( & format ! ( "Unknown key `{}`" , key) ) ,
70
+ _ => return failed_config_parsing ( config_file , & format ! ( "Unknown key `{}`" , key) ) ,
73
71
}
74
72
}
75
73
if config. gcc_path . is_none ( ) && config. download_gccjit . is_none ( ) {
76
74
return failed_config_parsing (
75
+ config_file,
77
76
"At least one of `gcc-path` or `download-gccjit` value must be set" ,
78
77
) ;
79
78
}
@@ -104,6 +103,7 @@ pub struct ConfigInfo {
104
103
pub cg_backend_path : String ,
105
104
pub sysroot_path : String ,
106
105
pub gcc_path : String ,
106
+ config_file : Option < String > ,
107
107
}
108
108
109
109
impl ConfigInfo {
@@ -135,6 +135,14 @@ impl ConfigInfo {
135
135
}
136
136
_ => return Err ( "Expected a value after `--out-dir`, found nothing" . to_string ( ) ) ,
137
137
} ,
138
+ "--config-file" => match args. next ( ) {
139
+ Some ( arg) if !arg. is_empty ( ) => {
140
+ self . config_file = Some ( arg. to_string ( ) ) ;
141
+ }
142
+ _ => {
143
+ return Err ( "Expected a value after `--config-file`, found nothing" . to_string ( ) )
144
+ }
145
+ } ,
138
146
"--release-sysroot" => self . sysroot_release_channel = true ,
139
147
"--release" => self . channel = Channel :: Release ,
140
148
"--sysroot-panic-abort" => self . sysroot_panic_abort = true ,
@@ -152,12 +160,15 @@ impl ConfigInfo {
152
160
}
153
161
154
162
pub fn setup_gcc_path ( & mut self , override_gcc_path : Option < & str > ) -> Result < ( ) , String > {
155
- let ConfigFile { gcc_path, .. } = ConfigFile :: new ( ) ?;
163
+ let ConfigFile { gcc_path, .. } = ConfigFile :: new ( self . config_file . as_deref ( ) ) ?;
156
164
157
165
self . gcc_path = match override_gcc_path {
158
166
Some ( path) => {
159
167
if gcc_path. is_some ( ) {
160
- println ! ( "overriding setting from `{}`" , ConfigFile :: CONFIG_FILE ) ;
168
+ println ! (
169
+ "overriding setting from `{}`" ,
170
+ self . config_file. as_deref( ) . unwrap_or( "config.toml" )
171
+ ) ;
161
172
}
162
173
path. to_string ( )
163
174
}
@@ -168,7 +179,7 @@ impl ConfigInfo {
168
179
None => {
169
180
return Err ( format ! (
170
181
"missing `gcc-path` value from `{}`" ,
171
- ConfigFile :: CONFIG_FILE
182
+ self . config_file . as_deref ( ) . unwrap_or ( "config.toml" ) ,
172
183
) )
173
184
}
174
185
}
@@ -363,7 +374,8 @@ impl ConfigInfo {
363
374
--out-dir : Location where the files will be generated
364
375
--release : Build in release mode
365
376
--release-sysroot : Build sysroot in release mode
366
- --sysroot-panic-abort : Build the sysroot without unwinding support."
377
+ --sysroot-panic-abort : Build the sysroot without unwinding support
378
+ --config-file : Location of the config file to be used"
367
379
) ;
368
380
}
369
381
}
0 commit comments