* [patch net-next] tools: ynl-gen: use temporary file for rendering
@ 2023-08-18 11:19 Jiri Pirko
2023-08-18 21:38 ` Jakub Kicinski
2023-08-19 18:34 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Jiri Pirko @ 2023-08-18 11:19 UTC (permalink / raw)
To: netdev; +Cc: kuba, pabeni, davem, edumazet
From: Jiri Pirko <jiri@nvidia.com>
Currently any error during render leads to output an empty file.
That is quite annoying when using tools/net/ynl/ynl-regen.sh
which git greps files with content of "YNL-GEN.." and therefore ignores
empty files. So once you fail to regen, you have to checkout the file.
Avoid that by rendering to a temporary file first, only at the end
copy the content to the actual destination.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
tools/net/ynl/ynl-gen-c.py | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 5f39d2490655..bdff8dfc29c9 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -5,6 +5,8 @@ import argparse
import collections
import os
import re
+import shutil
+import tempfile
import yaml
from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, SpecEnumEntry
@@ -2304,7 +2306,7 @@ def main():
parser.add_argument('-o', dest='out_file', type=str)
args = parser.parse_args()
- out_file = open(args.out_file, 'w+') if args.out_file else os.sys.stdout
+ tmp_file = tempfile.TemporaryFile('w+') if args.out_file else os.sys.stdout
if args.header is None:
parser.error("--header or --source is required")
@@ -2329,7 +2331,7 @@ def main():
print(f'Message enum-model {parsed.msg_id_model} not supported for {args.mode} generation')
os.sys.exit(1)
- cw = CodeWriter(BaseNlLib(), out_file)
+ cw = CodeWriter(BaseNlLib(), tmp_file)
_, spec_kernel = find_kernel_root(args.spec)
if args.mode == 'uapi' or args.header:
@@ -2578,6 +2580,10 @@ def main():
if args.header:
cw.p(f'#endif /* {hdr_prot} */')
+ if args.out_file:
+ out_file = open(args.out_file, 'w+')
+ tmp_file.seek(0)
+ shutil.copyfileobj(tmp_file, out_file)
if __name__ == "__main__":
main()
--
2.41.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [patch net-next] tools: ynl-gen: use temporary file for rendering
2023-08-18 11:19 [patch net-next] tools: ynl-gen: use temporary file for rendering Jiri Pirko
@ 2023-08-18 21:38 ` Jakub Kicinski
2023-08-19 18:34 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2023-08-18 21:38 UTC (permalink / raw)
To: Jiri Pirko; +Cc: netdev, pabeni, davem, edumazet
On Fri, 18 Aug 2023 13:19:27 +0200 Jiri Pirko wrote:
> From: Jiri Pirko <jiri@nvidia.com>
>
> Currently any error during render leads to output an empty file.
> That is quite annoying when using tools/net/ynl/ynl-regen.sh
> which git greps files with content of "YNL-GEN.." and therefore ignores
> empty files. So once you fail to regen, you have to checkout the file.
>
> Avoid that by rendering to a temporary file first, only at the end
> copy the content to the actual destination.
>
> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Neat! I thought this would be harder to implement.
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch net-next] tools: ynl-gen: use temporary file for rendering
2023-08-18 11:19 [patch net-next] tools: ynl-gen: use temporary file for rendering Jiri Pirko
2023-08-18 21:38 ` Jakub Kicinski
@ 2023-08-19 18:34 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-19 18:34 UTC (permalink / raw)
To: Jiri Pirko; +Cc: netdev, kuba, pabeni, davem, edumazet
Hello:
This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:
On Fri, 18 Aug 2023 13:19:27 +0200 you wrote:
> From: Jiri Pirko <jiri@nvidia.com>
>
> Currently any error during render leads to output an empty file.
> That is quite annoying when using tools/net/ynl/ynl-regen.sh
> which git greps files with content of "YNL-GEN.." and therefore ignores
> empty files. So once you fail to regen, you have to checkout the file.
>
> [...]
Here is the summary with links:
- [net-next] tools: ynl-gen: use temporary file for rendering
https://git.kernel.org/netdev/net-next/c/f65f305ae008
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-19 18:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-18 11:19 [patch net-next] tools: ynl-gen: use temporary file for rendering Jiri Pirko
2023-08-18 21:38 ` Jakub Kicinski
2023-08-19 18:34 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).