1
0
forked from mirrors/pacman

Compare commits

...

14 Commits

Author SHA1 Message Date
Allan McRae
f1c7341a81 WIP: First pass at adding a pkgdiff script
Signed-off-by: Allan McRae <allan@archlinux.org>
2023-05-22 20:05:03 +10:00
Allan McRae
2c45e854ab Disable brittle valgrind test in CI
Signed-off-by: Allan McRae <allan@archlinux.org>
2023-05-22 19:32:47 +10:00
Allan McRae
a81ec016d7 Update pactest README
Signed-off-by: Allan McRae <allan@archlinux.org>
2023-05-22 19:25:23 +10:00
Allan McRae
55da1a01b6 makepkg.conf.in: strip leading slash from LIB_DIRS
Signed-off-by: Allan McRae <allan@archlinux.org>
2023-05-22 18:55:23 +10:00
Allan McRae
5e94752434 makepkg.conf.5: correction option name
Also fix typo "librarys"

Signed-off-by: Allan McRae <allan@archlinux.org>
2023-05-22 18:54:01 +10:00
Allan McRae
262aa6c24e Fix comment
Signed-off-by: Allan McRae <allan@archlinux.org>
2023-02-13 12:09:11 +00:00
Allan McRae
3323662ee0 makepkg: do not recurse into LIB_DIRS when looking for library provides
We should only find library provides in the configured directories, and
not their subdirectories.

Signed-off-by: Allan McRae <allan@archlinux.org>
2023-02-13 12:09:11 +00:00
Allan McRae
6c913af95d Add the -pedantic' compiler flag back to our debug builds
This was lost in the transition from autotools to meson. No additional
warnings are given with current gcc and clang.

Signed-off-by: Allan McRae <allan@archlinux.org>
2023-02-13 22:07:32 +10:00
Allan McRae
71764b6d4c makepkg.conf: allow configuration additions via a subdirectory
Move rust related buildflags to their own configuration file to
provide an example of how other languages could be supported.

Signed-off-by: Allan McRae <allan@archlinux.org>
2023-01-17 10:26:07 +10:00
Allan McRae
e0bbfb5682 libmakepkg: ensure clearing of buildflags happens first
When 'options=('!buildflags') is used, we want to ensure our
buildflags are cleared first. Currently this happens due to luck
of alphabetical ordering, but this could change with libmakepkg
drop-ins.

Signed-off-by: Allan McRae <allan@archlinux.org>
2023-01-13 11:35:42 +10:00
Allan McRae
09e82f01ea libmakepkg: move rust buildenv handling to separate file
This serves as a demonstration for how other languages could drop
in support into libmakepkg.

Signed-off-by: Allan McRae <allan@archlinux.org>
2023-01-13 11:35:35 +10:00
Stefan Weil
d35728f924 pacman-key: Fix shell syntax
Fixes: 3f8029af92 ("pacman-key: Use ngettext for plurals")
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2023-01-01 15:54:48 +01:00
Allan McRae
3f8029af92 pacman-key: Use ngettext for plurals
There are two strings that may be singular or plural in pacman-key.
Use ngettext to handle these strings correctly, and provide a fallback
function if it is not available.

Fixes FS#70556.

Signed-off-by: Allan McRae <allan@archlinux.org>
2023-01-01 13:41:52 +10:00
Allan McRae
6344aab3bd zsh: make names unique to avoid clashes
The function _keys is a bit generic and can result in clashes.  Change
other functions starting with _key_ to be _pacman_key_ as well.

Fixes FS#74507.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-12-24 00:55:30 +10:00
18 changed files with 423 additions and 52 deletions

View File

@@ -46,14 +46,14 @@ arch-clang:
- ninja -C build - ninja -C build
- fakechroot meson test -C build - fakechroot meson test -C build
arch-valgrind: #arch-valgrind:
extends: .arch-test # extends: .arch-test
script: # script:
- pacman -Syu --needed --noconfirm valgrind # - pacman -Syu --needed --noconfirm valgrind
- pacman -U --noconfirm https://geo.mirror.pkgbuild.com/core-debug/os/x86_64/glibc-debug-$(pacman -S --print-format %v glibc)-x86_64.pkg.tar.zst # - pacman -U --noconfirm https://geo.mirror.pkgbuild.com/core-debug/os/x86_64/glibc-debug-$(pacman -S --print-format %v glibc)-x86_64.pkg.tar.zst
- meson setup build # - meson setup build
- ninja -C build # - ninja -C build
- PACTEST_VALGRIND=1 fakechroot meson test -C build # - PACTEST_VALGRIND=1 fakechroot meson test -C build
arch-nettle: arch-nettle:
extends: .arch-test extends: .arch-test

View File

@@ -199,7 +199,7 @@ Options
flags specified in LTOFLAGS to CFLAGS, CXXFLAGS and LDFLAGS (or flags specified in LTOFLAGS to CFLAGS, CXXFLAGS and LDFLAGS (or
``-flto'' if LTOFLAGS is empty). ``-flto'' if LTOFLAGS is empty).
*autodep*;; *autodeps*;;
Enable the automatic addition of libraries to the depends and Enable the automatic addition of libraries to the depends and
provides arrays. Search library directories are controlled by provides arrays. Search library directories are controlled by
the LIB_DIRS variable defined below. the LIB_DIRS variable defined below.
@@ -236,7 +236,7 @@ Options
**LIB_DIRS=(**lib:usr/lib ...**)**:: **LIB_DIRS=(**lib:usr/lib ...**)**::
If `autodeps` is specified in the `OPTIONS` array, this variable will If `autodeps` is specified in the `OPTIONS` array, this variable will
instruct makepkg where to look to find librarys to add to the `provides` instruct makepkg where to look to find libraries to add to the `provides`
array. The format is "prefix:path", where provides will be added for array. The format is "prefix:path", where provides will be added for
libraries found in "path" with the specified prefix added. libraries found in "path" with the specified prefix added.

View File

@@ -0,0 +1,11 @@
#!/hint/bash
#
# @sysconfdir@/makepkg.conf.d/rust.conf
#
#########################################################################
# RUST LANGUAGE SUPPORT
#########################################################################
#
#RUSTFLAGS="-C opt-level=2"
#DEBUG_RUSTFLAGS="-C debuginfo=2"

View File

@@ -42,13 +42,11 @@ CHOST="@CHOST@"
#CXXFLAGS="-O2 -pipe" #CXXFLAGS="-O2 -pipe"
#LDFLAGS="" #LDFLAGS=""
#LTOFLAGS="-flto" #LTOFLAGS="-flto"
#RUSTFLAGS="-C opt-level=2"
#-- Make Flags: change this for DistCC/SMP systems #-- Make Flags: change this for DistCC/SMP systems
#MAKEFLAGS="-j2" #MAKEFLAGS="-j2"
#-- Debugging flags #-- Debugging flags
#DEBUG_CFLAGS="-g" #DEBUG_CFLAGS="-g"
#DEBUG_CXXFLAGS="-g" #DEBUG_CXXFLAGS="-g"
#DEBUG_RUSTFLAGS="-C debuginfo=2"
######################################################################### #########################################################################
# BUILD ENVIRONMENT # BUILD ENVIRONMENT
@@ -111,7 +109,7 @@ PURGE_TARGETS=(usr/{,share}/info/dir .packlist *.pod)
#-- Directory to store source code in for debug packages #-- Directory to store source code in for debug packages
DBGSRCDIR="/usr/src/debug" DBGSRCDIR="/usr/src/debug"
#-- Prefix and directories for library autodeps #-- Prefix and directories for library autodeps
LIB_DIRS=('lib:/usr/lib' 'lib32:/usr/lib32') LIB_DIRS=('lib:usr/lib' 'lib32:usr/lib32')
######################################################################### #########################################################################
# PACKAGE OUTPUT # PACKAGE OUTPUT

View File

@@ -190,6 +190,7 @@ endif
if get_option('debug') if get_option('debug')
extra_cflags = [ extra_cflags = [
'-pedantic',
'-Wcast-align', '-Wcast-align',
'-Wclobbered', '-Wclobbered',
'-Wempty-body', '-Wempty-body',
@@ -401,6 +402,12 @@ configure_file(
configuration : substs, configuration : substs,
install_dir : SYSCONFDIR) install_dir : SYSCONFDIR)
configure_file(
input : 'etc/makepkg.conf.d/rust.conf.in',
output : 'rust.conf',
configuration : substs,
install_dir : join_paths(SYSCONFDIR, 'makepkg.conf.d/'))
configure_file( configure_file(
input : 'etc/pacman.conf.in', input : 'etc/pacman.conf.in',
output : 'pacman.conf', output : 'pacman.conf',

View File

@@ -586,38 +586,38 @@ _pacman_conf() {
esac esac
} }
_key_shortopts=( _pacman_key_shortopts=(
'-h[show help]' '-h[show help]'
'-a[Add the specified keys (empty for stdin)]: :_files' '-a[Add the specified keys (empty for stdin)]: :_files'
'-d[Remove the Specified keyids]:*: :_keys' '-d[Remove the Specified keyids]:*: :_pacman_key_list'
'-e[Export the specified or all keyids]:*: :_keys' '-e[Export the specified or all keyids]:*: :_pacman_key_list'
'-f[List fingerprint for specified or all keyids]:*: :_keys' '-f[List fingerprint for specified or all keyids]:*: :_pacman_key_list'
'-l[List the specified or all keys]:*: :_keys' '-l[List the specified or all keys]:*: :_pacman_key_list'
'-r[Fetch the specified keyids]:*: :_keys' '-r[Fetch the specified keyids]:*: :_pacman_key_list'
'-u[Update the trustdb of pacman]' '-u[Update the trustdb of pacman]'
'-v[Verify the file specified by the signature]: :_files -g "*.sig"' '-v[Verify the file specified by the signature]: :_files -g "*.sig"'
'-V[Show program version]' '-V[Show program version]'
) )
_key_longopts=( _pacman_key_longopts=(
'--help[show help]' '--help[show help]'
'--add[Add the specified keys (empty for stdin)]: :_files' '--add[Add the specified keys (empty for stdin)]: :_files'
'--delete[Remove the Specified keyids]:*: :_keys' '--delete[Remove the Specified keyids]:*: :_pacman_key_list'
'--export[Export the specified or all keyids]:*: :_keys' '--export[Export the specified or all keyids]:*: :_pacman_key_list'
'--finger[List fingerprint for specified or all keyids]:*: :_keys' '--finger[List fingerprint for specified or all keyids]:*: :_pacman_key_list'
'--list-keys[List the specified or all keys]:*: :_keys' '--list-keys[List the specified or all keys]:*: :_pacman_key_list'
'--recv-keys[Fetch the specified keyids]:*: :_keys' '--recv-keys[Fetch the specified keyids]:*: :_pacman_key_list'
'--updatedb[Update the trustdb of pacman]' '--updatedb[Update the trustdb of pacman]'
'--verify[Verify the file specified by the signature]: :_files -g "*.sig"' '--verify[Verify the file specified by the signature]: :_files -g "*.sig"'
'--version[Show program version]' '--version[Show program version]'
'--edit-key[Present a menu for key management task on keyids]:*: :_keys' '--edit-key[Present a menu for key management task on keyids]:*: :_pacman_key_list'
'--import[Imports pubring.gpg from dir(s)]: :_files -g "*.gpg"' '--import[Imports pubring.gpg from dir(s)]: :_files -g "*.gpg"'
'--import-tb[Imports ownertrust values from trustdb.gpg in dir(s)]: :_files -g "*.gpg"' '--import-tb[Imports ownertrust values from trustdb.gpg in dir(s)]: :_files -g "*.gpg"'
'--init[Ensure the keyring is properly initialized]' '--init[Ensure the keyring is properly initialized]'
'--list-sigs[List keys and their signatures]:*: :_keys' '--list-sigs[List keys and their signatures]:*: :_pacman_key_list'
'--lsign-key[Locally sign the specified keyid]:*: :_keys' '--lsign-key[Locally sign the specified keyid]:*: :_pacman_key_list'
'--populate[Reload the default keys from the (given) keyrings in '@keyringdir@']: :_path_files -W @keyringdir@' '--populate[Reload the default keys from the (given) keyrings in '@keyringdir@']: :_path_files -W @keyringdir@'
'--refresh-keys[Update specified or all keys from a keyserver]:*: :_keys' '--refresh-keys[Update specified or all keys from a keyserver]:*: :_pacman_key_list'
) )
_pacman_key_options=( _pacman_key_options=(
@@ -631,13 +631,13 @@ _pacman_key() {
--*) --*)
_arguments -s : \ _arguments -s : \
"$_pacman_key_options[@]" \ "$_pacman_key_options[@]" \
"$_key_longopts[@]" "$_pacman_key_longopts[@]"
;; ;;
-*) -*)
_arguments -s : \ _arguments -s : \
"$_pacman_key_options[@]" \ "$_pacman_key_options[@]" \
"$_key_shortopts[@]" \ "$_pacman_key_shortopts[@]" \
"$_key_longopts[@]" "$_pacman_key_longopts[@]"
;; ;;
*) *)
i=$# i=$#
@@ -648,13 +648,13 @@ _pacman_key() {
--*) --*)
_arguments -s : \ _arguments -s : \
"$_pacman_key_options[@]" \ "$_pacman_key_options[@]" \
"$_key_longopts[@]" "$_pacman_key_longopts[@]"
;; ;;
-*) -*)
_arguments -s : \ _arguments -s : \
"$_pacman_key_options[@]" \ "$_pacman_key_options[@]" \
"$_key_shortopts[@]" \ "$_pacman_key_shortopts[@]" \
"$_key_longopts[@]" "$_pacman_key_longopts[@]"
;; ;;
*) *)
return 1 return 1
@@ -664,7 +664,7 @@ _pacman_key() {
esac esac
} }
_keys() { _pacman_key_list() {
local keylist keys local keylist keys
keylist=$(pacman-key --list-keys 2>/dev/null | awk ' keylist=$(pacman-key --list-keys 2>/dev/null | awk '
$1 == "pub" { $1 == "pub" {
@@ -733,7 +733,7 @@ _makepkg_longopts=(
'--check[Run check() function in the PKGBUILD]' '--check[Run check() function in the PKGBUILD]'
'--config[Use an alternate config file instead of '@sysconfdir@/makepkg.conf']: :_files' '--config[Use an alternate config file instead of '@sysconfdir@/makepkg.conf']: :_files'
'--holdver[Do not update VCS sources]' '--holdver[Do not update VCS sources]'
'--key[Specify key to use for gpg signing instead of the default]: :_keys' '--key[Specify key to use for gpg signing instead of the default]: :_pacman_key_list'
'--noarchive[Do not create package archive]' '--noarchive[Do not create package archive]'
'--nocheck[Do not run the check() function in the PKGBUILD]' '--nocheck[Do not run the check() function in the PKGBUILD]'
'--noprepare[Do not run the prepare() function in the PKGBUILD]' '--noprepare[Do not run the prepare() function in the PKGBUILD]'

View File

@@ -35,7 +35,7 @@ library_provides() {
continue; continue;
fi fi
mapfile -t filenames < <(find "$pkgdir/$dir" -type f | LC_ALL=C sort) mapfile -t filenames < <(find "$pkgdir/$dir" -maxdepth 1 -type f | LC_ALL=C sort)
for fn in "${filenames[@]}"; do for fn in "${filenames[@]}"; do
# check we have a shared library # check we have a shared library
@@ -44,7 +44,7 @@ library_provides() {
local sofile=$(LC_ALL=C readelf -d "$fn" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p') local sofile=$(LC_ALL=C readelf -d "$fn" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
if [[ -z "$sofile" ]]; then if [[ -z "$sofile" ]]; then
# the library is not versioned # the library has no soname
continue continue
fi fi

View File

@@ -25,18 +25,22 @@ LIBMAKEPKG_BUILDENV_SH=1
LIBRARY=${LIBRARY:-'@libmakepkgdir@'} LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
declare -a buildenv_functions build_options declare -a buildenv_functions build_options
buildenv_vars=('CPPFLAGS' 'CFLAGS' 'CXXFLAGS' 'LDFLAGS' 'MAKEFLAGS' 'CHOST')
for lib in "$LIBRARY/buildenv/"*.sh; do for lib in "$LIBRARY/buildenv/"*.sh; do
source "$lib" source "$lib"
done done
readonly -a buildenv_functions build_options readonly -a buildenv_functions buildenv_vars build_options
prepare_buildenv() { prepare_buildenv() {
# ensure this function runs first
buildenv_buildflags
for func in ${buildenv_functions[@]}; do for func in ${buildenv_functions[@]}; do
$func $func
done done
# ensure all necessary build variables are exported # ensure all necessary build variables are exported
export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS RUSTFLAGS MAKEFLAGS CHOST export ${buildenv_vars[@]}
} }

View File

@@ -26,10 +26,9 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
source "$LIBRARY/util/option.sh" source "$LIBRARY/util/option.sh"
build_options+=('buildflags') build_options+=('buildflags')
buildenv_functions+=('buildenv_buildflags')
buildenv_buildflags() { buildenv_buildflags() {
if check_option "buildflags" "n"; then if check_option "buildflags" "n"; then
unset CPPFLAGS CFLAGS DEBUG_CFLAGS CXXFLAGS DEBUG_CXXFLAGS LDFLAGS LTOFLAGS RUSTFLAGS DEBUG_RUSTFLAGS unset ${buildenv_vars[@]}
fi fi
} }

View File

@@ -32,9 +32,7 @@ buildenv_debugflags() {
if check_option "debug" "y" && ! check_option "buildflags" "n"; then if check_option "debug" "y" && ! check_option "buildflags" "n"; then
DEBUG_CFLAGS+=" -ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}" DEBUG_CFLAGS+=" -ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
DEBUG_CXXFLAGS+=" -ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}" DEBUG_CXXFLAGS+=" -ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
DEBUG_RUSTFLAGS+=" --remap-path-prefix=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
CFLAGS+=" $DEBUG_CFLAGS" CFLAGS+=" $DEBUG_CFLAGS"
CXXFLAGS+=" $DEBUG_CXXFLAGS" CXXFLAGS+=" $DEBUG_CXXFLAGS"
RUSTFLAGS+=" $DEBUG_RUSTFLAGS"
fi fi
} }

View File

@@ -6,6 +6,7 @@ sources = [
'debugflags.sh.in', 'debugflags.sh.in',
'lto.sh.in', 'lto.sh.in',
'makeflags.sh.in', 'makeflags.sh.in',
'rust.sh.in',
] ]
foreach src : sources foreach src : sources

View File

@@ -0,0 +1,36 @@
#!/usr/bin/bash
#
# rust.sh - Specify flags for building a package with rust
#
# Copyright (c) 2022 Pacman Development Team <pacman-dev@lists.archlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[[ -n "$LIBMAKEPKG_BUILDENV_RUST_SH" ]] && return
LIBMAKEPKG_BUILDENV_RUST_SH=1
LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
source "$LIBRARY/util/option.sh"
buildenv_var+=('RUSTFLAGS' 'DEBUG_RUSTFLAGS')
buildenv_functions+=('buildenv_rust')
buildenv_rust() {
if check_option "debug" "y" && ! check_option "buildflags" "n"; then
DEBUG_RUSTFLAGS+=" --remap-path-prefix=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
RUSTFLAGS+=" $DEBUG_RUSTFLAGS"
fi
}

View File

@@ -32,10 +32,10 @@ lint_config_variables() {
local array=(DLAGENTS VCSCLIENTS BUILDENV OPTIONS INTEGRITY_CHECK MAN_DIRS local array=(DLAGENTS VCSCLIENTS BUILDENV OPTIONS INTEGRITY_CHECK MAN_DIRS
DOC_DIRS PURGE_TARGETS COMPRESSGZ COMPRESSBZ2 COMPRESSXZ DOC_DIRS PURGE_TARGETS COMPRESSGZ COMPRESSBZ2 COMPRESSXZ
COMPRESSLRZ COMPRESSLZO COMPRESSZ) COMPRESSLRZ COMPRESSLZO COMPRESSZ)
local string=(CARCH CHOST CPPFLAGS CFLAGS CXXFLAGS RUSTFLAGS LDFLAGS LTOFLAGS local string=(CARCH CHOST CPPFLAGS CFLAGS CXXFLAGS LDFLAGS LTOFLAGS DEBUG_CFLAGS
DEBUG_CFLAGS DEBUG_CXXFLAGS DEBUG_RUSTFLAGS DISTCC_HOSTS BUILDDIR DEBUG_CXXFLAGS DISTCC_HOSTS BUILDDIR STRIP_BINARIES STRIP_SHARED
STRIP_BINARIES STRIP_SHARED STRIP_STATIC PKGDEST SRCDEST SRCPKGDEST STRIP_STATIC PKGDEST SRCDEST SRCPKGDEST LOGDEST PACKAGER GPGKEY
LOGDEST PACKAGER GPGKEY PKGEXT SRCEXT) PKGEXT SRCEXT)
local i keys ret=0 local i keys ret=0

View File

@@ -37,6 +37,11 @@ source_makepkg_config() {
# Source the config file; fail if it is not found # Source the config file; fail if it is not found
if [[ -r $MAKEPKG_CONF ]]; then if [[ -r $MAKEPKG_CONF ]]; then
source_safe "$MAKEPKG_CONF" source_safe "$MAKEPKG_CONF"
if [[ -d "$MAKEPKG_CONF.d" ]]; then
for c in "$MAKEPKG_CONF.d"/*.conf; do
source_safe $c
done
fi
else else
error "$(gettext "%s not found.")" "$MAKEPKG_CONF" error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
plainerr "$(gettext "Aborting...")" plainerr "$(gettext "Aborting...")"

View File

@@ -2,6 +2,7 @@ wrapped_scripts = [
'makepkg.sh.in', 'makepkg.sh.in',
'pacman-db-upgrade.sh.in', 'pacman-db-upgrade.sh.in',
'pacman-key.sh.in', 'pacman-key.sh.in',
'pkgdiff.sh.in',
'repo-add.sh.in' 'repo-add.sh.in'
] ]

View File

@@ -378,7 +378,7 @@ populate_keyring() {
key_count=$((key_count+1)) key_count=$((key_count+1))
done done
if (( key_count )); then if (( key_count )); then
msg2 "$(gettext "Disabled %s keys.")" "${key_count}" msg2 "$(ngettext "Disabled %s key." "Disabled %s keys." "${key_count}")" "${key_count}"
fi fi
fi fi
} }
@@ -506,7 +506,7 @@ lsign_keys() {
exit 1 exit 1
fi fi
if (( key_count )); then if (( key_count )); then
msg2 "$(gettext "Locally signed %s keys.")" "${key_count}" msg2 "$(ngettext "Locally signed %s key." "Locally signed %s keys." "${key_count}")" "${key_count}"
fi fi
} }
@@ -612,6 +612,16 @@ if ! type gettext &>/dev/null; then
} }
fi fi
if ! type ngettext &>/dev/null; then
ngettext() {
if (( $3 == 1 )); then
echo "$1"
else
echo "$2"
fi
}
fi
OPT_SHORT="adefhlruvV" OPT_SHORT="adefhlruvV"
OPT_LONG=('add' 'config:' 'delete' 'edit-key' 'export' 'finger' 'gpgdir:' OPT_LONG=('add' 'config:' 'delete' 'edit-key' 'export' 'finger' 'gpgdir:'
'help' 'import' 'import-trustdb' 'init' 'keyserver:' 'list-keys' 'list-sigs' 'help' 'import' 'import-trustdb' 'init' 'keyserver:' 'list-keys' 'list-sigs'

301
scripts/pkgdiff.sh.in Executable file
View File

@@ -0,0 +1,301 @@
#!/bin/bash
#
# pkgdiff - package differencing utility
#
# Copyright (c) 2022 Pacman Development Team <pacman-dev@lists.archlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# gettext initialization
export TEXTDOMAIN='pacman-scripts'
export TEXTDOMAINDIR='@localedir@'
declare -r myver='@PACKAGE_VERSION@'
declare -r confdir='@sysconfdir@'
LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
QUIET=0
USE_COLOR='y'
source "$LIBRARY"/util/compress.sh
source "$LIBRARY"/util/message.sh
source "$LIBRARY"/util/parseopts.sh
# minimal of package before a pkgdiff is generated (bytes)
min_pkg_size=$((1024*1024))
# percent of new package above which the pkgdiff will be discarded
max_diff_size=70
# ensure we have a sane umask set
umask 0022
# print usage instructions
usage() {
cmd=${0##*/}
printf "%s (pacman) %s\n\n" "$cmd" "$myver"
echo
printf -- $(gettext "Usage: pkgdiff <old> <new>\n")
echo
printf -- "$(gettext "\
pkgdiff will create a file providing the differences between two packages.\n
This file can then be added to a database using repo-add.\n")"
echo
printf -- "$(gettext "Example: pkgdiff pacman-6.0.0-1-x86_64.pkg.tar.gz pacman-6.0.1-1-x86_64.pkg.tar.gz")\n"
echo
printf -- "$(gettext "Options:\n")"
printf -- "$(gettext " -q, --quiet minimize output\n")"
printf -- "$(gettext " --nocolor remove color from output\n")"
printf -- "$(gettext " --min-pkg-size minimum package size before pkgdiffs are generated\n")"
printf -- "$(gettext " --max-diff-size percent of new package above which the pkgdiff will be discarded\n")"
}
version() {
cmd=${0##*/}
printf "%s (pacman) %s\n\n" "$cmd" "$myver"
printf -- "Copyright (c) 2022 Pacman Development Team <pacman-dev@lists.archlinux.org>.\n"
echo
printf -- "$(gettext "\
This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")"
}
trap_exit() {
# unhook all traps to avoid race conditions
trap '' EXIT TERM HUP QUIT INT ERR
echo
error "$@"
clean_up 1
}
clean_up() {
local exit_code=${1:-$?}
# unhook all traps to avoid race conditions
trap '' EXIT TERM HUP QUIT INT ERR
[[ -d $tmpdir ]] && rm -rf "$tmpdir"
exit $exit_code
}
read_pkginfo() {
unset pkgver pkgname arch
while IFS='=' read -r field value; do
# skip comments and invalid lines
[[ $field = '#'* || -z $value ]] && continue
# skip lines which aren't fields we care about
[[ $field != @(pkgver|pkgname|arch) ]] || continue
declare -g "${field% }=${value# }"
[[ $pkgname && $pkgver && $arch ]] && return 0
done < <(bsdtar -xOqf "$1" .PKGINFO 2>/dev/null)
error "$(gettext "Invalid package file '%s'.")" "$1"
return 1
}
create_pkgdiff() {
local oldfile=$1
local newfile=$2
local \
oldname oldver oldarch \
newname newver newarch \
diff_file
read_pkginfo "$oldfile" || return 1
oldname="$pkgname"
oldver="$pkgver"
oldarch="$arch"
read_pkginfo "$newfile" || return 1
newname="$pkgname"
newver="$pkgver"
newarch="$arch"
pkgsize=$(wc -c < "$newfile")
if ((pkgsize < min_pkg_size)); then
msg "$(gettext "Skipping pkgdiff creation for small package: %s - size %s")" "$newname" "$pkgsize"
return 0
fi
if [[ $oldname != "$newname" ]]; then
error "$(gettext "The package names don't match : '%s' and '%s'")" "$oldname" "$newname"
return 1
fi
if [[ $oldarch != "$newarch" ]]; then
error "$(gettext "The package architectures don't match : '%s' and '%s'")" "$oldarch" "$newarch"
return 1
fi
if [[ $oldver == "$newver" ]]; then
error "$(gettext "Both packages have the same version : '%s'")" "$newver"
return 1
fi
### TODO: check oldver < newver with vercmp ###
declare -r startdir="$(pwd -P)"
if [[ ${oldfile::1} != "/" ]]; then
oldfile=${startdir}/${oldfile}
fi
if [[ ${newfile::1} != "/" ]]; then
newfile=${startdir}/${newfile}
fi
tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/pkgdiff.XXXXXXXXXX")
pushd $tmpdir &>/dev/null
### TODO: almost everything below here is a quick hack... ###
bsdtar -xOf $oldfile .MTREE | zcat | awk '{for (i=1;i<=NF;i++){if ($i ~/^sha256/) {print $1 " " $i}}}' > ${oldver}.files
bsdtar -xOf $newfile .MTREE | zcat | awk '{for (i=1;i<=NF;i++){if ($i ~/^sha256/) {print $1 " " $i}}}' > ${newver}.files
files=($(diff -Naur ${oldver}.files ${newver}.files |
grep "^+\./" |
grep -v -e "\.BUILDINFO" -e "\.PKGINFO" |
cut -f1 -d' ' |
sed 's|+./||'))
mkdir $newname
tar -xf $newfile -C $newname
diffdir="${oldname}-${oldver}-to-${newname}-${newver}-${newarch}.pkgdiff"
mkdir $diffdir
for f in ${files[@]}; do
mkdir -p ${diffdir}/${f%/*}
cp ${newname}/$f ${diffdir}/$f
done
cp ${newname}/.{BUILD,PKG}INFO ${diffdir}
### TODO: this should use libmakepkg/compress - need PKGEXT from makepkg.conf ###
### TODO: collect files in same order as makepkg ###
tar -cf ${diffdir}.tar ${diffdir}
zstd -T0 --ultra -20 ${diffdir}.tar &> /dev/null
diff_file=${diffdir}.tar.zst
diffsize=$(wc -c < "$diff_file")
if ((max_diff_size * pkgsize / 100 < diffsize)); then
msg "$(gettext "pkgdiff larger than maximum size. Removing.")"
rm -f "$diff_file"
return 0
fi
popd &>/dev/null
mv ${tmpdir}/${diff_file} .
msg "$(gettext "Generated pkgdiff : '%s'")" "$diff_file"
(( QUIET )) && echo "$diff_file"
return 0
}
# PROGRAM START
# determine whether we have gettext; make it a no-op if we do not
if ! type gettext &>/dev/null; then
gettext() {
echo "$@"
}
fi
case $1 in
-h|--help) usage; exit 0;;
-V|--version) version; exit 0;;
esac
trap 'clean_up' EXIT
for signal in TERM HUP QUIT; do
trap "trap_exit \"$(gettext "%s signal caught. Exiting...")\" \"$signal\"" "$signal"
done
trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
OPT_SHORT='hqV'
OPT_LONG=('help' 'quiet' 'max-diff-size:' 'min-pkg-size:' 'nocolor' 'version')
if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
exit 1
fi
set -- "${OPTRET[@]}"
unset OPT_SHORT OPT_LONG OPTRET
# parse options
while :; do
case $1 in
-h|--help)
usage
exit 0 ;;
-V|--version)
version
exit 0 ;;
-q|--quiet)
QUIET=1;;
--nocolor)
USE_COLOR='n';;
--min-pkg-size)
### TODO ###
shift ;;
--max-delta-size)
### TODO ###
shift ;;
--)
shift
break ;;
esac
shift
done
# check if messages are to be printed using color
if [[ -t 2 && $USE_COLOR != "n" ]]; then
colorize
else
unset ALL_OFF BOLD BLUE GREEN RED YELLOW
fi
if (( $# != 2 )); then
usage
exit 1
fi
for i in "$@"; do
if [[ ! -f $i ]]; then
error "$(gettext "File '%s' does not exist")" "$i"
exit 1
fi
done
### TODO: the creation of the pkgdiff should be done in fakeroot ###
create_pkgdiff "$@"

View File

@@ -65,7 +65,7 @@ Use the "help" option to get the full list of parameters:
When run with the `--valgrind' option, an additional rule will be added to all When run with the `--valgrind' option, an additional rule will be added to all
tests to check for memory leaks. To use `--valgrind' when running the full tests to check for memory leaks. To use `--valgrind' when running the full
test suite, run: test suite, run:
make PY_LOG_FLAGS=--valgrind check PACTEST_VALGRIND=1 ninja test
The following pieces of software are required to run the pactest suite: The following pieces of software are required to run the pactest suite: