From 832934efd633de3fa0051bfb30e94b64c885f542 Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Mon, 12 Feb 2018 10:52:02 -0600 Subject: icecc-create-env: Symlink alternate names Instead of renaming files to a new path in the toolchain archive, keep the files with their original paths and create a relative symbolic link from the new path to the original file. (From OE-Core rev: 256f8f6cc5b520b59cfdc44aa076f71990e18e2c) Signed-off-by: Joshua Watt Signed-off-by: Richard Purdie --- .../icecc-create-env/icecc-create-env | 64 +++++++++++++++++++--- 1 file changed, 57 insertions(+), 7 deletions(-) (limited to 'meta/recipes-devtools/icecc-create-env/icecc-create-env/icecc-create-env') diff --git a/meta/recipes-devtools/icecc-create-env/icecc-create-env/icecc-create-env b/meta/recipes-devtools/icecc-create-env/icecc-create-env/icecc-create-env index 7636d090a4..0791bd54b2 100755 --- a/meta/recipes-devtools/icecc-create-env/icecc-create-env/icecc-create-env +++ b/meta/recipes-devtools/icecc-create-env/icecc-create-env/icecc-create-env @@ -21,10 +21,28 @@ is_contained () esac } +normalize_path () +{ + # Normalizes the path to a file or directory, removing all "." and ".." + # entries. Use pwd -L to explicitly prevent symlink expansion + local path=$1 + if test -f "$path"; then + pushd $(dirname $path) > /dev/null 2>&1 + dir_path=$(pwd -L) + path=$dir_path/$(basename $path) + popd > /dev/null 2>&1 + elif test -d "$path"; then + pushd $path > /dev/null 2>&1 + path=$(pwd -L) + popd > /dev/null 2>&1 + fi + echo $path +} + add_file () { - local name="$1" - local path="$1"; + local path=`normalize_path $1` + local name="$path" if test -n "$2"; then name="$2" fi @@ -129,7 +147,7 @@ if test -n "$specfile" && test -e "$specfile"; then fi ltofile=`$added_gcc -print-prog-name=lto1` -pluginfile="${ltofile%lto1}liblto_plugin.so" +pluginfile=`normalize_path "${ltofile%lto1}liblto_plugin.so"` if test -r "$pluginfile" then add_file $pluginfile ${pluginfile#*usr} @@ -146,6 +164,19 @@ else exit 1 fi +link_rel () +{ + local target="$1" + local name="$2" + local base="$3" + + local prefix=`dirname $name` + + prefix=`echo $prefix | sed 's,[^/]\+,..,g' | sed 's,^/*,,g'` + + ln -s $prefix/$target $base/$name +} + tempdir=`mktemp -d /tmp/iceccenvXXXXXX` new_target_files= for i in $target_files; do @@ -159,11 +190,30 @@ for i in $target_files; do target=$i ;; esac - mkdir -p $tempdir/`dirname $target` - cp -p $path $tempdir/$target - if test -f $tempdir/$target -a -x $tempdir/$target; then - strip -s $tempdir/$target 2>/dev/null + if test "$target" == "$path"; then + mkdir -p $tempdir/`dirname $target` + cp -pH $target $tempdir/$target + + if test -f $tempdir/$target -a -x $tempdir/$target; then + strip -s $tempdir/$target 2>/dev/null + fi + else + mkdir -p $tempdir/`dirname $path` + cp -pH $path $tempdir/$path + + mkdir -p $tempdir/`dirname $target` + # Relative links are used because the files are checked for being + # executable outside the chroot + link_rel $path $target $tempdir + + if test -f $tempdir/$path -a -x $tempdir/$path; then + strip -s $tempdir/$path 2>/dev/null + fi + + path=`echo $path | cut -b2-` + new_target_files="$new_target_files $path" fi + target=`echo $target | cut -b2-` new_target_files="$new_target_files $target" done -- cgit v1.2.3-54-g00ecf