1
1
use crate :: godot_version;
2
+ use std:: fs;
2
3
use std:: path:: PathBuf ;
3
4
use std:: process:: Command ;
4
5
@@ -43,20 +44,50 @@ pub fn generate_json_if_needed() -> bool {
43
44
exec (
44
45
if has_generate_bug { 10 } else { 1 } ,
45
46
Command :: new ( & godot_bin)
47
+ . arg ( "--no-window" )
46
48
. arg ( "--gdnative-generate-json-api" )
47
49
. arg ( "api.json" ) ,
48
50
) ;
49
51
52
+ // Best effort for generating the XML documentation
53
+ // Note: this documentation is not the same as shipped by official Godot releases, but it's the best we have.
54
+ exec_maybe (
55
+ 1 ,
56
+ Command :: new ( & godot_bin)
57
+ . arg ( "--no-window" )
58
+ . arg ( "--doctool" )
59
+ . arg ( "." ) ,
60
+ ) ;
61
+
62
+ // Godot output structure required structure
63
+ //
64
+ // +-- api.json
65
+ // +-- modules +-- api.json
66
+ // +-- doc +-- docs [*]
67
+ // +-- classes [*]
68
+ //
69
+ let _ = fs:: remove_dir_all ( "docs" ) ;
70
+ let _ = fs:: rename ( "doc/classes" , "docs" ) ;
71
+ let _ = fs:: remove_dir ( "doc" ) ;
72
+ let _ = fs:: remove_dir_all ( "modules" ) ;
73
+
50
74
true
51
75
}
52
76
53
77
/// Executes a command and returns stdout. Panics on failure.
54
78
fn exec ( attempts : i32 , command : & mut Command ) -> String {
79
+ exec_maybe ( attempts, command)
80
+ . unwrap_or_else ( || panic ! ( "Could not execute Godot command (see above)." ) )
81
+ }
82
+
83
+ fn exec_maybe ( attempts : i32 , command : & mut Command ) -> Option < String > {
55
84
let command_line = format ! ( "{:?}" , command) ;
56
85
57
86
for _attempt in 0 ..attempts {
58
87
match command. output ( ) {
59
- Ok ( output) => return String :: from_utf8 ( output. stdout ) . expect ( "parse UTF8 string" ) ,
88
+ Ok ( output) => {
89
+ return Some ( String :: from_utf8 ( output. stdout ) . expect ( "parse UTF8 string" ) )
90
+ }
60
91
Err ( err) => {
61
92
eprintln ! (
62
93
"Godot command failed:\n command: {}\n error: {}" ,
@@ -66,5 +97,5 @@ fn exec(attempts: i32, command: &mut Command) -> String {
66
97
}
67
98
}
68
99
69
- panic ! ( "Could not execute Godot command (see above)." )
100
+ None
70
101
}
0 commit comments