2022-06-26 12:00:03 +00:00
|
|
|
import posixpath
|
|
|
|
import os
|
2022-08-02 14:05:31 +00:00
|
|
|
from SCons.Errors import UserError
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def BuildModule(env, module):
|
|
|
|
src_dir = str(env.Dir(".").srcdir or os.getcwd())
|
|
|
|
module_sconscript = posixpath.join(src_dir, module, "SConscript")
|
|
|
|
if not os.path.exists(module_sconscript):
|
|
|
|
module_sconscript = posixpath.join(src_dir, f"{module}.scons")
|
|
|
|
if not os.path.exists(module_sconscript):
|
2022-08-02 14:05:31 +00:00
|
|
|
raise UserError(f"Cannot build module {module}: scons file not found")
|
2022-06-26 12:00:03 +00:00
|
|
|
|
2022-08-02 14:05:31 +00:00
|
|
|
env.Append(PY_LINT_SOURCES=[module_sconscript])
|
2022-06-26 12:00:03 +00:00
|
|
|
return env.SConscript(
|
|
|
|
module_sconscript,
|
|
|
|
variant_dir=posixpath.join(env.subst("$BUILD_DIR"), module),
|
|
|
|
duplicate=0,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def BuildModules(env, modules):
|
|
|
|
result = []
|
|
|
|
for module in modules:
|
|
|
|
build_res = env.BuildModule(module)
|
|
|
|
# print("module ", module, build_res)
|
|
|
|
if build_res is None:
|
|
|
|
continue
|
|
|
|
result.append(build_res)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2022-06-30 16:06:12 +00:00
|
|
|
def PhonyTarget(env, name, action, source=None, **kw):
|
|
|
|
if not source:
|
|
|
|
source = []
|
|
|
|
phony_name = "phony_" + name
|
|
|
|
env.Pseudo(phony_name)
|
2022-07-04 16:53:04 +00:00
|
|
|
command = env.Command(phony_name, source, action, **kw)
|
|
|
|
env.AlwaysBuild(env.Alias(name, command))
|
|
|
|
return command
|
2022-06-30 16:06:12 +00:00
|
|
|
|
|
|
|
|
2022-06-26 12:00:03 +00:00
|
|
|
def generate(env):
|
|
|
|
env.AddMethod(BuildModule)
|
|
|
|
env.AddMethod(BuildModules)
|
2022-06-30 16:06:12 +00:00
|
|
|
env.AddMethod(PhonyTarget)
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|