From cfeb2e1f7c0df9a2322581de3f957fb7a14a1a72 Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Wed, 8 Mar 2023 04:26:21 -0500 Subject: [PATCH 1/4] common/xbps-src/shutils/common.sh: add function for str->array this will allow select variables to be defined as arrays or strings. if a string is specified, it will be converted to an array for internal usage. if it is an array, it passes through untouched. this should allow for a smooth transition to using more arrays inside xbps-src, and should solve issues with shell quoting in things like configure_args, make_check_args, etc. --- common/xbps-src/shutils/common.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh index 04247942decf25..88ee6b4fb6ec1a 100644 --- a/common/xbps-src/shutils/common.sh +++ b/common/xbps-src/shutils/common.sh @@ -286,6 +286,18 @@ source_file() { fi } +arrayise() { + for name; do + if [[ -n "$name" && "${!name@a}" != *a* ]]; then + IFS=" " read -r -a "${name}" <<< "${!name}" + declare -n nameref="$name" + if [ "${#nameref[@]}" -gt 1 ]; then + msg_error "template variable '$name' should be an array!\n" + fi + fi + done +} + run_pkg_hooks() { local phase="$1" hookn f @@ -568,6 +580,8 @@ setup_pkg() { set_build_options + arrayise configure_args + export CFLAGS="$XBPS_CFLAGS $XBPS_CROSS_CFLAGS $CFLAGS $dbgflags" export CXXFLAGS="$XBPS_CXXFLAGS $XBPS_CROSS_CXXFLAGS $CXXFLAGS $dbgflags" export FFLAGS="$XBPS_FFLAGS $XBPS_CROSS_FFLAGS $FFLAGS $dbgflags" From a7c20ad2f26a5806fce95dc50e56ffa8c1dd6e7a Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Wed, 8 Mar 2023 04:32:03 -0500 Subject: [PATCH 2/4] common/xbps-src/shutils/show.sh: refactor show_pkg_var to support arrays --- common/xbps-src/shutils/show.sh | 89 ++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 28 deletions(-) diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh index 6ae0f4e6d7df28..464ac04f6261e3 100644 --- a/common/xbps-src/shutils/show.sh +++ b/common/xbps-src/shutils/show.sh @@ -1,27 +1,27 @@ # vim: set ts=4 sw=4 et: show_pkg() { - show_pkg_var "pkgname" "$pkgname" - show_pkg_var "version" "$version" - show_pkg_var "revision" "$revision" - show_pkg_var "distfiles" "$distfiles" 1 - show_pkg_var "checksum" "$checksum" 1 - show_pkg_var "archs" "$archs" 1 - show_pkg_var "maintainer" "${maintainer}" - show_pkg_var "Upstream URL" "$homepage" - show_pkg_var "License(s)" "${license//,/ }" 1 - show_pkg_var "Changelog" "$changelog" - show_pkg_var "build_style" "$build_style" - show_pkg_var "build_helper" "$build_helper" 1 - show_pkg_var "configure_args" "$configure_args" 1 - show_pkg_var "short_desc" "$short_desc" - show_pkg_var "subpackages" "$subpackages" 1 + show_pkg_var no "pkgname" "$pkgname" + show_pkg_var no "version" "$version" + show_pkg_var no "revision" "$revision" + show_pkg_var st "distfiles" "$distfiles" + show_pkg_var st "checksum" "$checksum" + show_pkg_var st "archs" "$archs" + show_pkg_var no "maintainer" "${maintainer}" + show_pkg_var no "Upstream URL" "$homepage" + show_pkg_var st "License(s)" "${license//,/ }" + show_pkg_var no "Changelog" "$changelog" + show_pkg_var no "build_style" "$build_style" + show_pkg_var st "build_helper" "$build_helper" + show_pkg_var ar "configure_args" "${configure_args[@]}" + show_pkg_var no "short_desc" "$short_desc" + show_pkg_var st "subpackages" "$subpackages" set -f - show_pkg_var "conf_files" "$conf_files" 1 + show_pkg_var st "conf_files" "$conf_files" set +f - show_pkg_var "replaces" "$replaces" 1 - show_pkg_var "provides" "$provides" 1 - show_pkg_var "conflicts" "$conflicts" 1 + show_pkg_var st "replaces" "$replaces" + show_pkg_var st "provides" "$provides" + show_pkg_var st "conflicts" "$conflicts" local OIFS="$IFS" IFS=',' for var in $1; do @@ -29,9 +29,9 @@ show_pkg() { if [ ${var} != ${var/'*'} ] then var="${var/'*'}" - show_pkg_var "$var" "${!var//$'\n'/' '}" + show_pkg_var no "$var" "${!var//$'\n'/' '}" else - show_pkg_var "$var" "${!var}" 1 + show_pkg_var st "$var" "${!var}" fi done IFS="$OIFS" @@ -41,26 +41,59 @@ show_pkg() { show_pkg_var() { local _sep i= - local _label="$1" - local _value="$2" - local _always_split="$3" - if [ -n "$_value" ] && [ -n "$_label" ]; then + local _split="$1" + local _label="$2" + shift 2 + if [ -n "$_label" ]; then # on short labels, use more padding so everything lines up if [ "${#_label}" -lt 7 ]; then _sep=" " else _sep=" " fi - if [ -n "$_always_split" ] || [[ "$_value" =~ $'\n' ]]; then - for i in ${_value}; do + + # treat as an array + if [ "$_split" = "ar" ]; then + for _value; do + if [ -n "$_value" ]; then + if [[ "$_value" =~ $'\n' ]]; then + OIFS="$IFS"; IFS=$'\n' + for i in $_value; do + [ -n "$i" ] && echo "${_label}:${_sep}${i}" + done + IFS="$OIFS" + else + echo "${_label}:${_sep}${_value}" + fi + fi + done + # treat as a string, always split at whitespace + elif [ "$_split" = "st" ] || [[ "$@" =~ $'\n' ]]; then + _value="$@" + for i in $_value; do [ -n "$i" ] && echo "${_label}:${_sep}${i}" done else - echo "${_label}:${_sep}${_value}" + _value="$@" + [ -n "$_value" ] && echo "${_label}:${_sep}${_value}" fi fi } +show_pkg_arr() { + local _sep i= + local _label="$1" + shift + for _value; do + # on short labels, use more padding so everything lines up + if [ "${#_label}" -lt 7 ]; then + _sep=" " + else + _sep=" " + fi + done +} + show_pkg_deps() { [ -f "${PKGDESTDIR}/rdeps" ] && cat ${PKGDESTDIR}/rdeps } From adddd05ebe6055df0c6ab01022090f400faf6c6b Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Wed, 8 Mar 2023 04:32:56 -0500 Subject: [PATCH 3/4] common/build-style/: convert configure-args to array --- common/build-style/cargo.sh | 6 +++--- common/build-style/cmake.sh | 4 ++-- common/build-style/configure.sh | 2 +- common/build-style/gemspec.sh | 2 +- common/build-style/gnu-configure.sh | 2 +- common/build-style/meson.sh | 4 ++-- common/build-style/perl-ModuleBuild.sh | 2 +- common/build-style/perl-module.sh | 2 +- common/build-style/qmake.sh | 4 ++-- common/build-style/sip-build.sh | 2 +- common/build-style/void-cross.sh | 4 ++-- common/build-style/waf.sh | 2 +- common/build-style/waf3.sh | 2 +- common/build-style/zig-build.sh | 2 +- 14 files changed, 20 insertions(+), 20 deletions(-) diff --git a/common/build-style/cargo.sh b/common/build-style/cargo.sh index 751911d8dbee8d..c080a65ad71ca6 100644 --- a/common/build-style/cargo.sh +++ b/common/build-style/cargo.sh @@ -5,14 +5,14 @@ do_build() { : ${make_cmd:=cargo auditable} - ${make_cmd} build --release --locked --target ${RUST_TARGET} ${configure_args} + ${make_cmd} build --release --locked --target ${RUST_TARGET} "${configure_args[@]}" } do_check() { : ${make_cmd:=cargo auditable} ${make_check_pre} ${make_cmd} test --release --locked --target ${RUST_TARGET} \ - ${configure_args} ${make_check_args} + "${configure_args[@]}" ${make_check_args} } do_install() { @@ -20,7 +20,7 @@ do_install() { : ${make_install_args:=--path .} ${make_cmd} install --target ${RUST_TARGET} --root="${DESTDIR}/usr" \ - --offline --locked ${configure_args} ${make_install_args} + --offline --locked "${configure_args[@]}" ${make_install_args} rm -f "${DESTDIR}"/usr/.crates.toml rm -f "${DESTDIR}"/usr/.crates2.json diff --git a/common/build-style/cmake.sh b/common/build-style/cmake.sh index 124ed354eff674..3adbba4db263b2 100644 --- a/common/build-style/cmake.sh +++ b/common/build-style/cmake.sh @@ -19,7 +19,7 @@ SET(CMAKE_FIND_ROOT_PATH "${XBPS_MASTERDIR}/usr;${XBPS_MASTERDIR}") SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) _EOF - configure_args+=" -DCMAKE_TOOLCHAIN_FILE=bootstrap.cmake" + configure_args+=("-DCMAKE_TOOLCHAIN_FILE=bootstrap.cmake") elif [ "$CROSS_BUILD" ]; then case "$XBPS_TARGET_MACHINE" in x86_64*) _CMAKE_SYSTEM_PROCESSOR=x86_64 ;; @@ -75,7 +75,7 @@ _EOF export CMAKE_GENERATOR="${CMAKE_GENERATOR:-Ninja}" # Remove -pipe: https://gitlab.kitware.com/cmake/cmake/issues/19590 CFLAGS="-DNDEBUG ${CFLAGS/ -pipe / }" CXXFLAGS="-DNDEBUG ${CXXFLAGS/ -pipe / }" \ - cmake ${cmake_args} ${configure_args} \ + cmake ${cmake_args} "${configure_args[@]}" \ ${LIBS:+-DCMAKE_C_STANDARD_LIBRARIES="$LIBS"} \ ${LIBS:+-DCMAKE_CXX_STANDARD_LIBRARIES="$LIBS"} \ ${wrksrc}/${build_wrksrc} diff --git a/common/build-style/configure.sh b/common/build-style/configure.sh index 8fe327507d9e8f..9b472ca28ccc20 100644 --- a/common/build-style/configure.sh +++ b/common/build-style/configure.sh @@ -5,7 +5,7 @@ do_configure() { : ${configure_script:=./configure} - ${configure_script} ${configure_args} + ${configure_script} "${configure_args[@]}" } do_build() { diff --git a/common/build-style/gemspec.sh b/common/build-style/gemspec.sh index 9568e819ed45a3..0ed948dbff0e57 100644 --- a/common/build-style/gemspec.sh +++ b/common/build-style/gemspec.sh @@ -120,7 +120,7 @@ do_install() { --no-document \ --verbose \ "${pkgname#ruby-}-${version}.gem" \ - -- $configure_args + -- "${configure_args[@]}" # Remove cache rm -rf ${DESTDIR}/${_GEMDIR}/cache diff --git a/common/build-style/gnu-configure.sh b/common/build-style/gnu-configure.sh index 82d36f6ee0f79c..b89008875a894a 100644 --- a/common/build-style/gnu-configure.sh +++ b/common/build-style/gnu-configure.sh @@ -5,7 +5,7 @@ do_configure() { : ${configure_script:=./configure} export lt_cv_sys_lib_dlsearch_path_spec="/usr/lib64 /usr/lib32 /usr/lib /lib /usr/local/lib" - ${configure_script} ${configure_args} + ${configure_script} "${configure_args[@]}" } do_build() { diff --git a/common/build-style/meson.sh b/common/build-style/meson.sh index 5ea2eeda40097d..9f1abed904a797 100644 --- a/common/build-style/meson.sh +++ b/common/build-style/meson.sh @@ -8,7 +8,7 @@ do_configure() { : ${meson_crossfile:="${XBPS_WRAPPERDIR}/meson/xbps_meson.cross"} if [ "$CROSS_BUILD" ]; then - configure_args+=" --cross-file=${meson_crossfile}" + configure_args+=("--cross-file=${meson_crossfile}") fi # binutils ar needs a plugin when LTO is used on static libraries, so we @@ -39,7 +39,7 @@ do_configure() { --wrap-mode=nodownload \ -Db_lto=true -Db_ndebug=true \ -Db_staticpic=true \ - ${configure_args} . ${meson_builddir} + "${configure_args[@]}" . ${meson_builddir} } do_build() { diff --git a/common/build-style/perl-ModuleBuild.sh b/common/build-style/perl-ModuleBuild.sh index f21d2b0efb4cf0..5efa8484068e48 100644 --- a/common/build-style/perl-ModuleBuild.sh +++ b/common/build-style/perl-ModuleBuild.sh @@ -24,7 +24,7 @@ do_configure() { perl Build.PL --config optimize="$_optimize" --config ccflags="$_ccflags" \ --config lddlflags="$_lddlflags" --config ldflags="$_ldflags" \ --config archlibexp="${XBPS_CROSS_BASE}${_archlibexp}" \ - ${configure_args} INSTALLDIRS=vendor + "${configure_args[@]}" INSTALLDIRS=vendor else msg_error "$pkgver: cannot find Build.PL for perl module!\n" fi diff --git a/common/build-style/perl-module.sh b/common/build-style/perl-module.sh index 2945787ffbe11e..2bcfda7430833f 100644 --- a/common/build-style/perl-module.sh +++ b/common/build-style/perl-module.sh @@ -47,7 +47,7 @@ do_configure() { CFLAGS="$CFLAGS -I${XBPS_CROSS_BASE}/usr/include" \ LDFLAGS="$LDFLAGS -L${XBPS_CROSS_BASE}/usr/lib -lperl" \ LDDLFLAGS="-shared $CFLAGS -L${XBPS_CROSS_BASE}/usr/lib" \ - perl -I. Makefile.PL ${configure_args} INSTALLDIRS=vendor + perl -I. Makefile.PL "${configure_args[@]}" INSTALLDIRS=vendor fi for i in ${perl_configure_dirs}; do diff --git a/common/build-style/qmake.sh b/common/build-style/qmake.sh index 31745833606eff..1f79fd42d55ced 100644 --- a/common/build-style/qmake.sh +++ b/common/build-style/qmake.sh @@ -117,7 +117,7 @@ _EOF QT_INSTALL_PREFIX=/usr \ LIB=/usr/lib \ QT_TARGET_ARCH=$_qt_arch \ - ${configure_args} + "${configure_args[@]}" else ${qmake} ${qmake_args} \ PREFIX=/usr \ @@ -129,7 +129,7 @@ _EOF QMAKE_CXXFLAGS="${CXXFLAGS}" \ QMAKE_LFLAGS="${LDFLAGS}" \ CONFIG+=no_qt_rpath \ - ${configure_args} + "${configure_args[@]}" fi } diff --git a/common/build-style/sip-build.sh b/common/build-style/sip-build.sh index d8b3bcea98bf09..42b5b2bff19122 100644 --- a/common/build-style/sip-build.sh +++ b/common/build-style/sip-build.sh @@ -124,7 +124,7 @@ do_configure() { sip-build --no-make \ ${_qt:+--qmake "$XBPS_WRAPPERDIR/sip-qmake"} \ --api-dir /usr/share/$_qt/qsci/api/python \ - $configure_args \ + "${configure_args[@]}" \ --build-dir "$sip_builddir" if [ "$CROSS_BUILD" ]; then diff --git a/common/build-style/void-cross.sh b/common/build-style/void-cross.sh index 2e8ebb52ceaf90..bcd6cece5eadf2 100644 --- a/common/build-style/void-cross.sh +++ b/common/build-style/void-cross.sh @@ -142,7 +142,7 @@ _void_cross_build_bootstrap_gcc() { --with-gnu-ld \ --with-gnu-as \ ${extra_args} \ - ${configure_args} \ + "${configure_args[@]}" \ ${cross_gcc_bootstrap_configure_args} make ${makejobs} @@ -442,7 +442,7 @@ _void_cross_build_gcc() { --with-gnu-as \ --with-linker-hash-style=gnu \ ${extra_args} \ - ${configure_args} \ + "${configure_args[@]}" \ ${cross_gcc_configure_args} make ${makejobs} diff --git a/common/build-style/waf.sh b/common/build-style/waf.sh index e943765f9b1797..2b3b6eb03c9df9 100644 --- a/common/build-style/waf.sh +++ b/common/build-style/waf.sh @@ -5,7 +5,7 @@ do_configure() { : ${configure_script:=waf} PYTHON=/usr/bin/python2 python2 ${configure_script} configure \ - --prefix=/usr --libdir=/usr/lib${XBPS_TARGET_WORDSIZE} ${configure_args} + --prefix=/usr --libdir=/usr/lib${XBPS_TARGET_WORDSIZE} "${configure_args[@]}" } do_build() { diff --git a/common/build-style/waf3.sh b/common/build-style/waf3.sh index 54fd221172b7f3..455b043ebfa398 100644 --- a/common/build-style/waf3.sh +++ b/common/build-style/waf3.sh @@ -13,7 +13,7 @@ do_configure() { PYTHON=/usr/bin/python3 python3 ${configure_script} configure \ --prefix=/usr --libdir=/usr/lib${XBPS_TARGET_WORDSIZE} \ - ${configure_args} ${cross_args} + "${configure_args[@]}" ${cross_args} } do_build() { diff --git a/common/build-style/zig-build.sh b/common/build-style/zig-build.sh index 205c4cadf53f8c..e2d02fb11b7f27 100644 --- a/common/build-style/zig-build.sh +++ b/common/build-style/zig-build.sh @@ -33,7 +33,7 @@ do_build() { --libc xbps_zig_libc.txt \ -Dtarget="${zig_target}" -Dcpu="${zig_cpu}" \ -Drelease-safe --prefix /usr install \ - ${configure_args} + "${configure_args[@]}" } do_install() { From 7e0ab2bbe997bf9e40997ed11822393cbb4fa4bd Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Wed, 8 Mar 2023 04:33:30 -0500 Subject: [PATCH 4/4] common/environment/configure/gnu-configure-args.sh: configure_args->array --- .../environment/configure/gnu-configure-args.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/environment/configure/gnu-configure-args.sh b/common/environment/configure/gnu-configure-args.sh index 1a552b5074a076..06974323cf94fd 100644 --- a/common/environment/configure/gnu-configure-args.sh +++ b/common/environment/configure/gnu-configure-args.sh @@ -6,18 +6,18 @@ fi # Store args from template so they can be included last and override # our defaults -TEMPLATE_CONFIGURE_ARGS="${configure_args}" +TEMPLATE_CONFIGURE_ARGS=("${configure_args[@]}") -export configure_args="--prefix=/usr --sysconfdir=/etc --sbindir=/usr/bin --bindir=/usr/bin - --mandir=/usr/share/man --infodir=/usr/share/info --localstatedir=/var" +export configure_args=(--prefix=/usr --sysconfdir=/etc --sbindir=/usr/bin --bindir=/usr/bin + --mandir=/usr/share/man --infodir=/usr/share/info --localstatedir=/var) . ${XBPS_COMMONDIR}/build-profiles/${XBPS_MACHINE}.sh -export configure_args+=" --host=$XBPS_TRIPLET --build=$XBPS_TRIPLET" +export configure_args+=("--host=$XBPS_TRIPLET" "--build=$XBPS_TRIPLET") # Always use wordsize-specific libdir even though the real path is lib # This is to make sure 32-bit and 64-bit libs can coexist when looking # up things (the opposite-libdir is always symlinked as libNN) -export configure_args+=" --libdir=\${exec_prefix}/lib${XBPS_TARGET_WORDSIZE}" +export configure_args+=("--libdir=\${exec_prefix}/lib${XBPS_TARGET_WORDSIZE}") _AUTOCONFCACHEDIR=${XBPS_COMMONDIR}/environment/configure/autoconf_cache @@ -33,16 +33,16 @@ esac # Cross compilation vars if [ -z "$CROSS_BUILD" ]; then - export configure_args+=" ${TEMPLATE_CONFIGURE_ARGS}" + export configure_args+=("${TEMPLATE_CONFIGURE_ARGS[@]}") unset TEMPLATE_CONFIGURE_ARGS set +a return 0 fi -export configure_args+=" --host=$XBPS_CROSS_TRIPLET --with-sysroot=$XBPS_CROSS_BASE --with-libtool-sysroot=$XBPS_CROSS_BASE " +export configure_args+=("--host=$XBPS_CROSS_TRIPLET" "--with-sysroot=$XBPS_CROSS_BASE" "--with-libtool-sysroot=$XBPS_CROSS_BASE") -export configure_args+=" ${TEMPLATE_CONFIGURE_ARGS}" +export configure_args+=("${TEMPLATE_CONFIGURE_ARGS[@]}") unset TEMPLATE_CONFIGURE_ARGS # Read autoconf cache variables for cross target (taken from OE).