aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author George L. Albany <Megacake1234@gmail.com>2023-01-29 03:03:54 +0100
committer George L. Albany <Megacake1234@gmail.com>2023-01-29 04:09:28 +0100
commit934f51ffc7b60551cc70bc9a07f0823976346a27 (patch)
tree83377db2542a6a80430ace2db21b249b7bc4d8b0
parent572ada1168537d20910aad935715ffec28c9fcf6 (diff)
feat(build): Allow local configuration build options with custom.py
feat(build): Allow deleting unassociated intermediate files (on by default) feat(build): Added recursive searching for C++ source files in src/extension feat(git): Ignore /custom.py
-rw-r--r--.gitignore5
-rw-r--r--SConstruct56
2 files changed, 59 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index cb404df..3b0260e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -61,4 +61,7 @@ bin/*
*.files
*.includes
*.idb
-*.exp \ No newline at end of file
+*.exp
+
+# Build configuarion.
+/custom.py \ No newline at end of file
diff --git a/SConstruct b/SConstruct
index cadc5d3..4e6fe70 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1,9 +1,43 @@
#!/usr/bin/env python
import os
import sys
+from glob import glob
+from pathlib import Path
+
+# Neccessary to have our own build options without errors
+SAVED_ARGUMENTS = ARGUMENTS.copy()
+ARGUMENTS.pop('intermediate_delete', True)
env = SConscript("godot-cpp/SConstruct")
+ARGUMENTS = SAVED_ARGUMENTS
+
+# Custom options and profile flags.
+customs = ["custom.py"]
+profile = ARGUMENTS.get("profile", "")
+if profile:
+ if os.path.isfile(profile):
+ customs.append(profile)
+ elif os.path.isfile(profile + ".py"):
+ customs.append(profile + ".py")
+opts = Variables(customs, ARGUMENTS)
+
+opts.Add(
+ BoolVariable("intermediate_delete", "Enables automatically deleting unassociated intermediate binary files.", True)
+)
+
+opts.Update(env)
+Help(opts.GenerateHelpText(env))
+
+def GlobRecursive(pattern, node='.'):
+ import SCons
+ results = []
+ for f in Glob(str(node) + '/*', source=True):
+ if type(f) is SCons.Node.FS.Dir:
+ results += GlobRecursive(pattern, f)
+ results += Glob(str(node) + '/' + pattern, source=True)
+ return results
+
# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
@@ -14,7 +48,27 @@ env = SConscript("godot-cpp/SConstruct")
# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=["extension/src/"])
-sources = Glob("extension/src/*.cpp")
+sources = GlobRecursive("*.cpp", "extension/src")
+
+# Remove unassociated intermediate binary files if allowed, usually the result of a renamed or deleted source file
+if env["intermediate_delete"]:
+ def remove_extension(file : str):
+ if file.find(".") == -1: return file
+ return file[:file.rindex(".")]
+
+ found_one = False
+ for obj_file in [file[:-len(".os")] for file in glob("extension/src/*.os", recursive=True)]:
+ found = False
+ for source_file in sources:
+ if remove_extension(str(source_file)) == obj_file:
+ found = True
+ break
+ if not found:
+ if not found_one:
+ found_one = True
+ print("Unassociated intermediate files found...")
+ print("Removing "+obj_file+".os")
+ os.remove(obj_file+".os")
if env["platform"] == "macos":
library = env.SharedLibrary(