Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SCons] Add option to generate a compilation database. #1189

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ def normalize_path(val):
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)


def validate_api_file(key, val, env):
def validate_file(key, val, env):
if not os.path.isfile(normalize_path(val)):
raise UserError("GDExtension API file ('%s') does not exist: %s" % (key, val))
raise UserError("'%s' is not a file: %s" % (key, val))


def validate_gdextension_dir(key, val, env):
def validate_dir(key, val, env):
if not os.path.isdir(normalize_path(val)):
raise UserError("GDExtension directory ('%s') does not exist: %s" % (key, val))
raise UserError("'%s' is not a directory: %s" % (key, val))


def validate_parent_dir(key, val, env):
if not os.path.isdir(normalize_path(os.path.dirname(val))):
raise UserError("'%s' is not a directory: %s" % (key, os.path.dirname(val)))


def get_gdextension_dir(env):
Expand Down Expand Up @@ -115,15 +120,15 @@ opts.Add(
key="gdextension_dir",
help="Path to a custom directory containing GDExtension interface header and API JSON file",
default=env.get("gdextension_dir", None),
validator=validate_gdextension_dir,
validator=validate_dir,
)
)
opts.Add(
PathVariable(
key="custom_api_file",
help="Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)",
default=env.get("custom_api_file", None),
validator=validate_api_file,
validator=validate_file,
)
)
opts.Add(
Expand Down Expand Up @@ -151,6 +156,23 @@ opts.Add(
)
)

# compiledb
opts.Add(
BoolVariable(
key="compiledb",
help="Generate compilation DB (`compile_commands.json`) for external tools",
default=env.get("compiledb", False),
)
)
opts.Add(
PathVariable(
key="compiledb_file",
help="Path to a custom `compile_commands.json` file",
default=env.get("compiledb_file", "compile_commands.json"),
validator=validate_parent_dir,
)
)

# Add platform options
tools = {}
for pl in platforms:
Expand Down Expand Up @@ -242,6 +264,11 @@ else:
if env["precision"] == "double":
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])

# compile_commands.json
if env.get("compiledb", False):
env.Tool("compilation_db")
env.Alias("compiledb", env.CompilationDatabase(normalize_path(env["compiledb_file"])))

# Generate bindings
env.Append(BUILDERS={"GenerateBindings": Builder(action=scons_generate_bindings, emitter=scons_emit_files)})

Expand Down