wscript: fix git version generation for tarballs

This commit is contained in:
Nedko Arnaudov 2023-11-17 22:07:33 +02:00
parent ec3c354b4e
commit b172dcb250
1 changed files with 23 additions and 15 deletions

38
wscript
View File

@ -23,9 +23,11 @@ from __future__ import print_function
import os
import shutil
import sys
import re
from waflib import Logs, Options, TaskGen
from waflib import Context
from waflib import Scripting
from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
from waftoolchainflags import WafToolchainFlags
@ -749,21 +751,25 @@ def build_drivers(bld):
def git_ver(self):
bld = self.generator.bld
header = self.outputs[0].abspath()
if os.access('./version.h', os.R_OK):
header = os.path.join(os.getcwd(), out, "version.h")
shutil.copy('./version.h', header)
data = open(header).read()
m = re.match(r'^#define GIT_VERSION "([^"]*)"$', data)
if m != None:
self.ver = m.group(1)
Logs.pprint('BLUE', "tarball from git revision " + self.ver)
else:
self.ver = "tarball"
return
if type(self) == Scripting.Dist:
header = "./version.h"
bld = self
else:
bld = self.generator.bld
header = self.outputs[0].abspath()
if os.access('./version.h', os.R_OK):
#header = os.path.join(os.getcwd(), out, "version.h")
shutil.copy('./version.h', header)
data = open(header).read()
m = re.match(r'^#define GIT_VERSION "([^"]*)"$', data)
if m != None:
self.ver = m.group(1)
Logs.pprint('BLUE', "tarball from git revision " + self.ver)
else:
self.ver = "tarball"
return
if bld.srcnode.find_node('.git'):
if os.access('./.git', os.R_OK):
self.ver = bld.cmd_and_log("LANG= git rev-parse HEAD", quiet=Context.BOTH).splitlines()[0]
if bld.cmd_and_log("LANG= git diff-index --name-only HEAD", quiet=Context.BOTH).splitlines():
self.ver += "-dirty"
@ -776,7 +782,6 @@ def git_ver(self):
fi.write('#define GIT_VERSION "%s"\n' % self.ver)
fi.close()
def build(bld):
bld(rule=git_ver, target='version.h', update_outputs=True, always=True, ext_out=['.h'])
if not bld.variant and bld.env['BUILD_WITH_32_64']:
@ -863,3 +868,6 @@ def build(bld):
def mm_hook(self, node):
"""Alias .mm files to be compiled the same as .cpp files, gcc will do the right thing."""
return self.create_compiled_task('cxx', node)
def dist(ctx):
git_ver(ctx)