BaseTools/build.py: set BUILD_TIME_EPOCH if not already in environment

Set BUILD_TIME_EPOCH to the current UTC timestamp if not already present
in the environment.

Use the resulting value to print the "Build start time:" message.

Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
This commit is contained in:
Leif Lindholm
2025-07-03 19:37:42 +01:00
committed by mergify[bot]
parent 5ca97bf64f
commit fcc568ca6e

View File

@ -5,6 +5,7 @@
# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>
# Copyright (c) 2020 - 2021, ARM Limited. All rights reserved.<BR>
# Copyright (c) 2025 Qualcomm Technologies, Inc. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@ -71,6 +72,25 @@ gSupportedTarget = ['all', 'genc', 'genmake', 'modules', 'libraries', 'fds', 'cl
TemporaryTablePattern = re.compile(r'^_\d+_\d+_[a-fA-F0-9]+$')
TmpTableDict = {}
## Set build time
#
# Check if SOURCE_DATE_EPOCH is set in environment, or set it to current timestamp.
# Return the resulting value.
#
# @retval float The time in seconds since the epoch as a floating-point number.
#
def GetBuildEpoch():
# Set SOURCE_DATE_EPOCH to the current time if not already set by environment
if "SOURCE_DATE_EPOCH" not in os.environ:
BuildEpoch = time.time()
BuildEpochString = str(int(BuildEpoch))
EdkLogger.quiet("SOURCE_DATE_EPOCH not set - using %s" % (BuildEpochString))
os.environ["SOURCE_DATE_EPOCH"] = BuildEpochString
else:
BuildEpoch = float(os.environ["SOURCE_DATE_EPOCH"])
return BuildEpoch
## Check environment variables
#
# Check environment variables that must be set for build. Currently they are
@ -2597,7 +2617,8 @@ def Main():
GlobalData.gIsWindows = False
EdkLogger.quiet("Build environment: %s" % platform.platform())
EdkLogger.quiet(time.strftime("Build start time: %H:%M:%S, %b.%d %Y\n", time.localtime()));
BuildStartTime = GetBuildEpoch()
EdkLogger.quiet(time.strftime("Build start time: %H:%M:%S, %b.%d %Y\n", time.localtime(BuildStartTime)));
ReturnCode = 0
MyBuild = None
BuildError = True