@@ -20,14 +20,19 @@ def normalize_path(val):
20
20
return val if os .path .isabs (val ) else os .path .join (env .Dir ("#" ).abspath , val )
21
21
22
22
23
- def validate_api_file (key , val , env ):
23
+ def validate_file (key , val , env ):
24
24
if not os .path .isfile (normalize_path (val )):
25
- raise UserError ("GDExtension API file ( '%s') does not exist : %s" % (key , val ))
25
+ raise UserError ("'%s' is not a file : %s" % (key , val ))
26
26
27
27
28
- def validate_gdextension_dir (key , val , env ):
28
+ def validate_dir (key , val , env ):
29
29
if not os .path .isdir (normalize_path (val )):
30
- raise UserError ("GDExtension directory ('%s') does not exist: %s" % (key , val ))
30
+ raise UserError ("'%s' is not a directory: %s" % (key , val ))
31
+
32
+
33
+ def validate_parent_dir (key , val , env ):
34
+ if not os .path .isdir (normalize_path (os .path .dirname (val ))):
35
+ raise UserError ("'%s' is not a directory: %s" % (key , os .path .dirname (val )))
31
36
32
37
33
38
def get_gdextension_dir (env ):
@@ -115,15 +120,15 @@ opts.Add(
115
120
key = "gdextension_dir" ,
116
121
help = "Path to a custom directory containing GDExtension interface header and API JSON file" ,
117
122
default = env .get ("gdextension_dir" , None ),
118
- validator = validate_gdextension_dir ,
123
+ validator = validate_dir ,
119
124
)
120
125
)
121
126
opts .Add (
122
127
PathVariable (
123
128
key = "custom_api_file" ,
124
129
help = "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)" ,
125
130
default = env .get ("custom_api_file" , None ),
126
- validator = validate_api_file ,
131
+ validator = validate_file ,
127
132
)
128
133
)
129
134
opts .Add (
@@ -151,6 +156,23 @@ opts.Add(
151
156
)
152
157
)
153
158
159
+ # compiledb
160
+ opts .Add (
161
+ BoolVariable (
162
+ key = "compiledb" ,
163
+ help = "Generate compilation DB (`compile_commands.json`) for external tools" ,
164
+ default = env .get ("compiledb" , False ),
165
+ )
166
+ )
167
+ opts .Add (
168
+ PathVariable (
169
+ key = "compiledb_file" ,
170
+ help = "Path to a custom `compile_commands.json` file" ,
171
+ default = env .get ("compiledb_file" , "compile_commands.json" ),
172
+ validator = validate_parent_dir ,
173
+ )
174
+ )
175
+
154
176
# Add platform options
155
177
tools = {}
156
178
for pl in platforms :
@@ -242,6 +264,11 @@ else:
242
264
if env ["precision" ] == "double" :
243
265
env .Append (CPPDEFINES = ["REAL_T_IS_DOUBLE" ])
244
266
267
+ # compile_commands.json
268
+ if env .get ("compiledb" , False ):
269
+ env .Tool ("compilation_db" )
270
+ env .Alias ("compiledb" , env .CompilationDatabase (normalize_path (env ["compiledb_file" ])))
271
+
245
272
# Generate bindings
246
273
env .Append (BUILDERS = {"GenerateBindings" : Builder (action = scons_generate_bindings , emitter = scons_emit_files )})
247
274
0 commit comments