Skip to content

Commit a115b92

Browse files
committed
tools: ynl: don't skip regeneration from make targets
Commit 2b7ac0c ("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. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 9cf9b57 commit a115b92

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

tools/net/ynl/ynl-gen-c.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,9 @@ def __init__(self, cw, family, ku_space, op, op_mode, attr_set=None):
11641164

11651165

11661166
class CodeWriter:
1167-
def __init__(self, nlib, out_file=None):
1167+
def __init__(self, nlib, out_file=None, overwrite=True):
11681168
self.nlib = nlib
1169+
self._overwrite = overwrite
11691170

11701171
self._nl = False
11711172
self._block_end = False
@@ -1186,8 +1187,9 @@ def close_out_file(self):
11861187
return
11871188
# Avoid modifying the file if contents didn't change
11881189
self._out.flush()
1189-
if os.path.isfile(self._out_file) and filecmp.cmp(self._out.name, self._out_file, shallow=False):
1190-
return
1190+
if not self._overwrite and os.path.isfile(self._out_file):
1191+
if filecmp.cmp(self._out.name, self._out_file, shallow=False):
1192+
return
11911193
with open(self._out_file, 'w+') as out_file:
11921194
self._out.seek(0)
11931195
shutil.copyfileobj(self._out, out_file)
@@ -2516,6 +2518,8 @@ def main():
25162518
parser.add_argument('--header', dest='header', action='store_true', default=None)
25172519
parser.add_argument('--source', dest='header', action='store_false')
25182520
parser.add_argument('--user-header', nargs='+', default=[])
2521+
parser.add_argument('--cmp-out', action='store_true', default=None,
2522+
help='Do not overwrite the output file if the new output is identical to the old')
25192523
parser.add_argument('--exclude-op', action='append', default=[])
25202524
parser.add_argument('-o', dest='out_file', type=str, default=None)
25212525
args = parser.parse_args()
@@ -2543,7 +2547,7 @@ def main():
25432547
print(f'Message enum-model {parsed.msg_id_model} not supported for {args.mode} generation')
25442548
os.sys.exit(1)
25452549

2546-
cw = CodeWriter(BaseNlLib(), args.out_file)
2550+
cw = CodeWriter(BaseNlLib(), args.out_file, overwrite=(not args.cmp_out))
25472551

25482552
_, spec_kernel = find_kernel_root(args.spec)
25492553
if args.mode == 'uapi' or args.header:

tools/net/ynl/ynl-regen.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ for f in $files; do
3030
fi
3131

3232
echo -e "\tGEN ${params[2]}\t$f"
33-
$TOOL --mode ${params[2]} --${params[3]} --spec $KDIR/${params[0]} \
34-
$args -o $f
33+
$TOOL --cmp-out --mode ${params[2]} --${params[3]} \
34+
--spec $KDIR/${params[0]} $args -o $f
3535
done
3636

3737
popd >>/dev/null

0 commit comments

Comments
 (0)