Skip to content

Commit

Permalink
test for symbol to pkg version map
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncaen committed Dec 30, 2019
1 parent cc5d5c0 commit 4d6e68d
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
60 changes: 60 additions & 0 deletions common/hooks/pre-pkg/07-shlib-symbols.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This hook executes the following tasks:
# - generates shlib-provides file for xbps-create(8)

get_symbols() {
local _destdir="$1" _fname="$2" _soname="$3"
local _addr _type _sym
local _path="${_fname#$_destdir}"
_path=${_path%/*}
$NM -Dg --defined-only $_fname | while read _addr _type _sym; do
echo "${_path}/$_soname $_sym ${pkgname}-${version}"
echo "${_path}/$_soname $_sym ${pkgname}-${version}" >&2
done
}

get_old_symbols() {
local _destdir="$1" _fname="$2"
$XBPS_QUERY_CMD -R --cat "/usr/lib/symbols/${pkgname}" "$pkgname" || :
}

merge_symbols() {
awk '
{x[$1][$2]=$3}
END{
for (k in x) for (k1 in x[k]) printf "%s %s %s\n",k,k1,x[k][k1]
}'
}

collect_symbols() {
local _destdir="$1"
local _soname

if [ ! -d ${_destdir} ]; then
return 0
fi
mkdir -p "${_destdir}/usr/lib/symbols"

find ${_destdir} -type f -name "*.so*" | while read f; do
_fname="${f##*/}"
case "$(file -bi "$f")" in
application/x-sharedlib*|application/x-pie-executable*)
_soname=$(${OBJDUMP} -p "$f"|grep SONAME|awk '{print $2}')
get_symbols "$_destdir" "$f" "$_soname"
get_old_symbols "$_destdir" "$f" "$_soname"
;;
esac
done | merge_symbols >"${_destdir}/usr/lib/symbols/${pkgname}"
}

hook() {
local _destdir32=${XBPS_DESTDIR}/${pkgname}-32bit-${version}

if [ -z "$shlib_provides" -a "${archs// /}" = "noarch" -o -n "$noshlibprovides" ]; then
return 0
fi

# native pkg
collect_symbols ${PKGDESTDIR}
# 32bit pkg
collect_symbols ${_destdir32}
}
1 change: 1 addition & 0 deletions common/shlibs
Original file line number Diff line number Diff line change
Expand Up @@ -3709,3 +3709,4 @@ libnvpair.so.1 zfs-0.8.2_1
libjsonnet.so.0 jsonnet-0.14.0_2
libjsonnet++.so.0 jsonnet-0.14.0_2
libigdgmm.so.12 intel-gmmlib-19.3.4_1
libtestlib.so.0 testlib-0.1_1
30 changes: 30 additions & 0 deletions srcpkgs/testbin/template
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Template file for 'testbin'
pkgname=testbin
version=0.2
revision=1
hostmakedepends=""
makedepends="testlib-devel"
depends=""
short_desc="symbol package version test"
maintainer="Duncaen <duncaen@voidlinux.org>"
license="BSD-2-clause"
homepage="https://voidlinux.org"

do_build() {
echo "#include <stdio.h>" >main.c
echo "#include <testlib.h>" >>main.c
case "${version}" in
0.1)
echo 'int main(void) { printf("%d\n", foo()); return 0; }' >>main.c
;;
0.2)
echo 'int main(void) { printf("%d %d\n", foo(), bar()); return 0; }' >>main.c
;;
esac
$CC $CFLAGS -c -o main.o main.c
$CC $LDFLAGS -o testbin main.c -ltestlib
}

do_install() {
vbin testbin
}
1 change: 1 addition & 0 deletions srcpkgs/testlib-devel
50 changes: 50 additions & 0 deletions srcpkgs/testlib/template
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Template file for 'testlib'
pkgname=testlib
version=0.2
revision=1
hostmakedepends=""
makedepends=""
depends=""
short_desc="symbol package version test"
maintainer="Duncaen <duncaen@voidlinux.org>"
license="BSD-2-clause"
homepage="https://voidlinux.org"

do_build() {
case "$version" in
0.1)
echo "int foo(void);" >testlib.h
echo "int foo(void) { return 1; }" >testlib.c
$CC $CFLAGS -c -o testlib.o testlib.c
$CC -shared $LDFLAGS -Wl,-soname,libtestlib.so.0 testlib.o -o libtestlib.so.${version}
ln -sf libtestlib.so.${version} libtestlib.so.0
ln -sf libtestlib.so.${version} libtestlib.so
;;
0.2)
echo "int foo(void);" >testlib.h
echo "int bar(void);" >>testlib.h
echo "int foo(void) { return 1; }" >testlib.c
echo "int bar(void) { return 1; }" >>testlib.c
$CC $CFLAGS -c -o testlib.o testlib.c
$CC -shared $LDFLAGS -Wl,-soname,libtestlib.so.0 testlib.o -o libtestlib.so.${version}
ln -sf libtestlib.so.${version} libtestlib.so.0
ln -sf libtestlib.so.${version} libtestlib.so
;;
esac
}

do_install() {
vmkdir usr/lib
vinstall libtestlib.so.${version} 755 usr/lib
vcopy libtestlib.so* usr/lib
vinstall testlib.h 644 usr/include
}

testlib-devel_package() {
short_desc+=" - development files"
depends="${sourcepkg}>=${version}_${revision}"
pkg_install() {
vmove usr/include
vmove "usr/lib/*.so"
}
}
29 changes: 29 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

mktestlib() {
local version="$1"
sed -i "s/version=.*/version=$version/" srcpkgs/testlib/template
./xbps-src -f pkg testlib >/dev/null || exit 1
echo "symbols for $version:"
xbps-query \
--repository=hostdir/binpkgs/ \
--repository=hostdir/binpkgs/symbol-map \
--cat /usr/lib/symbols/testlib testlib || exit 1
}

mktestbin() {
local version="$1"
sed -i "s/version=.*/version=$version/" srcpkgs/testbin/template
./xbps-src -f pkg testbin >/dev/null || exit 1
echo "deps for testbin-$version:"
xbps-query \
--repository=hostdir/binpkgs/ \
--repository=hostdir/binpkgs/symbol-map \
-x testbin || exit 1
}

rm -rf hostdir/binpkgs/symbol-map
mktestlib "0.1"
mktestbin "0.1"
mktestlib "0.2"
mktestbin "0.2"

0 comments on commit 4d6e68d

Please sign in to comment.