buildcommands: Don't attach hostname and build date to version on a clean build

Most builds will be direclty from git - removing the hostname and
build date should permit reproducible binaries in that common case.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-04-22 11:34:40 -04:00
parent acd94909bc
commit 947ffe706d
1 changed files with 10 additions and 6 deletions

View File

@ -466,14 +466,18 @@ def git_version():
logging.debug("Got git version: %s" % (repr(ver),)) logging.debug("Got git version: %s" % (repr(ver),))
return ver return ver
def build_version(extra): def build_version(extra, cleanbuild):
version = git_version() version = git_version()
if not version: if not version:
cleanbuild = False
version = "?" version = "?"
elif 'dirty' in version:
cleanbuild = False
if not cleanbuild:
btime = time.strftime("%Y%m%d_%H%M%S") btime = time.strftime("%Y%m%d_%H%M%S")
hostname = socket.gethostname() hostname = socket.gethostname()
version = "%s-%s-%s%s" % (version, btime, hostname, extra) version = "%s-%s-%s" % (version, btime, hostname)
return version return version + extra
# Run "tool --version" for each specified tool and extract versions # Run "tool --version" for each specified tool and extract versions
def tool_versions(tools): def tool_versions(tools):
@ -515,7 +519,7 @@ class HandleVersions:
data['build_versions'] = self.toolstr data['build_versions'] = self.toolstr
def generate_code(self, options): def generate_code(self, options):
cleanbuild, self.toolstr = tool_versions(options.tools) cleanbuild, self.toolstr = tool_versions(options.tools)
self.version = build_version(options.extra) self.version = build_version(options.extra, cleanbuild)
sys.stdout.write("Version: %s\n" % (self.version,)) sys.stdout.write("Version: %s\n" % (self.version,))
return "\n// version: %s\n// build_versions: %s\n" % ( return "\n// version: %s\n// build_versions: %s\n" % (
self.version, self.toolstr) self.version, self.toolstr)