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

Add compiledb generation to test project and customs loading SConstruct #1213

Closed
Closed
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ if env.GetOption("num_jobs") == altered_num_jobs:

# Custom options and profile flags.
customs = ["custom.py"]
try:
customs += Import("customs")
except:
pass

profile = ARGUMENTS.get("profile", "")
if profile:
if os.path.isfile(profile):
Expand Down Expand Up @@ -265,9 +270,11 @@ if env["precision"] == "double":
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])

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

# Generate bindings
env.Append(BUILDERS={"GenerateBindings": Builder(action=scons_generate_bindings, emitter=scons_emit_files)})
Expand Down Expand Up @@ -316,7 +323,10 @@ library_name = "libgodot-cpp{}{}".format(suffix, env["LIBSUFFIX"])

if env["build_library"]:
library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources)
Default(library)
default_args = [library]
if not compilation_db is None:
default_args += [compilation_db]
Default(*default_args)

env.Append(LIBPATH=[env.Dir("bin")])
env.Append(LIBS=library_name)
Expand Down
3 changes: 3 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ mono_crash.*.json
# System/tool-specific ignores
.directory
*~

# Build configuarion.
/custom.py
49 changes: 47 additions & 2 deletions test/SConstruct
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
#!/usr/bin/env python
import os
import sys
from SCons.Errors import UserError

env = SConscript("../SConstruct")

def normalize_path(val, env):
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)


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


localEnv = Environment()
customs = ["custom.py"]
opts = Variables(customs, ARGUMENTS)

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

opts.Update(localEnv)

env = localEnv.Clone()
env["compiledb"] = False
env = SConscript("../SConstruct", {"env": env, "customs": customs})

compilation_db = None
if localEnv.get("compiledb", False):
env.Tool("compilation_db")
compilation_db = env.CompilationDatabase(normalize_path(env["compiledb_file"], env))
env.Alias("compiledb", compilation_db)

# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
Expand All @@ -29,4 +70,8 @@ else:
source=sources,
)

Default(library)
default_args = [library]
if not compilation_db is None:
default_args += [compilation_db]

Default(*default_args)