11use crate :: godot_version;
2+ use std:: fs;
23use std:: path:: PathBuf ;
34use std:: process:: Command ;
45
@@ -43,20 +44,50 @@ pub fn generate_json_if_needed() -> bool {
4344 exec (
4445 if has_generate_bug { 10 } else { 1 } ,
4546 Command :: new ( & godot_bin)
47+ . arg ( "--no-window" )
4648 . arg ( "--gdnative-generate-json-api" )
4749 . arg ( "api.json" ) ,
4850 ) ;
4951
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+
5074 true
5175}
5276
5377/// Executes a command and returns stdout. Panics on failure.
5478fn 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 > {
5584 let command_line = format ! ( "{:?}" , command) ;
5685
5786 for _attempt in 0 ..attempts {
5887 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+ }
6091 Err ( err) => {
6192 eprintln ! (
6293 "Godot command failed:\n command: {}\n error: {}" ,
@@ -66,5 +97,5 @@ fn exec(attempts: i32, command: &mut Command) -> String {
6697 }
6798 }
6899
69- panic ! ( "Could not execute Godot command (see above)." )
100+ None
70101}
0 commit comments