makepkg: replaces sed in-place with built in substitution

Reads PKGBUILD into an array and replaces the pkgver and pkgrel with
bash parameter substitution, then uses shell redirection to write to to
the file. Because shell redirection follows symlinks, this accomplishes
the same thing as the previous default of using the GNU-specific
--follow-symlinks sed flag.

Removes SEDPATH and SEDINPLACEFLAGS from the build systems as they are
not used elsewhere.

Signed-off-by: Ethan Sommer <e5ten.arch@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Ethan Sommer 2019-11-05 20:29:11 -05:00 committed by Allan McRae
parent 424129e8d1
commit 3a814ee6bc
6 changed files with 5 additions and 32 deletions

View file

@ -20,8 +20,6 @@ mode=$3
-e "s|@DEBUGSUFFIX[@]|@DEBUGSUFFIX@|g" \ -e "s|@DEBUGSUFFIX[@]|@DEBUGSUFFIX@|g" \
-e "s|@INODECMD[@]|@INODECMD@|g" \ -e "s|@INODECMD[@]|@INODECMD@|g" \
-e "s|@FILECMD[@]|@FILECMD@|g" \ -e "s|@FILECMD[@]|@FILECMD@|g" \
-e "s|@SEDINPLACEFLAGS[@]|@SEDINPLACEFLAGS@|g" \
-e "s|@SEDPATH[@]|@SEDPATH@|g" \
-e "s|@configure_input[@]|Generated from ${input##*/}; do not edit by hand.|g" \ -e "s|@configure_input[@]|Generated from ${input##*/}; do not edit by hand.|g" \
"$input" >"$output" "$input" >"$output"

View file

@ -369,7 +369,6 @@ AC_CHECK_MEMBERS([struct statfs.f_flags],,,[[#include <sys/param.h>
GCC_VISIBILITY_CC GCC_VISIBILITY_CC
# Host-dependant definitions # Host-dependant definitions
DEFAULT_SEDINPLACEFLAGS=" --follow-symlinks -i"
INODECMD="stat -c '%i %n'" INODECMD="stat -c '%i %n'"
STRIP_BINARIES="--strip-all" STRIP_BINARIES="--strip-all"
STRIP_SHARED="--strip-unneeded" STRIP_SHARED="--strip-unneeded"
@ -377,30 +376,21 @@ STRIP_STATIC="--strip-debug"
case "${host_os}" in case "${host_os}" in
*bsd*) *bsd*)
INODECMD="stat -f '%i %N'" INODECMD="stat -f '%i %N'"
DEFAULT_SEDINPLACEFLAGS=" -i \"\""
;; ;;
darwin*) darwin*)
host_os_darwin=yes host_os_darwin=yes
INODECMD="/usr/bin/stat -f '%i %N'" INODECMD="/usr/bin/stat -f '%i %N'"
DEFAULT_SEDINPLACEFLAGS=" -i ''"
STRIP_BINARIES="" STRIP_BINARIES=""
STRIP_SHARED="-S" STRIP_SHARED="-S"
STRIP_STATIC="-S" STRIP_STATIC="-S"
;; ;;
esac esac
AM_CONDITIONAL([DARWIN], test "x$host_os_darwin" = "xyes") AM_CONDITIONAL([DARWIN], test "x$host_os_darwin" = "xyes")
AC_PATH_PROGS([SEDPATH], [sed], [sed], [/usr/bin$PATH_SEPARATOR/bin] )
AC_SUBST(INODECMD) AC_SUBST(INODECMD)
AC_SUBST(STRIP_BINARIES) AC_SUBST(STRIP_BINARIES)
AC_SUBST(STRIP_SHARED) AC_SUBST(STRIP_SHARED)
AC_SUBST(STRIP_STATIC) AC_SUBST(STRIP_STATIC)
# Flags for sed in place
if test "${SEDINPLACEFLAGS+set}" != "set"; then
SEDINPLACEFLAGS="${DEFAULT_SEDINPLACEFLAGS}"
fi
AC_ARG_VAR(SEDINPLACEFLAGS, [flags for sed, overriding the default])
# Variables plugged into makepkg.conf # Variables plugged into makepkg.conf
CARCH="${host%%-*}" CARCH="${host%%-*}"
CHOST="${host}" CHOST="${host}"
@ -576,7 +566,6 @@ ${PACKAGE_NAME}:
Architecture : ${CARCH} Architecture : ${CARCH}
Host Type : ${CHOST} Host Type : ${CHOST}
File inode command : ${INODECMD} File inode command : ${INODECMD}
In-place sed command : ${SEDPATH} ${SEDINPLACEFLAGS}
File seccomp command : ${FILECMD} File seccomp command : ${FILECMD}
libalpm version : ${LIB_VERSION} libalpm version : ${LIB_VERSION}

View file

@ -221,7 +221,6 @@ config_h = configure_file(
add_project_arguments('-include', 'config.h', language : 'c') add_project_arguments('-include', 'config.h', language : 'c')
filecmd = 'file' filecmd = 'file'
default_sedinplaceflags = ' --follow-symlinks -i'
inodecmd = 'stat -c \'%i %n\'' inodecmd = 'stat -c \'%i %n\''
strip_binaries = '--strip-all' strip_binaries = '--strip-all'
strip_shared = '--strip-unneeded' strip_shared = '--strip-unneeded'
@ -237,18 +236,11 @@ endif
os = host_machine.system() os = host_machine.system()
if os.startswith('darwin') if os.startswith('darwin')
inodecmd = '/usr/bin/stat -f \'%i %N\'' inodecmd = '/usr/bin/stat -f \'%i %N\''
default_sedinplaceflags = ' -i \'\''
strip_binaries = '' strip_binaries = ''
strip_shared = '-s' strip_shared = '-s'
strip_static = '-s' strip_static = '-s'
elif os.contains('bsd') or os == 'dragonfly' elif os.contains('bsd') or os == 'dragonfly'
inodecmd = 'stat -f \'%i %N\'' inodecmd = 'stat -f \'%i %N\''
default_sedinplaceflags = ' -i \'\''
endif
sedinplaceflags = get_option('sedinplaceflags')
if sedinplaceflags == 'auto'
sedinplaceflags = default_sedinplaceflags
endif endif
chost = run_command(cc, '-dumpmachine').stdout().strip() chost = run_command(cc, '-dumpmachine').stdout().strip()
@ -277,8 +269,6 @@ substs.set('TEMPLATE_DIR', get_option('makepkg-template-dir'))
substs.set('DEBUGSUFFIX', get_option('debug-suffix')) substs.set('DEBUGSUFFIX', get_option('debug-suffix'))
substs.set('INODECMD', inodecmd) substs.set('INODECMD', inodecmd)
substs.set('FILECMD', filecmd) substs.set('FILECMD', filecmd)
substs.set('SEDINPLACEFLAGS', sedinplaceflags)
substs.set('SEDPATH', SED.path())
substs.set('LIBMAKEPKGDIR', LIBMAKEPKGDIR) substs.set('LIBMAKEPKGDIR', LIBMAKEPKGDIR)
substs.set('STRIP_BINARIES', strip_binaries) substs.set('STRIP_BINARIES', strip_binaries)
substs.set('STRIP_SHARED', strip_shared) substs.set('STRIP_SHARED', strip_shared)
@ -430,7 +420,6 @@ message('\n '.join([
' Architecture : @0@'.format(carch), ' Architecture : @0@'.format(carch),
' Host Type : @0@'.format(chost), ' Host Type : @0@'.format(chost),
' File inode command : @0@'.format(inodecmd), ' File inode command : @0@'.format(inodecmd),
' In-place sed command : @0@ @1@'.format(SED.path(), sedinplaceflags),
' File seccomp command : @0@'.format(filecmd), ' File seccomp command : @0@'.format(filecmd),
' libalpm version : @0@'.format(libalpm_version), ' libalpm version : @0@'.format(libalpm_version),
' pacman version : @0@'.format(PACKAGE_VERSION), ' pacman version : @0@'.format(PACKAGE_VERSION),

View file

@ -54,6 +54,3 @@ option('i18n', type : 'boolean', value : true,
# tools # tools
option('file-seccomp', type: 'feature', value: 'auto', option('file-seccomp', type: 'feature', value: 'auto',
description: 'determine whether file is seccomp-enabled') description: 'determine whether file is seccomp-enabled')
option('sedinplaceflags', type : 'string', value : 'auto',
description : 'flags to pass to sed to edit a file in-place')

View file

@ -186,8 +186,6 @@ edit = sed \
-e 's|@DEBUGSUFFIX[@]|$(DEBUGSUFFIX)|g' \ -e 's|@DEBUGSUFFIX[@]|$(DEBUGSUFFIX)|g' \
-e "s|@INODECMD[@]|$(INODECMD)|g" \ -e "s|@INODECMD[@]|$(INODECMD)|g" \
-e "s|@FILECMD[@]|$(FILECMD)|g" \ -e "s|@FILECMD[@]|$(FILECMD)|g" \
-e 's|@SEDINPLACEFLAGS[@]|$(SEDINPLACEFLAGS)|g' \
-e 's|@SEDPATH[@]|$(SEDPATH)|g' \
-e 's|@SCRIPTNAME[@]|$@|g' \ -e 's|@SCRIPTNAME[@]|$@|g' \
-e 's|@configure_input[@]|Generated from $<; do not edit by hand.|g' -e 's|@configure_input[@]|Generated from $<; do not edit by hand.|g'

View file

@ -199,13 +199,15 @@ update_pkgver() {
fi fi
if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then
if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then if [[ -w $BUILDFILE ]]; then
if ! @SEDPATH@ @SEDINPLACEFLAGS@ "s:^pkgver=[^ ]*:pkgver=$newpkgver:" "$BUILDFILE"; then mapfile -t buildfile < "$BUILDFILE"
buildfile=("${buildfile[@]/#pkgver=*([^ ])/pkgver=$newpkgver}")
buildfile=("${buildfile[@]/#pkgrel=*([^ ])/pkgrel=1}")
if ! printf '%s\n' "${buildfile[@]}" > "$BUILDFILE"; then
error "$(gettext "Failed to update %s from %s to %s")" \ error "$(gettext "Failed to update %s from %s to %s")" \
"pkgver" "$pkgver" "$newpkgver" "pkgver" "$pkgver" "$newpkgver"
exit $E_PKGBUILD_ERROR exit $E_PKGBUILD_ERROR
fi fi
@SEDPATH@ @SEDINPLACEFLAGS@ "s:^pkgrel=[^ ]*:pkgrel=1:" "$BUILDFILE"
source_safe "$BUILDFILE" source_safe "$BUILDFILE"
local fullver=$(get_full_version) local fullver=$(get_full_version)
msg "$(gettext "Updated version: %s")" "$pkgbase $fullver" msg "$(gettext "Updated version: %s")" "$pkgbase $fullver"