Skip to content

Commit

Permalink
build-related tweaks: separate git commit info (re: 148a8a3)
Browse files Browse the repository at this point in the history
It was getting annoying that every file that includes
<releaseflags.h> for the _AST_release macro needs to be recompiled
every time the git commit changes, because the git commit
information is in that same <releaseflags.h> file (even though only
version,.h in ksh93 uses it). I anticipate checking _AST_release in
more files, so this will be getting worse.

src/lib/libast/Mamfile,
src/cmd/ksh93/Mamfile,
src/lib/libast/include/ast.h,
src/cmd/ksh93/include/version.h:
- To minimise dependencies on the git commit, move the git commit
  information to git.h in ksh93; make version.h include it.
- Rename releaseflags.h to ast_release.h as it (currently) only
  defines or doesn't define _AST_release.
- Include <ast_release.h> from ast.h so _AST_release can be checked
  for everywhere in future.
- ast.h: remove a dead struct define conditional upon _SFIO_H
  (which is known to be defined as sfio.h is included earlier).

src/cmd/ksh93/sh/array.c,
src/lib/libsum/sum-sha2.c:
- Now that we can easily use _AST_release everywhere, use it to
  include <assert.h> but disable assert() on _AST_release versions.
- Add missing assert() call to nv_endsubscript(). (re: 3939103)

src/lib/libast/comp/assert.c:
- Do not enclose the assertion in single quotes in assert() failure
  messages; assertions may themselves contain single quotes (like
  the one just added to array.c).

src/cmd/ksh93/tests/arrays.sh:
- Work around a spurious failure under ASan, which actually points
  to another flaw in the regex code. See link in comment for info.
  • Loading branch information
McDutchie committed Dec 2, 2024
1 parent fcb026b commit 4632c14
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 54 deletions.
34 changes: 31 additions & 3 deletions src/cmd/ksh93/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@ setv DYLIB_SUF %{mam_cc_SUFFIX_DYNAMIC-%{mam_cc_SUFFIX_SHARED}}
setv DYLIB_VERSION 2.0

make install virtual
note *
note * Generate Git commit information
note *
note * (The target is 'virtual' as it needs to be run at
note * every build, so we can catch changes of git commit)
note *
make git_commit notrace virtual
exec - git_commit=$(git rev-parse --short=8 HEAD 2>/dev/null)
exec - case $?,$git_commit in
exec - 0,[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z])
exec - echo "/* generated by ksh93/Mamfile using $(git --version) */"
exec - git update-index --really-refresh >/dev/null
exec - git diff-index --quiet HEAD
exec - wd_clean=$((! $?)) # working directory clean?
exec - test "$wd_clean" -eq 0 && git_commit=$git_commit/MOD
exec - echo "#define git_commit \"$git_commit\""
exec - echo "# current git commit: $git_commit" >&2 # for the log
exec - ;;
exec - *)
exec - echo "/* generated by libast/Mamfile (we're not in a git repo) */"
exec - echo "#undef git_commit"
exec - ;;
exec - esac > git.h.new
exec - if cmp -s git.h.new git.h
exec - then rm -f git.h.new
exec - else mv -f git.h.new git.h
exec - fi
done

note *
note * Library dependencies
note *
Expand Down Expand Up @@ -291,7 +320,8 @@ make install virtual
done

make include/version.h
prev %{INCLUDE_AST}/releaseflags.h
makp git.h
prev %{INCLUDE_AST}/ast_release.h
done

make include/timeout.h
Expand Down Expand Up @@ -724,7 +754,6 @@ make install virtual
prev include/defs.h
prev include/nval.h
prev include/fcin.h
prev %{INCLUDE_AST}/releaseflags.h
prev %{INCLUDE_AST}/ast.h
prev shopt.h
done
Expand Down Expand Up @@ -970,7 +999,6 @@ make install virtual
prev include/history.h
prev include/io.h
prev include/defs.h
prev %{INCLUDE_AST}/releaseflags.h
prev %{INCLUDE_AST}/ast.h
prev shopt.h
done
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/edit/emacs.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ One line screen editor for any program

#if SHOPT_ESH

#include <releaseflags.h>
#include "defs.h"
#include "io.h"
#include "history.h"
Expand Down
14 changes: 10 additions & 4 deletions src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@
* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) *
* *
* David Korn <[email protected]> *
* Martijn Dekker <[email protected]> *
* *
***********************************************************************/

#include <releaseflags.h>
#include <ast_release.h>
#include "git.h"

#define SH_RELEASE_DATE "2024-11-30" /* must be in this format for $((.sh.version)) */
/*
* This comment keeps SH_RELEASE_DATE a few lines away from SH_RELEASE_SVER to avoid
* merge conflicts when cherry-picking dev branch commits onto a release branch.
*/
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.11-beta" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2024-11-30" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2024 Contributors to ksh " SH_RELEASE_FORK

/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
/* Arithmetic $((.sh.version)) uses the last 10 chars, so the date must be at the end. */
#if _AST_release
# define SH_RELEASE SH_RELEASE_FORK "/" SH_RELEASE_SVER " " SH_RELEASE_DATE
#else
# ifdef _AST_git_commit
# define SH_RELEASE SH_RELEASE_FORK "/" SH_RELEASE_SVER "+" _AST_git_commit " " SH_RELEASE_DATE
# ifdef git_commit
# define SH_RELEASE SH_RELEASE_FORK "/" SH_RELEASE_SVER "+" git_commit " " SH_RELEASE_DATE
# else
# define SH_RELEASE SH_RELEASE_FORK "/" SH_RELEASE_SVER "+dev " SH_RELEASE_DATE
# endif
Expand Down
6 changes: 6 additions & 0 deletions src/cmd/ksh93/sh/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
#include "defs.h"
#include "name.h"

#if _AST_release
#define NDEBUG
#endif
#include <assert.h>

#define NUMSIZE 11
#define is_associative(ap) array_assoc((Namarr_t*)(ap))
#define array_setbit(cp, n, b) (cp[n] |= (b))
Expand Down Expand Up @@ -1479,6 +1484,7 @@ char *nv_endsubscript(Namval_t *np, char *cp, int mode)
{
int count=1, quoted=0, c;
char *sp = cp+1;
assert(*cp=='[');
/* first find matching ']' */
while(count>0 && (c= *++cp))
{
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/sh/lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include "shopt.h"
#include <ast.h>
#include <releaseflags.h>
#include <fcin.h>
#include <nval.h>
#include "defs.h"
Expand Down
6 changes: 5 additions & 1 deletion src/cmd/ksh93/tests/arrays.sh
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,11 @@ x=$(
) | read -C hugecpv
compound hugecpv2=hugecpv
v=$(typeset -p hugecpv)
[[ ${v/hugecpv/hugecpv2} == "$(typeset -p hugecpv2)" ]]
# FIXME: the == operator in [[ ... ]] may crash in the regex code for large values due to
# excessive recursion; replace with a test(1) invocation (it doesn't call the regex code).
# More info: https://github.com/ksh93/ksh/issues/207#issuecomment-2508747419
#[[ ${v/hugecpv/hugecpv2} == "$(typeset -p hugecpv2)" ]]
test "${v/hugecpv/hugecpv2}" = "$(typeset -p hugecpv2)"
EOF
) 2> /dev/null || err_exit 'copying a large array fails'
Expand Down
53 changes: 20 additions & 33 deletions src/lib/libast/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,51 +43,37 @@ make install virtual
note * Generate release information
note *
note * (The target is 'virtual' as it needs to be run at
note * every build, so we can catch changes of git commit)
note * every build, so we can catch changes of git status)
note *
make releaseflags notrace virtual
exec - git_commit=$(git rev-parse --short=8 HEAD 2>/dev/null)
exec - case $?,$git_commit in
exec - 0,[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z])
exec - echo "/* generated by libast/Mamfile using $(git --version) */"
exec - git update-index --really-refresh >/dev/null
exec - git diff-index --quiet HEAD
exec - wd_clean=$((! $?)) # working directory clean?
exec - case $(git branch) in
make ast_release notrace virtual
exec - if git_branch=$(git branch 2>/dev/null)
exec - then echo "/* generated by libast/Mamfile using $(git --version) */"
exec - case $git_branch in
exec - *\*\ [0-9]*.[0-9]*)
exec - # If we're not on a branch that starts with a number
exec - # (release branch), then compile as a release version
exec - case $wd_clean in
exec - 1) echo "#ifndef _AST_release"
exec - if git diff-index --quiet HEAD
exec - then echo "#ifndef _AST_release"
exec - echo "# define _AST_release 1"
exec - echo "#endif"
exec - ;;
exec - 0) echo "/*"
exec - else echo "/*"
exec - echo " * on a git release branch, but changes were made;"
exec - echo " * _AST_release not defined by default"
exec - echo " */"
exec - ;;
exec - esac
exec - fi
exec - ;;
exec - *)
exec - echo "/* not on a git release branch; _AST_release not defined by default */"
exec - ;;
exec - esac
exec - test "$wd_clean" -eq 0 && git_commit=$git_commit/MOD
exec - echo "#define _AST_git_commit \"$git_commit\""
exec - echo "# current git commit: $git_commit" >&2 # for the log
exec - ;;
exec - *)
exec - echo "/* generated by libast/Mamfile (we're not in a git repo) */"
exec - else echo "/* generated by libast/Mamfile (we're not in a git repo) */"
exec - echo "#ifndef _AST_release"
exec - echo "# define _AST_release 1"
exec - echo "#endif"
exec - echo "#undef _AST_git_commit"
exec - ;;
exec - esac > releaseflags.h.new
exec - if cmp -s releaseflags.h.new releaseflags.h
exec - then rm -f releaseflags.h.new
exec - else mv -f releaseflags.h.new releaseflags.h
exec - fi > ast_release.h.new
exec - if cmp -s ast_release.h.new ast_release.h
exec - then rm -f ast_release.h.new
exec - else mv -f ast_release.h.new ast_release.h
exec - fi
done

Expand Down Expand Up @@ -434,6 +420,7 @@ make install virtual
prev ast_common.h
prev include/ast_std.h
done
makp ast_release.h
done

make include/stak.h
Expand Down Expand Up @@ -4517,10 +4504,10 @@ make install virtual
done
done

note * install releaseflags.h outside the lib/mam/ast block below, so the mkdeps action is not triggered when
note * releaseflags.h changes every time that the git commit changes (it doesn't contain #includes anyway)
make %{INCLUDE_AST}/releaseflags.h
makp releaseflags.h
note * install ast_release.h outside the lib/mam/ast block below, so the mkdeps action
note * is not triggered when ast_release.h changes (it's known not to contain #includes)
make %{INCLUDE_AST}/ast_release.h
prev ast_release.h
exec - cp -f %{<} %{@}
done

Expand Down Expand Up @@ -4555,7 +4542,7 @@ make install virtual
done
done
note * generate header dependency rules
exec - mkdeps -last %{INCLUDE_AST}/releaseflags.h %{^} > %{@}
exec - mkdeps -last %{^} > %{@}
makp %{INSTALLROOT}/bin/mkdeps
done %{INSTALLROOT}/lib/mam/ast

Expand Down
4 changes: 2 additions & 2 deletions src/lib/libast/comp/assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
void noreturn _ast_assertfail(const char *a, const char *fun, const char *file, int line)
{
#if _has___func__ || _has___FUNCTION__
sfprintf(sfstderr,"\n*** assertion '%s' failed in %s(), %s:%d\n", a, fun, file, line);
sfprintf(sfstderr,"\n*** assertion %s failed in %s(), %s:%d\n", a, fun, file, line);
#else
NOT_USED(fun);
sfprintf(sfstderr,"\n*** assertion '%s' failed in %s:%d\n", a, file, line);
sfprintf(sfstderr,"\n*** assertion %s failed in %s:%d\n", a, file, line);
#endif
sfsync(NULL);
abort();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/features/common
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ tst - note{ does this compiler have __builtin_unreachable() }end output{
* argc should never be zero on init, but hopefully optimizers aren't that smart.
*/
#include <stdio.h>
#include "releaseflags.h"
#include "ast_release.h"
void testfn(int a)
{
switch(a)
Expand Down
5 changes: 2 additions & 3 deletions src/lib/libast/include/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#ifndef _AST_H
#define _AST_H

#include <ast_release.h>

#ifndef _AST_STD_H
#include <ast_std.h>
#endif
Expand All @@ -49,9 +51,6 @@
*/

#ifndef FILE
#ifndef _SFIO_H
struct _sfio_s;
#endif
#define FILE struct _sfio_s
#ifndef __FILE_typedef
#define __FILE_typedef 1
Expand Down
1 change: 1 addition & 0 deletions src/lib/libsum/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ make install virtual
make sumlib.c
make sum-sha2.c
prev %{INCLUDE_AST}/endian.h
prev %{INCLUDE_AST}/assert.h
done
makp sum-sha1.c
makp sum-md5.c
Expand Down
11 changes: 6 additions & 5 deletions src/lib/libsum/sum-sha2.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@

/*
* ASSERT NOTE:
* Some sanity checking code is included using assert(). On my FreeBSD
* system, this additional code can be removed by compiling with NDEBUG
* defined. Check your own system's man page on assert() to see how to
* compile WITHOUT the sanity checking code on your system.
* Some sanity checking code is included using assert().
* It can be removed by compiling with NDEBUG defined.
*
* UNROLLED TRANSFORM LOOP NOTE:
* You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform
Expand Down Expand Up @@ -71,7 +69,10 @@ typedef uint8_t sha2_byte; /* Exactly 1 byte */
typedef uint32_t sha2_word32; /* Exactly 4 bytes */
typedef uint64_t sha2_word64; /* Exactly 8 bytes */

#define assert(x)
#if _AST_release
#define NDEBUG
#endif
#include <assert.h>

#undef R
#undef S32
Expand Down

0 comments on commit 4632c14

Please sign in to comment.