Skip to content

Commit

Permalink
Remove include_repos and auto-detect existing SConscripts
Browse files Browse the repository at this point in the history
  • Loading branch information
calebchalmers committed Jul 14, 2024
1 parent 322a119 commit eeedcef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
1 change: 0 additions & 1 deletion test/config/lbuild.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</repositories>
<options>
<option name="modm:build:scons:include_sconstruct">True</option>
<option name="modm:build:scons:include_repos">modm-test</option>
<option name="modm:build:info.build">True</option>
<option name="modm:build:info.git">Info+Status</option>
<option name="modm:build:scons:cache_dir">$cache</option>
Expand Down
35 changes: 11 additions & 24 deletions tools/build_script_generator/scons/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ from os.path import join, relpath, isdir, exists
def init(module):
module.name = ":build:scons"
module.description = FileReader("module.md")
module.order = 10000 # do project-wide file generation last


def prepare(module, options):
Expand All @@ -30,10 +31,6 @@ def prepare(module, options):
PathOption(name="path.artifact", default="artifacts", absolute=True,
description=descr_path_artifact))

module.add_option(
StringOption(name="include_repos", default="",
description=descr_include_repos))

module.add_collector(
CallableCollector(name="flag_format",
description="Formatting compile flags for SCons"))
Expand Down Expand Up @@ -154,15 +151,8 @@ def post_build(env):
has_xpcc_generator = env.has_module(":communication:xpcc:generator")
has_image_source = len(env["::image.source"])
has_nanopb = env.has_module(":nanopb")

repositories = ["modm"]
for token in env["include_repos"].split(","):
repo = token.strip()
if repo in env.buildlog.repositories and isdir(env.real_outpath(repo, basepath=".")):
repositories.append(repo)
elif repo != "":
env.log.error(f"\"{repo}\" is not a valid repository!")

repositories = [p for p in env.buildlog.repositories if isdir(env.real_outpath(p, basepath="."))]
repositories.sort(key=lambda name: "0" if name == "modm" else name)
generated_paths = [join(env.relcwdoutpath(""), r) for r in repositories]

subs = env.query("::device")
Expand Down Expand Up @@ -218,7 +208,14 @@ def post_build(env):
if nflag: return nflag;
return '"{}"'.format(flag)

for repo in repositories:
# Generate SConscript files for each repository that doesn't already have one
repos_without_sconscript = repositories.copy()
for op in env.buildlog.operations:
repo, relpath = op.repository, env.relative_outpath(op.filename, op.repository)
if relpath == "SConscript" and repo in repos_without_sconscript:
repos_without_sconscript.remove(repo)

for repo in repos_without_sconscript:
files = []
repo_filter = lambda scope: scope.repository == repo
repo_flags = env.query("::collect_flags")(env, repo_filter)
Expand Down Expand Up @@ -248,7 +245,6 @@ def post_build(env):
"is_modm": repo == "modm",
})

# Generate library SConscript
env.outbasepath = repo
env.template("resources/SConscript.in", "SConscript",
filters={"flags_format": flags_format,
Expand Down Expand Up @@ -277,13 +273,4 @@ descr_path_artifact = """# Path to Artifact Store
The artifact folder contains ELF files named by their GNU build id hash. This
allows identification of firmware on the device via serial output and is useful
for archiving or post-mortem debugging.
"""

descr_include_repos = """# Include Additional Repositories
This should be a comma-separated list of repository names for which to generate
additional SConscript files. Note: `include_sconstruct` should generally be
disabled when using this option, as you will want to write a custom SConstruct.
!!! warning "This overwrites any existing `../[repo]/SConscript` files!"
"""

0 comments on commit eeedcef

Please sign in to comment.