Skip to content

Commit

Permalink
Use build_profile to improve build times (GodotVR#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsnopek authored Jun 24, 2024
1 parent 94c2d3e commit 10cf401
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build-addon-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ jobs:
- name: Create extension library
run: |
cd aar
scons platform=${{ matrix.platform }} target=template_debug ${{ matrix.flags }} custom_api_file=thirdparty/godot_cpp_gdextension_api/extension_api.json
scons platform=${{ matrix.platform }} target=template_release ${{ matrix.flags }} custom_api_file=thirdparty/godot_cpp_gdextension_api/extension_api.json
scons platform=${{ matrix.platform }} target=template_debug ${{ matrix.flags }} custom_api_file=thirdparty/godot_cpp_gdextension_api/extension_api.json build_profile=thirdparty/godot_cpp_build_profile/build_profile.json
scons platform=${{ matrix.platform }} target=template_release ${{ matrix.flags }} custom_api_file=thirdparty/godot_cpp_gdextension_api/extension_api.json build_profile=thirdparty/godot_cpp_build_profile/build_profile.json
cd ..
# On Android we build our loaders and build our extension with gradlew
Expand All @@ -94,10 +94,10 @@ jobs:
- name: Create Godot-CPP library
run: |
cd aar/thirdparty/godot-cpp
scons platform=${{ matrix.platform }} target=template_debug arch=arm64 custom_api_file=../godot_cpp_gdextension_api/extension_api.json
scons platform=${{ matrix.platform }} target=template_release arch=arm64 custom_api_file=../godot_cpp_gdextension_api/extension_api.json
scons platform=${{ matrix.platform }} target=template_debug arch=x86_64 custom_api_file=../godot_cpp_gdextension_api/extension_api.json
scons platform=${{ matrix.platform }} target=template_release arch=x86_64 custom_api_file=../godot_cpp_gdextension_api/extension_api.json
scons platform=${{ matrix.platform }} target=template_debug arch=arm64 custom_api_file=../godot_cpp_gdextension_api/extension_api.json build_profile=../godot_cpp_build_profile/build_profile.json
scons platform=${{ matrix.platform }} target=template_release arch=arm64 custom_api_file=../godot_cpp_gdextension_api/extension_api.json build_profile=../godot_cpp_build_profile/build_profile.json
scons platform=${{ matrix.platform }} target=template_debug arch=x86_64 custom_api_file=../godot_cpp_gdextension_api/extension_api.json build_profile=../godot_cpp_build_profile/build_profile.json
scons platform=${{ matrix.platform }} target=template_release arch=x86_64 custom_api_file=../godot_cpp_gdextension_api/extension_api.json build_profile=../godot_cpp_build_profile/build_profile.json
cd ../../..
if: matrix.platform == 'android'
- name: Create Godot OpenXR Vendors AARs
Expand Down
63 changes: 63 additions & 0 deletions thirdparty/godot_cpp_build_profile/build_profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"enabled_classes": [
"ArrayMesh",
"BaseMaterial3D",
"BoxMesh",
"BoxShape3D",
"CollisionShape3D",
"ConcavePolygonShape3D",
"Curve",
"EditorExportPlatform",
"EditorExportPlatformAndroid",
"EditorExportPlugin",
"EditorPlugin",
"Engine",
"FileAccess",
"GLTFDocument",
"GLTFState",
"GeometryInstance3D",
"Gradient",
"Image",
"MainLoop",
"Material",
"Mesh",
"MeshConvexDecompositionSettings",
"MeshInstance3D",
"Node",
"Node3D",
"OS",
"Object",
"OpenXRAPIExtension",
"OpenXRExtensionWrapperExtension",
"OpenXRInterface",
"PackedScene",
"PlaneMesh",
"PrimitiveMesh",
"ProjectSettings",
"RefCounted",
"Resource",
"SceneTree",
"Shader",
"ShaderMaterial",
"Shape3D",
"Shortcut",
"Skeleton3D",
"SkeletonModifier3D",
"StandardMaterial3D",
"SurfaceTool",
"Viewport",
"VisualInstance3D",
"XRAnchor3D",
"XRBodyTracker",
"XRFaceTracker",
"XRHandModifier3D",
"XRHandTracker",
"XRInterface",
"XRNode3D",
"XROrigin3D",
"XRPose",
"XRPositionalTracker",
"XRServer",
"XRTracker"
]
}
93 changes: 93 additions & 0 deletions thirdparty/godot_cpp_build_profile/create_build_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env python

import os
import re
import json

SOURCE_DIRS = [
'../../common',
'../../godotopenxrkhronos',
'../../godotopenxrlynx',
'../../godotopenxrmeta',
'../../godotopenxrpico',
]

GODOT_CPP_HEADERS = "../godot-cpp/gen/include/godot_cpp/classes"
#GODOT_CPP_SOURCES = "../godot-cpp/gen/src/classes"

INCLUDE_PATTERN = re.compile(r'#include <godot_cpp/classes/(\w+)\.hpp>')
CLASS_PATTERN = re.compile(r'class\s+(\w+)\s*:\s*public')

processed_files = {}
class_list = []

def find_includes(file_path):
"""
Finds all the includes in a given file and returns the list of CLASS names.
"""
includes = []
try:
with open(file_path, 'r') as file:
content = file.read()
includes = INCLUDE_PATTERN.findall(content)
except FileNotFoundError:
print(f"File not found: {file_path}")
return includes

def find_primary_class(file_path):
"""
Finds the primary class name in a given .hpp file by looking for 'class ClassName : public'.
"""
try:
with open(file_path, 'r') as file:
for line in file:
match = CLASS_PATTERN.search(line)
if match:
return match.group(1)
except FileNotFoundError:
print(f"File not found: {file_path}")
return None

def process_file(file_path, top_level=False):
"""
Processes a given file for includes and processes the included files recursively.
"""
if file_path in processed_files:
return

processed_files[file_path] = True

if not top_level and file_path.endswith('.hpp'):
primary_class = find_primary_class(file_path)
if primary_class and primary_class not in class_list:
class_list.append(primary_class)

includes = find_includes(file_path)
for include_name in includes:
hpp_file = f"{GODOT_CPP_HEADERS}/{include_name}.hpp"
#cpp_file = f"{GODOT_CPP_SOURCES}/{include_name}.cpp"

if os.path.exists(hpp_file):
process_file(hpp_file)
#if os.path.exists(cpp_file):
# process_file(cpp_file)

def main():
for dir in SOURCE_DIRS:
for root, _, files in os.walk(dir):
for file in files:
if file.endswith('.cpp') or file.endswith('.h'):
file_path = os.path.join(root, file)
process_file(file_path, True)

class_list.sort()

build_profile = {
"enabled_classes": class_list
}

with open("build_profile.json", "wt") as file:
json.dump(build_profile, file, indent=4)

if __name__ == "__main__":
main()

0 comments on commit 10cf401

Please sign in to comment.