Skip to content

Commit 934f51f

Browse files
committed
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
1 parent 572ada1 commit 934f51f

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,7 @@ bin/*
6161
*.files
6262
*.includes
6363
*.idb
64-
*.exp
64+
*.exp
65+
66+
# Build configuarion.
67+
/custom.py

SConstruct

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
11
#!/usr/bin/env python
22
import os
33
import sys
4+
from glob import glob
5+
from pathlib import Path
6+
7+
# Neccessary to have our own build options without errors
8+
SAVED_ARGUMENTS = ARGUMENTS.copy()
9+
ARGUMENTS.pop('intermediate_delete', True)
410

511
env = SConscript("godot-cpp/SConstruct")
612

13+
ARGUMENTS = SAVED_ARGUMENTS
14+
15+
# Custom options and profile flags.
16+
customs = ["custom.py"]
17+
profile = ARGUMENTS.get("profile", "")
18+
if profile:
19+
if os.path.isfile(profile):
20+
customs.append(profile)
21+
elif os.path.isfile(profile + ".py"):
22+
customs.append(profile + ".py")
23+
opts = Variables(customs, ARGUMENTS)
24+
25+
opts.Add(
26+
BoolVariable("intermediate_delete", "Enables automatically deleting unassociated intermediate binary files.", True)
27+
)
28+
29+
opts.Update(env)
30+
Help(opts.GenerateHelpText(env))
31+
32+
def GlobRecursive(pattern, node='.'):
33+
import SCons
34+
results = []
35+
for f in Glob(str(node) + '/*', source=True):
36+
if type(f) is SCons.Node.FS.Dir:
37+
results += GlobRecursive(pattern, f)
38+
results += Glob(str(node) + '/' + pattern, source=True)
39+
return results
40+
741
# For the reference:
842
# - CCFLAGS are compilation flags shared between C and C++
943
# - CFLAGS are for C-specific compilation flags
@@ -14,7 +48,27 @@ env = SConscript("godot-cpp/SConstruct")
1448

1549
# tweak this if you want to use different folders, or more folders, to store your source code in.
1650
env.Append(CPPPATH=["extension/src/"])
17-
sources = Glob("extension/src/*.cpp")
51+
sources = GlobRecursive("*.cpp", "extension/src")
52+
53+
# Remove unassociated intermediate binary files if allowed, usually the result of a renamed or deleted source file
54+
if env["intermediate_delete"]:
55+
def remove_extension(file : str):
56+
if file.find(".") == -1: return file
57+
return file[:file.rindex(".")]
58+
59+
found_one = False
60+
for obj_file in [file[:-len(".os")] for file in glob("extension/src/*.os", recursive=True)]:
61+
found = False
62+
for source_file in sources:
63+
if remove_extension(str(source_file)) == obj_file:
64+
found = True
65+
break
66+
if not found:
67+
if not found_one:
68+
found_one = True
69+
print("Unassociated intermediate files found...")
70+
print("Removing "+obj_file+".os")
71+
os.remove(obj_file+".os")
1872

1973
if env["platform"] == "macos":
2074
library = env.SharedLibrary(

0 commit comments

Comments
 (0)