Skip to content

Commit 0c94f81

Browse files
committed
Codegen: version file also updated if JSON file does not exist
1 parent 5a8a000 commit 0c94f81

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

godot-codegen/src/godot_exe.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ pub fn load_extension_api_json(watch: &mut StopWatch) -> String {
2525
rerun_on_changed(&godot_bin);
2626
watch.record("locate_godot");
2727

28-
// Regnerate API JSON if first time or Godot version is different
29-
if !json_path.exists() || has_version_changed(&godot_bin) {
28+
// Regenerate API JSON if first time or Godot version is different
29+
let version = read_godot_version(&godot_bin);
30+
if !json_path.exists() || has_version_changed(&version) {
3031
dump_extension_api(&godot_bin, json_path);
32+
update_version_file(&version);
33+
3134
watch.record("dump_extension_api");
3235
}
3336

@@ -37,23 +40,23 @@ pub fn load_extension_api_json(watch: &mut StopWatch) -> String {
3740
result
3841
}
3942

40-
fn has_version_changed(godot_bin: &Path) -> bool {
43+
fn has_version_changed(current_version: &str) -> bool {
4144
let version_path = Path::new(GODOT_VERSION_PATH);
42-
rerun_on_changed(version_path);
4345

44-
let current_version = read_godot_version(&godot_bin);
45-
let changed = match std::fs::read_to_string(version_path) {
46+
match std::fs::read_to_string(version_path) {
4647
Ok(last_version) => current_version != last_version,
4748
Err(_) => true,
48-
};
49-
50-
if changed {
51-
std::fs::write(version_path, current_version).expect(&format!(
52-
"write Godot version to file {}",
53-
version_path.display()
54-
));
5549
}
56-
changed
50+
}
51+
52+
fn update_version_file(version: &str) {
53+
let version_path = Path::new(GODOT_VERSION_PATH);
54+
rerun_on_changed(version_path);
55+
56+
std::fs::write(version_path, version).expect(&format!(
57+
"write Godot version to file {}",
58+
version_path.display()
59+
));
5760
}
5861

5962
fn read_godot_version(godot_bin: &Path) -> String {

0 commit comments

Comments
 (0)