tools: ynl-gen: fix uAPI generation after tempfile changes
authorJakub Kicinski <kuba@kernel.org>
Thu, 24 Aug 2023 21:24:31 +0000 (14:24 -0700)
committerJakub Kicinski <kuba@kernel.org>
Sat, 26 Aug 2023 01:56:48 +0000 (18:56 -0700)
commita02430c06f56931675f19a914b11a960607b2505
tree1c1d9f35fbe0312b0161120354e5644a8f1b055e
parentf5e17b471fa88e1e6b430c5df383a04c8caf3707
tools: ynl-gen: fix uAPI generation after tempfile changes

We use a tempfile for code generation, to avoid wiping the target
file out if the code generator crashes. File contents are copied
from tempfile to actual destination at the end of main().

uAPI generation is relatively simple so when generating the uAPI
header we return from main() early, and never reach the "copy code
over" stage. Since commit under Fixes uAPI headers are not updated
by ynl-gen.

Move the copy/commit of the code into CodeWriter, to make it
easier to call at any point in time. Hook it into the destructor
to make sure we don't miss calling it.

Fixes: f65f305ae008 ("tools: ynl-gen: use temporary file for rendering")
Link: https://lore.kernel.org/r/20230824212431.1683612-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/net/ynl/ynl-gen-c.py