diff --git a/tests/data/valid/scenarios/native/yambs.yaml b/tests/data/valid/scenarios/native/yambs.yaml index d7e5296..55eacf4 100644 --- a/tests/data/valid/scenarios/native/yambs.yaml +++ b/tests/data/valid/scenarios/native/yambs.yaml @@ -22,6 +22,8 @@ variants: debug: suffix: &gcc_version "-13" + targets: [apps, lib, uf2s] + opt: suffix: *gcc_version diff --git a/yambs/data/schemas/Native.yaml b/yambs/data/schemas/Native.yaml index bca0bbd..4cc4308 100644 --- a/yambs/data/schemas/Native.yaml +++ b/yambs/data/schemas/Native.yaml @@ -36,3 +36,4 @@ properties: uf2_family: type: string + default: "" diff --git a/yambs/data/templates/native_rules.ninja.j2 b/yambs/data/templates/native_rules.ninja.j2 index b0be966..22476e5 100644 --- a/yambs/data/templates/native_rules.ninja.j2 +++ b/yambs/data/templates/native_rules.ninja.j2 @@ -27,9 +27,11 @@ rule hex rule dump command = ${toolchain_prefix}objdump -D $in > $out +{% if uf2_family %} rule uf2 - command = mbs uf2conv $uf2conv_args -o $out $in + command = mbs uf2conv -f {{uf2_family}} -o $out $in +{% endif %} rule ar command = ar rcs $out $in diff --git a/yambs/environment/native.py b/yambs/environment/native.py index 0051595..7be4930 100644 --- a/yambs/environment/native.py +++ b/yambs/environment/native.py @@ -139,6 +139,36 @@ def write_static_library_rule( return lib + def _write_app_phony_targets( + self, stream: TextIO, elfs: Dict[Path, Path], uf2_family: str = None + ) -> None: + """Write phony targets for all variants.""" + + elfs_list = list(elfs.values()) + + if elfs_list: + line = "build ${variant}_apps: phony " + offset = " " * len(line) + + stream.write(line + str(elfs_list[0])) + for elf in elfs_list[1:]: + write_continuation(stream, offset) + stream.write(str(elf)) + stream.write(linesep) + + if uf2_family: + # Create uf2 phony. + line = "build ${variant}_uf2s: phony " + offset = " " * len(line) + + uf2s = [x.with_suffix(".uf2") for x in elfs_list] + + stream.write(line + str(uf2s[0])) + for elf in uf2s[1:]: + write_continuation(stream, offset) + stream.write(str(elf)) + stream.write(linesep) + def write_app_rules( self, stream: TextIO, outputs: Set[Path], uf2_family: str = None ) -> Dict[Path, Path]: @@ -168,6 +198,24 @@ def write_app_rules( stream.write(linesep + linesep) + # Write rules for other kinds of outputs. + for output in ["bin", "hex", "dump"]: + stream.write( + f"build {elf.with_suffix('.' + output)}: {output} {elf}" + ) + stream.write(linesep) + + if uf2_family: + stream.write( + ( + f"build {elf.with_suffix('.uf2')}: " + f"uf2 {elf.with_suffix('.hex')}" + ) + ) + stream.write(linesep) + + stream.write(linesep) + # Add a phony target for creating a static library. if outputs: stream.write( @@ -177,20 +225,7 @@ def write_app_rules( + linesep ) - line = "build ${variant}_apps: phony " - offset = " " * len(line) - - elfs_list = list(elfs.values()) - if elfs_list: - stream.write(line + str(elfs_list[0])) - for elf in elfs_list[1:]: - write_continuation(stream, offset) - stream.write(str(elf)) - stream.write(linesep) - - # need to actually handle this - if uf2_family is not None: - print(uf2_family) + self._write_app_phony_targets(stream, elfs, uf2_family=uf2_family) return elfs