1
1
// cargo run --example gen_svc --release
2
2
// https://github.com/Azure/azure-rest-api-specs/blob/master/specification/batch/data-plane
3
- use autorust_codegen:: {
4
- self , cargo_toml,
5
- config_parser:: { to_mod_name, to_tag_name} ,
6
- get_svc_readmes, lib_rs, path, Config , PropertyName , SpecReadme ,
7
- } ;
3
+ use autorust_codegen:: { self , cargo_toml, get_svc_readmes, lib_rs, path, Config , PropertyName , SpecReadme } ;
8
4
use std:: { collections:: HashSet , fs, path:: PathBuf } ;
9
5
10
6
const OUTPUT_FOLDER : & str = "../svc" ;
@@ -22,11 +18,11 @@ const SKIP_SERVICES: &[&str] = &[
22
18
const SKIP_SERVICE_TAGS : & [ ( & str , & str ) ] = & [
23
19
( "agrifood" , "package-2021-03-31-preview" ) , // duplicate params https://github.com/Azure/azure-sdk-for-rust/issues/501
24
20
( "purview" , "package-2021-05-01-preview" ) , // need to box types
25
- ( "maps" , "package-preview-2_0 " ) , // global responses https://github.com/Azure/azure-sdk-for-rust/issues/502
26
- ( "maps" , "package-1_0 -preview" ) , // global responses https://github.com/Azure/azure-sdk-for-rust/issues/502
27
- ( "servicefabric" , "6_2 " ) , // invalid model TimeBasedBackupScheduleDescription
28
- ( "servicefabric" , "6_3 " ) , // invalid model TimeBasedBackupScheduleDescription
29
- ( "servicefabric" , "6_4 " ) , // invalid model TimeBasedBackupScheduleDescription
21
+ ( "maps" , "package-preview-2.0 " ) , // global responses https://github.com/Azure/azure-sdk-for-rust/issues/502
22
+ ( "maps" , "package-1.0 -preview" ) , // global responses https://github.com/Azure/azure-sdk-for-rust/issues/502
23
+ ( "servicefabric" , "6.2 " ) , // invalid model TimeBasedBackupScheduleDescription
24
+ ( "servicefabric" , "6.3 " ) , // invalid model TimeBasedBackupScheduleDescription
25
+ ( "servicefabric" , "6.4 " ) , // invalid model TimeBasedBackupScheduleDescription
30
26
( "storagedatalake" , "package-2018-11" ) , // "invalid value: string \"ErrorResponse\", expected length 3"
31
27
( "storagedatalake" , "package-2018-06-preview" ) ,
32
28
( "storagedatalake" , "package-2019-10" ) ,
@@ -201,11 +197,9 @@ fn main() -> Result<()> {
201
197
202
198
fn gen_crate ( spec : & SpecReadme ) -> Result < ( ) > {
203
199
let skip_service_tags: HashSet < & ( & str , & str ) > = SKIP_SERVICE_TAGS . iter ( ) . collect ( ) ;
204
- let has_no_configs = spec
205
- . configs ( ) ?
206
- . iter ( )
207
- . all ( |x| skip_service_tags. contains ( & ( spec. spec ( ) , x. tag . as_str ( ) ) ) ) ;
208
- if has_no_configs {
200
+ let config = spec. config ( ) ?;
201
+ let has_no_tags = config. tags ( ) . iter ( ) . all ( |x| skip_service_tags. contains ( & ( spec. spec ( ) , x. name ( ) ) ) ) ;
202
+ if has_no_tags {
209
203
println ! ( "not generating {}" , spec. spec( ) ) ;
210
204
return Ok ( ( ) ) ;
211
205
}
@@ -219,7 +213,7 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
219
213
fs:: remove_dir_all ( & src_folder) . map_err ( |source| Error :: IoError { source } ) ?;
220
214
}
221
215
222
- let mut feature_mod_names = Vec :: new ( ) ;
216
+ let mut tags = Vec :: new ( ) ;
223
217
224
218
let mut fix_case_properties = HashSet :: new ( ) ;
225
219
for spec_title in FIX_CASE_PROPERTIES {
@@ -244,30 +238,22 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
244
238
} ) ;
245
239
}
246
240
247
- for config in spec . configs ( ) ? {
248
- let tag = to_tag_name ( config . tag . as_str ( ) ) ;
249
- if skip_service_tags. contains ( & ( spec. spec ( ) , tag . as_ref ( ) ) ) {
241
+ for tag in config . tags ( ) {
242
+ let tag_name = tag. name ( ) ;
243
+ if skip_service_tags. contains ( & ( spec. spec ( ) , tag_name . as_ref ( ) ) ) {
250
244
// println!(" skipping {}", tag);
251
245
continue ;
252
246
}
253
- println ! ( " {}" , tag ) ;
254
- let mod_name = to_mod_name ( & tag) ;
247
+ println ! ( " {}" , tag_name ) ;
248
+ let mod_name = tag. rust_mod_name ( ) ;
255
249
let mod_output_folder = path:: join ( & src_folder, & mod_name) . map_err ( |source| Error :: PathError { source } ) ?;
256
- feature_mod_names. push ( ( tag, mod_name) ) ;
257
- // println!(" {}", mod_name);
258
- // println!(" {:?}", mod_output_folder);
259
- // for input_file in &config.input_files {
260
- // println!(" {}", input_file);
261
- // }
262
- let input_files: Result < Vec < _ > > = config
263
- . input_files
250
+ tags. push ( tag) ;
251
+ let input_files: Result < Vec < _ > > = tag
252
+ . input_files ( )
264
253
. iter ( )
265
254
. map ( |input_file| path:: join ( spec. readme ( ) , input_file) . map_err ( |source| Error :: PathError { source } ) )
266
255
. collect ( ) ;
267
256
let input_files = input_files?;
268
- // for input_file in &input_files {
269
- // println!(" {:?}", input_file);
270
- // }
271
257
autorust_codegen:: run ( Config {
272
258
output_folder : mod_output_folder,
273
259
input_files,
@@ -278,17 +264,18 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
278
264
..Config :: default ( )
279
265
} ) ?;
280
266
}
281
- if feature_mod_names . is_empty ( ) {
267
+ if tags . is_empty ( ) {
282
268
return Ok ( ( ) ) ;
283
269
}
284
270
cargo_toml:: create (
285
271
crate_name,
286
- & feature_mod_names,
272
+ & tags,
273
+ config. tag ( ) ,
287
274
& path:: join ( output_folder, "Cargo.toml" ) . map_err ( |source| Error :: PathError { source } ) ?,
288
275
)
289
276
. map_err ( |source| Error :: CargoTomlError { source } ) ?;
290
277
lib_rs:: create (
291
- & feature_mod_names ,
278
+ & tags ,
292
279
& path:: join ( src_folder, "lib.rs" ) . map_err ( |source| Error :: PathError { source } ) ?,
293
280
false ,
294
281
)
0 commit comments