From 8bb743a494216c89b7d41b295f1cca0099b3001b Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Mon, 22 Jan 2024 15:38:19 +0000 Subject: [PATCH] [util/reggen] Do not generate stamping information if not available If stamping is disable, version_stamp will be an empty dictionary and the code will print something like ``` // Generated register constants for rv_plic. // Built for // https://github.com/lowRISC/opentitan/tree/ // Tree status: // Build date: ``` This is unhelpful and still prints the current time which is defeats the point of not stamping. The new code will not print anything when a piece of information is not available. Signed-off-by: Amaury Pouly --- util/reggen/gen_tock.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/util/reggen/gen_tock.py b/util/reggen/gen_tock.py index 13a8696249ce64..009de52b09dbf4 100644 --- a/util/reggen/gen_tock.py +++ b/util/reggen/gen_tock.py @@ -384,8 +384,6 @@ def gen_tock(block: IpBlock, outfile: TextIO, src_file: Optional[str], fieldstr = fieldout.getvalue() fieldout.close() - tm = int(version_stamp.get('BUILD_TIMESTAMP', 0)) - dt = datetime.utcfromtimestamp(tm) if tm else datetime.utcnow() # Opensource council has approved dual-licensing the generated files under # both Apache and MIT licenses. # Since these generated files are meant to be imported into the Tock @@ -395,17 +393,20 @@ def gen_tock(block: IpBlock, outfile: TextIO, src_file: Optional[str], "// Licensed under the Apache License, Version 2.0 or the MIT License.\n" ) genout(outfile, "// SPDX-License-Identifier: Apache-2.0 OR MIT\n") - genout(outfile, "// Copyright lowRISC contributors {}.\n", dt.year) + genout(outfile, "// Copyright lowRISC contributors.\n") genout(outfile, '\n') genout(outfile, '// Generated register constants for {}.\n', block.name) - genout(outfile, '// Built for {}\n', - version_stamp.get('BUILD_GIT_VERSION', '')) - genout(outfile, '// https://github.com/lowRISC/opentitan/tree/{}\n', - version_stamp.get('BUILD_SCM_REVISION', '')) - genout(outfile, '// Tree status: {}\n', - version_stamp.get('BUILD_SCM_STATUS', '')) - genout(outfile, '// Build date: {}\n\n', dt.isoformat()) + if 'BUILD_GIT_VERSION' in version_stamp: + genout(outfile, '// Built for {}\n', version_stamp['BUILD_GIT_VERSION']) + if 'BUILD_SCM_REVISION' in version_stamp: + genout(outfile, '// https://github.com/lowRISC/opentitan/tree/{}\n', version_stamp['BUILD_SCM_REVISION']) + if 'BUILD_SCM_STATUS' in version_stamp: + genout(outfile, '// Tree status: {}\n', version_stamp['BUILD_SCM_STATUS']) + if 'BUILD_TIMESTAMP' in version_stamp: + tm = int(version_stamp['BUILD_TIMESTAMP']) + dt = datetime.utcfromtimestamp(tm) + genout(outfile, '// Build date: {}\n\n', dt.isoformat()) if src_file: genout(outfile, '// Original reference file: {}\n', src_file)