From 3314a23d06e25ed2fbf8b737de6d3f230d327049 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 24 Sep 2021 12:42:17 -0400 Subject: [PATCH 01/10] Record version information in DISTINFO --- wscript | 186 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 136 insertions(+), 50 deletions(-) diff --git a/wscript b/wscript index 0b2d45c5b..099c23c87 100644 --- a/wscript +++ b/wscript @@ -11,10 +11,23 @@ from waflib import Task from waflib import Utils from waflib import TaskGen -APPNAME = "HSTCAL" - top = '.' out = 'build.' + platform.platform() +out_include_dir = os.path.abspath(os.path.join(out, 'include')) + +APPNAME = "hstcal" +VERSION = "UNKNOWN" +BRANCH = "UNKNOWN" +COMMIT = "UNKNOWN" + +# DISTINFO controls distribution archive versioning +DISTINFO = os.path.abspath(os.path.join(top, "DISTINFO")) +DISTINFO_KEYS = [ + "APPNAME", + "VERSION", + "BRANCH", + "COMMIT", +] # A list of subdirectories to recurse into SUBDIRS = [ @@ -29,9 +42,6 @@ SUBDIRS = [ 'tables', ] -# Have 'waf dist' create tar.gz files, rather than tar.bz2 files -Scripting.g_gz = 'gz' - # Have gcc supersede clang from waflib.Tools.compiler_c import c_compiler c_compiler['darwin'] = ['gcc', 'clang'] @@ -134,56 +144,120 @@ def call(cmd): return None + +def _gen_distinfo(data): + """Generates a DISTINFO file + data: [["key", "value"], ["key", "value"], ...] + """ + + # Generate DISTINFO file UNLESS we are building from an archive + if os.path.exists('.git') and os.path.exists(DISTINFO): + return + + # Write data pairs to DISTINFO file + with open(DISTINFO, 'w+') as fp: + for key_dist in DISTINFO_KEYS: + for name, value in data: + if name == key_dist: + fp.write("{}:{}\n".format(name, value)) + + +def _get_distinfo(): + """Creates a DISTINFO file using information from git + """ + global APPNAME + global VERSION + global BRANCH + global COMMIT + + # Die silently when there's nothing to do + if not os.path.exists(DISTINFO): + return + + with open(DISTINFO, 'r') as fp: + for record in fp: + record = record.strip() + if not record: + continue + + name, value = record.split(":", 1) + for key_dist in DISTINFO_KEYS: + if name == key_dist: + if name == "APPNAME": + APPNAME = value + if name == "VERSION": + VERSION = value + if name == "BRANCH": + BRANCH = value + if name == "COMMIT": + COMMIT = value + + def _get_git_details(ctx): + global APPNAME + global VERSION + global BRANCH + global COMMIT + + # Handle building from a archive + if not os.path.exists(".git") and os.path.exists(DISTINFO): + print("Using DISTINFO file") + _get_distinfo() + return + tmp = call('git describe --dirty --abbrev=7') if tmp: - ctx.env.gitTag = tmp + VERSION = tmp tmp = call('git rev-parse HEAD') if tmp: - ctx.env.gitCommit = tmp + COMMIT = tmp tmp = call('git rev-parse --abbrev-ref HEAD') if tmp: - ctx.env.gitBranch = tmp + BRANCH = tmp + + +def _gen_version_header(ctx): + """Generate a C header to provide versioning data to hstcal's programs + """ + data = [ + ["APPNAME", APPNAME], + ["VERSION", VERSION], + ["BRANCH", BRANCH], + ["COMMIT", COMMIT], + ] + _gen_distinfo(data) + + filename = os.path.join(out_include_dir, 'version.h') + label = "HEADER_" + os.path.basename(filename).replace(".", "_").upper() + + os.makedirs(out_include_dir, exist_ok=True) + with open(filename, 'w+') as hdr: + hdr.write("#ifndef {}\n".format(label)) + hdr.write("#define {}\n".format(label)) + for key, value in data: + hdr.write("#define {} \"{}\"\n".format(key, value)) + hdr.write("#endif /* {} */\n".format(label)) + def _use_git_details(ctx): _get_git_details(ctx) + # Include generated header(s) + ctx.env.append_value('CFLAGS', '-I{}'.format(out_include_dir)) + + # Inform user ctx.start_msg("Building app") ctx.end_msg(APPNAME, _warn_color(APPNAME, "UNKNOWN")) ctx.start_msg("Version") - ctx.end_msg(ctx.env.gitTag, _warn_color(ctx.env.gitTag, "UNKNOWN")) + ctx.end_msg(VERSION, _warn_color(VERSION, "UNKNOWN")) ctx.start_msg("git HEAD commit") - ctx.end_msg(ctx.env.gitCommit, _warn_color(ctx.env.gitCommit, "UNKNOWN")) + ctx.end_msg(COMMIT, _warn_color(COMMIT, "UNKNOWN")) ctx.start_msg("git branch") - ctx.end_msg(ctx.env.gitBranch, _warn_color(ctx.env.gitBranch, "UNKNOWN")) - - ctx.env.append_value('CFLAGS', '-D APPNAME="{0}"'.format(APPNAME)) - ctx.env.append_value('CFLAGS', '-D VERSION="{0}"'.format(ctx.env.gitTag)) - ctx.env.append_value('CFLAGS', '-D BRANCH="{0}"'.format(ctx.env.gitBranch)) - ctx.env.append_value('CFLAGS', '-D COMMIT="{0}"'.format(ctx.env.gitCommit)) - -def _is_same_git_details(ctx, diffList): - oldTag = ctx.env.gitTag[:] - oldCommit = ctx.env.gitCommit[:] - oldBranch = ctx.env.gitBranch[:] + ctx.end_msg(BRANCH, _warn_color(BRANCH, "UNKNOWN")) - _get_git_details(ctx) - - isSame = True - - if ctx.env.gitTag != oldTag: - diffList.append("'{0}' -> '{1}'".format(oldTag, ctx.env.gitTag)) - isSame = False - if ctx.env.gitCommit != oldCommit: - diffList.append("'{0}' -> '{1}'\n".format(oldCommit, ctx.env.gitCommit)) - isSame = False - if ctx.env.gitBranch != oldBranch: - diffList.append("'{0}' -> '{1}'\n".format(oldBranch, ctx.env.gitBranch)) - isSame = False - return isSame def _check_mac_osx_version(floor_version): ''' @@ -300,10 +374,6 @@ def configure(conf): # NOTE: All of the variables in conf.env are defined for use by # wscript files in subdirectories. - conf.env.gitTag = "UNKNOWN" - conf.env.gitCommit = "UNKNOWN" - conf.env.gitBranch = "UNKNOWN" - # Read in options from a file. The file is just a set of # commandline arguments in the same syntax. May be spread across # multiple lines. @@ -318,6 +388,7 @@ def configure(conf): fd.close() _use_git_details(conf) + _gen_version_header(conf) # Load C compiler support conf.load('compiler_c') @@ -353,7 +424,7 @@ def configure(conf): _setup_openmp(conf) - _determine_sizeof_int(conf) + #_determine_sizeof_int(conf) if conf.check_cc(cflags='-std=gnu99'): conf.env.append_value('CFLAGS', '-std=gnu99') @@ -401,17 +472,32 @@ Press any key to continue or Ctrl+c to abort...\033[0m""" conf.end_msg(' '.join(conf.env['LDFLAGS']) or None) -def build(bld): - if bld.cmd == 'build': - diffList = [] - if not _is_same_git_details(bld, diffList): - diffString = '' - for item in diffList: - diffString = diffString + item + '\n' - bld.fatal("ERROR: git details differ between current source \ -tree and build configuration. Please run 'configure' again to \ -update the build configuration.\n{0}".format(diffString)) +def dist(ctx): + ctx.algo = 'tar.gz' + + # Manually include project files in the archive + ctx.files = ctx.path.ant_glob('**/*', excl=[ + '.git*', + '.waf*', + '.lock-*', + 'Makefile', + '__pycache__', + '**/__pycache__', + '.cache', + '**/.cache', + out, + 'bin.*', + '*.tar.*', + '*.zip']) + + # Update version information + _get_git_details(ctx) + + # call 'waf dist' directly to generate an archive + Scripting.dist(ctx) + +def build(bld): bld(name='lib', always=True) bld(name='test', always=True) From 57f53f0678613c1c503f162c102f9ee1666e67d4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 24 Sep 2021 12:42:38 -0400 Subject: [PATCH 02/10] Use generated version header --- include/hstcalversion.h | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/include/hstcalversion.h b/include/hstcalversion.h index d1cad0311..77e416a7a 100644 --- a/include/hstcalversion.h +++ b/include/hstcalversion.h @@ -1,17 +1,7 @@ #ifndef HSTCALVERSION_INCL #define HSTCALVERSION_INCL -#ifndef VERSION -#define VERSION "UNKNOWN" -#endif - -#ifndef BRANCH -#define BRANCH "UNKNOWN" -#endif - -#ifndef COMMIT -#define COMMIT "UNKNOWN" -#endif +#include "version.h" char * getVersionInfo(char ** buffer); char * sprintfGitInfo(char ** buffer); From fefa7965a8458d0f46b4c5d2b63b54a79dd225f7 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 24 Sep 2021 12:42:53 -0400 Subject: [PATCH 03/10] Ignore generated files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index c53e1f342..de9919391 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +DISTINFO +*.tar.* .lock-waf* .waf* bin.* From 621f125c310d4591539ae004b88f5549feb6ffb6 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 24 Sep 2021 15:30:06 -0400 Subject: [PATCH 04/10] Fix wording --- wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wscript b/wscript index 099c23c87..7f8730eef 100644 --- a/wscript +++ b/wscript @@ -163,7 +163,7 @@ def _gen_distinfo(data): def _get_distinfo(): - """Creates a DISTINFO file using information from git + """Extract data from the DISTINFO file """ global APPNAME global VERSION From 6aa3aedf03f278755b21efa07f9c593f1e3e39dc Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 27 Sep 2021 09:55:28 -0400 Subject: [PATCH 05/10] Enable distcheck target Fix not continuously updating the DISTINFO file when in a repository --- wscript | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wscript b/wscript index 7f8730eef..65b958e20 100644 --- a/wscript +++ b/wscript @@ -151,7 +151,7 @@ def _gen_distinfo(data): """ # Generate DISTINFO file UNLESS we are building from an archive - if os.path.exists('.git') and os.path.exists(DISTINFO): + if not os.path.exists('.git') and os.path.exists(DISTINFO): return # Write data pairs to DISTINFO file @@ -472,7 +472,7 @@ Press any key to continue or Ctrl+c to abort...\033[0m""" conf.end_msg(' '.join(conf.env['LDFLAGS']) or None) -def dist(ctx): +def _dist_setup(ctx): ctx.algo = 'tar.gz' # Manually include project files in the archive @@ -493,10 +493,17 @@ def dist(ctx): # Update version information _get_git_details(ctx) +def dist(ctx): + _dist_setup(ctx) # call 'waf dist' directly to generate an archive Scripting.dist(ctx) +def distcheck(ctx): + _dist_setup(ctx) + Scripting.distcheck(ctx) + + def build(bld): bld(name='lib', always=True) bld(name='test', always=True) From 812d39bff37c8cd132e5e374a8f4b75d39d37394 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 27 Sep 2021 10:07:33 -0400 Subject: [PATCH 06/10] Increased verbosity of DISTINFO actions --- wscript | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wscript b/wscript index 65b958e20..2016e8f3a 100644 --- a/wscript +++ b/wscript @@ -152,9 +152,16 @@ def _gen_distinfo(data): # Generate DISTINFO file UNLESS we are building from an archive if not os.path.exists('.git') and os.path.exists(DISTINFO): + print("Building from distribution archive") return + # Remove previous edition of the file + if os.path.exists(DISTINFO): + print("Removing previous DISTINFO file") + os.unlink(DISTINFO) + # Write data pairs to DISTINFO file + print("Generating DISTINFO file") with open(DISTINFO, 'w+') as fp: for key_dist in DISTINFO_KEYS: for name, value in data: From 8494cc10626acd023eef9c2fa9d66509432df695 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 27 Sep 2021 10:17:50 -0400 Subject: [PATCH 07/10] Configure the project prior to creating an archive --- wscript | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wscript b/wscript index 2016e8f3a..1e40b3057 100644 --- a/wscript +++ b/wscript @@ -157,7 +157,6 @@ def _gen_distinfo(data): # Remove previous edition of the file if os.path.exists(DISTINFO): - print("Removing previous DISTINFO file") os.unlink(DISTINFO) # Write data pairs to DISTINFO file @@ -498,7 +497,8 @@ def _dist_setup(ctx): '*.zip']) # Update version information - _get_git_details(ctx) + Scripting.run_command('configure') + def dist(ctx): _dist_setup(ctx) From 79a52eed2d8d2934adeece1ebbd238885c4f35c1 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 27 Sep 2021 10:55:57 -0400 Subject: [PATCH 08/10] Remove need to configure at all --- wscript | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/wscript b/wscript index 1e40b3057..866b88073 100644 --- a/wscript +++ b/wscript @@ -145,9 +145,9 @@ def call(cmd): return None -def _gen_distinfo(data): +def _gen_distinfo(ctx): """Generates a DISTINFO file - data: [["key", "value"], ["key", "value"], ...] + ctx.git_data: [["key", "value"], ["key", "value"], ...] """ # Generate DISTINFO file UNLESS we are building from an archive @@ -163,7 +163,7 @@ def _gen_distinfo(data): print("Generating DISTINFO file") with open(DISTINFO, 'w+') as fp: for key_dist in DISTINFO_KEYS: - for name, value in data: + for name, value in ctx.git_data: if name == key_dist: fp.write("{}:{}\n".format(name, value)) @@ -209,6 +209,7 @@ def _get_git_details(ctx): if not os.path.exists(".git") and os.path.exists(DISTINFO): print("Using DISTINFO file") _get_distinfo() + _gen_version_header(ctx) return tmp = call('git describe --dirty --abbrev=7') @@ -223,26 +224,27 @@ def _get_git_details(ctx): if tmp: BRANCH = tmp + _gen_version_header(ctx) + _gen_distinfo(ctx) + def _gen_version_header(ctx): """Generate a C header to provide versioning data to hstcal's programs """ - data = [ + filename = os.path.join(out_include_dir, 'version.h') + label = "HEADER_" + os.path.basename(filename).replace(".", "_").upper() + ctx.git_data = [ ["APPNAME", APPNAME], ["VERSION", VERSION], ["BRANCH", BRANCH], ["COMMIT", COMMIT], ] - _gen_distinfo(data) - - filename = os.path.join(out_include_dir, 'version.h') - label = "HEADER_" + os.path.basename(filename).replace(".", "_").upper() os.makedirs(out_include_dir, exist_ok=True) with open(filename, 'w+') as hdr: hdr.write("#ifndef {}\n".format(label)) hdr.write("#define {}\n".format(label)) - for key, value in data: + for key, value in ctx.git_data: hdr.write("#define {} \"{}\"\n".format(key, value)) hdr.write("#endif /* {} */\n".format(label)) @@ -264,7 +266,6 @@ def _use_git_details(ctx): ctx.end_msg(BRANCH, _warn_color(BRANCH, "UNKNOWN")) - def _check_mac_osx_version(floor_version): ''' Purpose: @@ -394,7 +395,6 @@ def configure(conf): fd.close() _use_git_details(conf) - _gen_version_header(conf) # Load C compiler support conf.load('compiler_c') @@ -497,17 +497,20 @@ def _dist_setup(ctx): '*.zip']) # Update version information - Scripting.run_command('configure') + _get_git_details(ctx) def dist(ctx): _dist_setup(ctx) + # call 'waf dist' directly to generate an archive Scripting.dist(ctx) def distcheck(ctx): _dist_setup(ctx) + + # call 'waf distcheck' directly to smoke test building from an archive Scripting.distcheck(ctx) From 2d7ff6ab930099cdd84ed24be3024f5948b527fc Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 27 Sep 2021 11:00:14 -0400 Subject: [PATCH 09/10] Remove tab character --- wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wscript b/wscript index 866b88073..514b3387f 100644 --- a/wscript +++ b/wscript @@ -157,7 +157,7 @@ def _gen_distinfo(ctx): # Remove previous edition of the file if os.path.exists(DISTINFO): - os.unlink(DISTINFO) + os.unlink(DISTINFO) # Write data pairs to DISTINFO file print("Generating DISTINFO file") From e03d6a38ac043d12843fa9dfe907912aa5af8a1e Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 6 Oct 2021 12:20:48 -0400 Subject: [PATCH 10/10] Fix acsforwardmodel.e missing execution bit --- pkg/acs/calacs/acscte/wscript | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/acs/calacs/acscte/wscript b/pkg/acs/calacs/acscte/wscript index 22983fb45..e78be81f8 100644 --- a/pkg/acs/calacs/acscte/wscript +++ b/pkg/acs/calacs/acscte/wscript @@ -1,4 +1,6 @@ # vim: set syntax=python: +from waflib import Utils + def build(bld): t = bld.program( @@ -15,4 +17,4 @@ def build(bld): rpath=bld.env.LIBPATH_CFITSIO, install_path = '${PREFIX}/bin' ) - bld.install_as('${PREFIX}/bin/acscteforwardmodel.e', 'acscte.e') + bld.install_as('${PREFIX}/bin/acscteforwardmodel.e', 'acscte.e', chmod=Utils.O755)