-
-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate godot compat for dual build
generate compat generate compat Update ci.yml Update binding_generator.py generate compat generate compat lint python files Update compat_generator.py update docs Update binding_generator.py Update module_converter.py also collect defines Add module converter file that converts module based projects to godot_compat Update ci.yml update docs Update compat_generator.py lint python files generate compat generate compat generate compat generate compat Update ci.yml fix path issue when caling from outside Update binding_generator.py update to also take missing classes/structs Update binding_generator.py Generate godot compat for dual build generate compat generate compat Update ci.yml Update binding_generator.py generate compat generate compat lint python files Update compat_generator.py update docs Update binding_generator.py Update module_converter.py also collect defines Add module converter file that converts module based projects to godot_compat Update ci.yml update docs Update compat_generator.py lint python files generate compat generate compat generate compat generate compat Update ci.yml fix path issue when caling from outside Add support for build profiles. Allow enabling or disabling specific classes (which will not be built). Allow forwarding from `ClassDB` to `ClassDBSingleton` to support enumerations update to also take missing classes/structs Update binding_generator.py update update naming of files add godot mappings. update and run output_header_mapping.json Update README.md make godot_compat work without a file generated fix the test Update binding_generator.py Update binding_generator.py Update binding_generator.py use files from include too Update README.md lint lint lint Update CMakeLists.txt update to use all. fix linting a bit update wip fix posix path Update CMakeLists.txt Update binding_generator.py add using namespace godot; everywhere to includes fix includes Try fixes.
- Loading branch information
Showing
6 changed files
with
234 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python | ||
|
||
import json | ||
import os | ||
import re | ||
import sys | ||
|
||
|
||
def parse_header_file(file_path): | ||
types = {"classes": [], "structs": [], "defines": [], "enums": []} | ||
|
||
with open(file_path, "r", encoding="utf-8") as file: | ||
content = file.read() | ||
|
||
# Regular expressions to match different types | ||
struct_pattern = r"struct.*\s(\S+)\s*\{" | ||
type_pattern = r"typedef.*\s(\S+)\s*\;" | ||
enum_pattern = r"enum.*\s(\S+)\s*\{" | ||
class_pattern = r"class\s+[\w\s]*?([a-zA-Z_]\w*)\s*[:{]" | ||
define_pattern = r"#define\s+([a-zA-Z_]\w*)" | ||
|
||
# Extract classes | ||
types["classes"] += re.findall(class_pattern, content) | ||
|
||
# Extract structs | ||
struct_names = re.findall(struct_pattern, content) | ||
types["structs"].extend(struct_names) | ||
type_names = re.findall(type_pattern, content) | ||
types["structs"].extend(type_names) | ||
enum_names = re.findall(enum_pattern, content) | ||
types["enums"].extend(enum_names) | ||
|
||
# Extract defines | ||
define_matches = re.findall(define_pattern, content) | ||
types["defines"] += define_matches | ||
|
||
# Debug the case where no classes or structs are found | ||
# if len(types["classes"]) == 0 and len(types["structs"]) == 0 and len(types["defines"]) == 0: | ||
# print(f"{file_path} missing things") | ||
return types | ||
|
||
|
||
def map_header_files(directory): | ||
file_types_mapping = {} | ||
for root, dirs, files in os.walk(directory): | ||
if "thirdparty" in dirs: | ||
dirs.remove("thirdparty") | ||
if "tests" in dirs: | ||
dirs.remove("tests") | ||
if "test" in dirs: | ||
dirs.remove("test") | ||
if "misc" in dirs: | ||
dirs.remove("misc") | ||
if "gdextension" in dirs: | ||
dirs.remove("gdextension") | ||
for file in files: | ||
if file.endswith(".h") or file.endswith(".hpp"): | ||
relative_path = os.path.relpath(root, directory) | ||
file_path = os.path.join(root, file) | ||
file_types_mapping[f"{relative_path}/{file}"] = parse_header_file(file_path) | ||
|
||
return file_types_mapping | ||
|
||
|
||
if __name__ == "__main__": | ||
# Get current directory for godot-cpp | ||
current_directory = os.path.join(os.getcwd(), "") | ||
mapping_name = "" | ||
if len(sys.argv) > 1: | ||
mapping_name = "_godot" | ||
current_directory = os.path.join(os.getcwd(), sys.argv[1]) | ||
|
||
file_types_mapping = map_header_files(current_directory) | ||
with open(f"output_header_mapping{mapping_name}.json", "w") as json_file: | ||
json.dump(file_types_mapping, json_file, indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import json | ||
import os | ||
|
||
from compat_generator import map_header_files | ||
|
||
|
||
def match_headers(mapping1, mapping2): | ||
matches = {} | ||
for header_file, data1 in mapping1.items(): | ||
for header_file2, data2 in mapping2.items(): | ||
# Check if classes/defines/structs in header_file1 are present in header_file2 | ||
if header_file not in matches: | ||
matches[header_file] = [] | ||
if ( | ||
any(class_name in data2["classes"] for class_name in data1["classes"]) | ||
or any(define_name in data2["defines"] for define_name in data1["defines"]) | ||
or any(define_name in data2["structs"] for define_name in data1["structs"]) | ||
): # or | ||
# any(define_name in data2["enums"] for define_name in data1["enums"])): | ||
matches[header_file].append(header_file2) | ||
return matches | ||
|
||
|
||
if __name__ == "__main__": | ||
# Load the two header mappings | ||
with open("output_header_mapping_godot.json", "r") as file: | ||
mapping_godot = json.load(file) | ||
file_types_mapping_godot_cpp_gen = map_header_files(os.path.join(os.getcwd(), "gen", "include")) | ||
matches = match_headers(file_types_mapping_godot_cpp_gen, mapping_godot) | ||
|
||
# Optionally, you can save the matches to a file | ||
with open("header_matches.json", "w") as outfile: | ||
json.dump(matches, outfile, indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters