From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
Jakub Kicinski <kuba@kernel.org>,
sdf@google.com
Subject: [PATCH net-next 4/4] tools: ynl: don't skip regeneration from make targets
Date: Wed, 29 Nov 2023 11:36:22 -0800 [thread overview]
Message-ID: <20231129193622.2912353-5-kuba@kernel.org> (raw)
In-Reply-To: <20231129193622.2912353-1-kuba@kernel.org>
Commit 2b7ac0c87d98 ("tools: ynl-gen: don't touch the output file if
content is the same") is working too well. It was added so that
ynl-regen -f doesn't make us rebuild half of the kernel, if there
are no actual changes in any generated code.
When ynl-gen-c is called by make, however, we're better off trusting
make's tracking and overwrite the file. Otherwise if output is identical
we won't update file timestamps and make will retry code gen on every
invocation.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: sdf@google.com
---
tools/net/ynl/ynl-gen-c.py | 12 ++++++++----
tools/net/ynl/ynl-regen.sh | 4 ++--
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index cbbda276f6d1..ba1c3611c6fa 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -1164,8 +1164,9 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
class CodeWriter:
- def __init__(self, nlib, out_file=None):
+ def __init__(self, nlib, out_file=None, overwrite=True):
self.nlib = nlib
+ self._overwrite = overwrite
self._nl = False
self._block_end = False
@@ -1186,8 +1187,9 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
return
# Avoid modifying the file if contents didn't change
self._out.flush()
- if os.path.isfile(self._out_file) and filecmp.cmp(self._out.name, self._out_file, shallow=False):
- return
+ if not self._overwrite and os.path.isfile(self._out_file):
+ if filecmp.cmp(self._out.name, self._out_file, shallow=False):
+ return
with open(self._out_file, 'w+') as out_file:
self._out.seek(0)
shutil.copyfileobj(self._out, out_file)
@@ -2516,6 +2518,8 @@ _C_KW = {
parser.add_argument('--header', dest='header', action='store_true', default=None)
parser.add_argument('--source', dest='header', action='store_false')
parser.add_argument('--user-header', nargs='+', default=[])
+ parser.add_argument('--cmp-out', action='store_true', default=None,
+ help='Do not overwrite the output file if the new output is identical to the old')
parser.add_argument('--exclude-op', action='append', default=[])
parser.add_argument('-o', dest='out_file', type=str, default=None)
args = parser.parse_args()
@@ -2543,7 +2547,7 @@ _C_KW = {
print(f'Message enum-model {parsed.msg_id_model} not supported for {args.mode} generation')
os.sys.exit(1)
- cw = CodeWriter(BaseNlLib(), args.out_file)
+ cw = CodeWriter(BaseNlLib(), args.out_file, overwrite=(not args.cmp_out))
_, spec_kernel = find_kernel_root(args.spec)
if args.mode == 'uapi' or args.header:
diff --git a/tools/net/ynl/ynl-regen.sh b/tools/net/ynl/ynl-regen.sh
index bdba24066cf1..a37304dcc88e 100755
--- a/tools/net/ynl/ynl-regen.sh
+++ b/tools/net/ynl/ynl-regen.sh
@@ -30,8 +30,8 @@ for f in $files; do
fi
echo -e "\tGEN ${params[2]}\t$f"
- $TOOL --mode ${params[2]} --${params[3]} --spec $KDIR/${params[0]} \
- $args -o $f
+ $TOOL --cmp-out --mode ${params[2]} --${params[3]} \
+ --spec $KDIR/${params[0]} $args -o $f
done
popd >>/dev/null
--
2.43.0
next prev parent reply other threads:[~2023-11-29 19:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-29 19:36 [PATCH net-next 0/4] tools: ynl: fixes for the page-pool sample and the generation process Jakub Kicinski
2023-11-29 19:36 ` [PATCH net-next 1/4] tools: ynl: fix build of the page-pool sample Jakub Kicinski
2023-11-29 19:36 ` [PATCH net-next 2/4] tools: ynl: make sure we use local headers for page-pool Jakub Kicinski
2023-11-29 19:36 ` [PATCH net-next 3/4] tools: ynl: order building samples after generated code Jakub Kicinski
2023-11-29 19:36 ` Jakub Kicinski [this message]
2023-11-30 0:06 ` [PATCH net-next 0/4] tools: ynl: fixes for the page-pool sample and the generation process Jakub Kicinski
2023-11-30 0:10 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231129193622.2912353-5-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).