1
- use run_make_support:: { python_command, rustdoc} ;
1
+ use run_make_support:: path_helpers:: read_dir_entries_recursive;
2
+ use run_make_support:: rfs:: read_to_string;
3
+ use run_make_support:: { jzon, rustdoc} ;
2
4
3
5
fn main ( ) {
4
6
let out_dir = "out" ;
@@ -8,6 +10,48 @@ fn main() {
8
10
. arg ( "--generate-redirect-map" )
9
11
. out_dir ( & out_dir)
10
12
. run ( ) ;
11
- // FIXME (GuillaumeGomez): Port the python script to Rust as well.
12
- python_command ( ) . arg ( "validate_json.py" ) . arg ( & out_dir) . run ( ) ;
13
+
14
+ let mut found_file = false ;
15
+ read_dir_entries_recursive ( & out_dir, |path| {
16
+ if !found_file
17
+ && path. is_file ( )
18
+ && path. file_name ( ) . map ( |name| name == "redirect-map.json" ) . unwrap_or ( false )
19
+ {
20
+ found_file = true ;
21
+ let generated = read_to_string ( path) ;
22
+ let expected = read_to_string ( "expected.json" ) ;
23
+ let generated = jzon:: parse ( & generated) . expect ( "failed to parse JSON" ) ;
24
+ let expected = jzon:: parse ( & expected) . expect ( "failed to parse JSON" ) ;
25
+
26
+ let mut differences = Vec :: new ( ) ;
27
+ for ( key, expected_value) in expected. entries ( ) {
28
+ match generated. get ( key) {
29
+ Some ( value) => {
30
+ if expected_value != value {
31
+ differences. push ( format ! ( "values for key `{key}` don't match" ) ) ;
32
+ }
33
+ }
34
+ None => differences. push ( format ! ( "missing key `{key}`" ) ) ,
35
+ }
36
+ }
37
+ for ( key, data) in generated. entries ( ) {
38
+ if !expected. has_key ( key) {
39
+ differences
40
+ . push ( format ! ( "Extra data not expected: key: `{key}`, data: `{data}`" ) ) ;
41
+ }
42
+ }
43
+
44
+ if !differences. is_empty ( ) {
45
+ eprintln ! ( "Found differences in JSON files:" ) ;
46
+ for diff in differences {
47
+ eprintln ! ( "=> {diff}" ) ;
48
+ }
49
+ std:: process:: exit ( 1 ) ;
50
+ }
51
+ }
52
+ } ) ;
53
+
54
+ if !found_file {
55
+ panic ! ( "`redirect-map.json` file was not found" ) ;
56
+ }
13
57
}
0 commit comments