Skip to content

Commit 2586ad0

Browse files
committed
[SCons] Add option to generate a compilation database.
1 parent 3162be2 commit 2586ad0

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

SConstruct

+33-6
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ def normalize_path(val):
2020
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
2121

2222

23-
def validate_api_file(key, val, env):
23+
def validate_file(key, val, env):
2424
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))
2626

2727

28-
def validate_gdextension_dir(key, val, env):
28+
def validate_dir(key, val, env):
2929
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)))
3136

3237

3338
def get_gdextension_dir(env):
@@ -115,15 +120,15 @@ opts.Add(
115120
key="gdextension_dir",
116121
help="Path to a custom directory containing GDExtension interface header and API JSON file",
117122
default=env.get("gdextension_dir", None),
118-
validator=validate_gdextension_dir,
123+
validator=validate_dir,
119124
)
120125
)
121126
opts.Add(
122127
PathVariable(
123128
key="custom_api_file",
124129
help="Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)",
125130
default=env.get("custom_api_file", None),
126-
validator=validate_api_file,
131+
validator=validate_file,
127132
)
128133
)
129134
opts.Add(
@@ -151,6 +156,23 @@ opts.Add(
151156
)
152157
)
153158

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+
154176
# Add platform options
155177
tools = {}
156178
for pl in platforms:
@@ -242,6 +264,11 @@ else:
242264
if env["precision"] == "double":
243265
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
244266

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+
245272
# Generate bindings
246273
env.Append(BUILDERS={"GenerateBindings": Builder(action=scons_generate_bindings, emitter=scons_emit_files)})
247274

0 commit comments

Comments
 (0)