1
1
#!/usr/bin/env python
2
2
import os
3
3
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 )
4
10
5
11
env = SConscript ("godot-cpp/SConstruct" )
6
12
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
+
7
41
# For the reference:
8
42
# - CCFLAGS are compilation flags shared between C and C++
9
43
# - CFLAGS are for C-specific compilation flags
@@ -14,7 +48,27 @@ env = SConscript("godot-cpp/SConstruct")
14
48
15
49
# tweak this if you want to use different folders, or more folders, to store your source code in.
16
50
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" )
18
72
19
73
if env ["platform" ] == "macos" :
20
74
library = env .SharedLibrary (
0 commit comments