Skip to content

Commit 281cd78

Browse files
committed
Re-generate XML docs when using 'custom-godot' feature
The docs generated from a Godot binary are not as complete as the officially shipped ones, but it's probably the most accurate for a given version.
1 parent 14416c4 commit 281cd78

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

bindings-generator/src/godot_api_json.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::godot_version;
2+
use std::fs;
23
use std::path::PathBuf;
34
use 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.
5478
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> {
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
}

gdnative-bindings/build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ fn main() {
3333
format_file_if_needed(&generated_rs);
3434
format_file_if_needed(&icalls_rs);
3535

36-
// build.rs will automatically be recompiled and run if it's dependencies are updated.
37-
// Ignoring all but build.rs will keep from needless rebuilds.
38-
// Manually rebuilding the crate will ignore this.
39-
println!("cargo:rerun-if-changed=docs/");
36+
// build.rs will automatically be recompiled and run if its dependencies are updated.
37+
// Ignoring everything but build.rs will avoid needless rebuilds.
38+
// Manually rebuilding the crate does not affect this.
4039
println!("cargo:rerun-if-changed=build.rs");
4140

42-
// Avoid endless recompiling, if this script generates api.json
41+
// Avoid endless recompiling, if this script generates api.json and docs
4342
if !just_generated_api {
43+
println!("cargo:rerun-if-changed=docs/");
4444
println!("cargo:rerun-if-changed=api.json");
4545
}
4646
}

0 commit comments

Comments
 (0)