1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Single Compilation Unit build.

Adds support for simple SCU build.
This speeds up compilation by compiling multiple cpp files within a single translation unit.
This commit is contained in:
lawnjelly
2022-11-27 08:34:07 +00:00
parent 29eeb461f2
commit 43e181a00a
35 changed files with 542 additions and 130 deletions

View File

@@ -13,8 +13,23 @@ from SCons.Script import ARGUMENTS
from SCons.Script import Glob
from SCons.Variables.BoolVariable import _text2bool
from pathlib import Path
from os.path import normpath, basename
def add_source_files(self, sources, files):
# Get the "Godot" folder name ahead of time
base_folder_path = str(os.path.abspath(Path(__file__).parent)) + "/"
base_folder_only = os.path.basename(os.path.normpath(base_folder_path))
# Listing all the folders we have converted
# for SCU in scu_builders.py
_scu_folders = set()
def set_scu_folders(scu_folders):
global _scu_folders
_scu_folders = scu_folders
def add_source_files_orig(self, sources, files, allow_gen=False):
# Convert string to list of absolute paths (including expanding wildcard)
if isbasestring(files):
# Keep SCons project-absolute path as they are (no wildcard support)
@@ -29,7 +44,7 @@ def add_source_files(self, sources, files):
skip_gen_cpp = "*" in files
dir_path = self.Dir(".").abspath
files = sorted(glob.glob(dir_path + "/" + files))
if skip_gen_cpp:
if skip_gen_cpp and not allow_gen:
files = [f for f in files if not f.endswith(".gen.cpp")]
# Add each path as compiled Object following environment (self) configuration
@@ -41,6 +56,71 @@ def add_source_files(self, sources, files):
sources.append(obj)
# The section name is used for checking
# the hash table to see whether the folder
# is included in the SCU build.
# It will be something like "core/math".
def _find_scu_section_name(subdir):
section_path = os.path.abspath(subdir) + "/"
folders = []
folder = ""
for i in range(8):
folder = os.path.dirname(section_path)
folder = os.path.basename(folder)
if folder == base_folder_only:
break
folders += [folder]
section_path += "../"
section_path = os.path.abspath(section_path) + "/"
section_name = ""
for n in range(len(folders)):
section_name += folders[len(folders) - n - 1]
if n != (len(folders) - 1):
section_name += "/"
return section_name
def add_source_files_scu(self, sources, files, allow_gen=False):
if self["scu_build"] and isinstance(files, str):
if "*." not in files:
return False
# If the files are in a subdirectory, we want to create the scu gen
# files inside this subdirectory.
subdir = os.path.dirname(files)
if subdir != "":
subdir += "/"
section_name = _find_scu_section_name(subdir)
# if the section name is in the hash table?
# i.e. is it part of the SCU build?
global _scu_folders
if section_name not in (_scu_folders):
return False
if self["verbose"]:
print("SCU building " + section_name)
# Add all the gen.cpp files in the SCU directory
add_source_files_orig(self, sources, subdir + ".scu/scu_*.gen.cpp", True)
return True
return False
# Either builds the folder using the SCU system,
# or reverts to regular build.
def add_source_files(self, sources, files, allow_gen=False):
if not add_source_files_scu(self, sources, files, allow_gen):
# Wraps the original function when scu build is not active.
add_source_files_orig(self, sources, files, allow_gen)
return False
return True
def disable_warnings(self):
# 'self' is the environment
if self.msvc: