diff options
author | Ole Troan <otroan@employees.org> | 2024-06-19 11:31:30 +0200 |
---|---|---|
committer | Ole Troan <otroan@employees.org> | 2024-06-19 13:18:36 +0200 |
commit | ed61b20ad7bd439f58393ae19694aa09c4f44ee0 (patch) | |
tree | 9b1462dc90747f155de7bcf84576bd2e769d92ff /src/tools | |
parent | e95687b0d6f692ed0b27e0ff0876fbe61be6c4a3 (diff) |
build: vppapigen dependency handling
Add dependency generation to the vppapigen compiler, so that
when an API file depends on another, that's registered as a dependency
with the build system.
Add a build dependency on vppapigen submodules so that all api files
are regenerated if the compiler itself changes.
Type: improvement
Change-Id: I392853754129778ef15532d1b04813786b943b44
Signed-off-by: Ole Troan <otroan@employees.org>
Diffstat (limited to 'src/tools')
-rwxr-xr-x | src/tools/vppapigen/vppapigen.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py index 2b0ce9999d7..0bed578eb93 100755 --- a/src/tools/vppapigen/vppapigen.py +++ b/src/tools/vppapigen/vppapigen.py @@ -9,6 +9,7 @@ import os from subprocess import Popen, PIPE import ply.lex as lex import ply.yacc as yacc +from io import TextIOWrapper assert sys.version_info >= (3, 5), "Not supported Python version: {}".format( sys.version @@ -1166,6 +1167,21 @@ def foldup_crcs(s): f.crc = foldup_blocks(f.block, binascii.crc32(f.crc) & 0xFFFFFFFF) +def write_dependencies(output_file, dependency_file, imports): + r = [] + for i in imports: + for d in dirlist: + f = os.path.abspath(os.path.join(d, i.filename)) + if os.path.exists(f): + r.append(f) + with open(dependency_file, "w", encoding="utf8") as f: + print(f"{output_file}: \\", file=f) + for i in r[:-1]: + print(f" {i} \\", file=f) + if imports: + print(f" {r[-1]}", file=f) + + def run_vppapigen( input_file=None, output=sys.stdout, @@ -1176,6 +1192,7 @@ def run_vppapigen( outputdir=None, pluginpath="", git_revision=None, + dependency_file=None, ): # reset globals dirlist.clear() @@ -1256,6 +1273,9 @@ def run_vppapigen( imports = parser.process_imports(parsed_objects, False, result) s["imported"] = parser.process(imports) + if dependency_file and isinstance(output, TextIOWrapper): + write_dependencies(output.name, dependency_file[0], s["Import"]) + # Add msg_id field s["Define"] = add_msg_id(s["Define"]) @@ -1324,6 +1344,7 @@ def main(): cliparser.add_argument( "--git-revision", help="Git revision to use for opening files" ) + cliparser.add_argument("-MF", nargs=1, help="Dependency file") args = cliparser.parse_args() return run_vppapigen( @@ -1336,6 +1357,7 @@ def main(): pluginpath=args.pluginpath, git_revision=args.git_revision, output=args.output, + dependency_file=args.MF, ) |