Skip to content

Commit

Permalink
Reduce bloat in the output zip package
Browse files Browse the repository at this point in the history
Avoid dereferencing symlinks when iterating over libc files. Otherwise,
we end up with two copies of the same file, one with the symlink name
and the actual file.

Files which are directly linked to the executable are listed (in the
ldd output) by their symlink name. Those are fine to dereference
because there's only a single mention of them. The actual (dereferenced)
file is not listed in output from ldd.
  • Loading branch information
marcomagdy committed Dec 27, 2018
1 parent 0ce4d7a commit 9df7041
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packaging/packager
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ libc_libs+=$(package_libc_via_dpkg)
libc_libs+=$(package_libc_via_rpm)
libc_libs+=$(package_libc_via_pacman)

if [[ $INCLUDE_LIBC == true ]]; then
list+=$libc_libs;
fi

mkdir -p "$PKG_DIR/bin" "$PKG_DIR/lib"

for i in $list
Expand All @@ -101,19 +97,26 @@ do
continue
fi

if [[ $INCLUDE_LIBC == false ]]; then
matched=$(echo $libc_libs | grep --count $i) || true # prevent the non-zero exit status from terminating the script
if [ $matched -gt 0 ]; then
continue
fi
# Do not copy libc files which are directly linked
matched=$(echo $libc_libs | grep --count $i) || true # prevent the non-zero exit status from terminating the script
if [ $matched -gt 0 ]; then
continue
fi

cp $i $PKG_DIR/lib
filename=`basename $i`
if [[ -z "${filename##ld-*}" ]]; then
PKG_LD=$filename # Use this file as the loader
fi
done

if [[ $INCLUDE_LIBC == true ]]; then
for i in $libc_libs
do
cp --no-dereference $i $PKG_DIR/lib
done
fi

bootstrap_script=$(cat <<EOF
#!/bin/bash
set -euo pipefail
Expand All @@ -140,7 +143,7 @@ fi
chmod +x "$PKG_DIR/bootstrap"
# some shenanigans to create the right layout in the zip file without extraneous directories
pushd "$PKG_DIR" > /dev/null
zip -r $PKG_BIN_FILENAME.zip *
zip -yr $PKG_BIN_FILENAME.zip *
ORIGIN_DIR=$(dirs -l +1)
mv $PKG_BIN_FILENAME.zip $ORIGIN_DIR
popd > /dev/null
Expand Down

0 comments on commit 9df7041

Please sign in to comment.