Skip to content

Commit

Permalink
use exported functions instead
Browse files Browse the repository at this point in the history
potentially fixes NVIDIA#3769, NVIDIA#3783

Signed-off-by: Gera Shegalov [email protected]
  • Loading branch information
NvTimLiu committed Oct 12, 2021
1 parent 6e36043 commit 03df549
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions dist/scripts/binary-dedupe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set -ex
}

SPARK3XX_COMMON_TXT=$PWD/spark3xx-common.txt
SPARK3XX_COMMON_DIR=$PWD/spark3xx-common
export SPARK3XX_COMMON_DIR=$PWD/spark3xx-common

# This script de-duplicates .class files at the binary level.
# We could also diff classes using scalap / javap outputs.
Expand All @@ -47,16 +47,23 @@ find . -path './parallel-world/spark*' -type f -name '*class' | \
sort -k3 -k2,2 -u | uniq -f 2 -c | grep '^\s\+1 .*' | \
awk '{$1=""; $3=""; print $0 }' | tr -s ' ' | sed 's/\ /\//g' > "$SPARK3XX_COMMON_TXT"

remove_duplicates() {
set -x
class_resource=$1
shim=$(<<< "$class_resource" cut -d'/' -f 2)
class_file=$(<<< "$class_resource" cut -d'/' -f 3-)
class_dir=$(dirname "$class_file")
dest_dir="$SPARK3XX_COMMON_DIR/$class_dir"
mkdir -p "$dest_dir"
cp "./parallel-world/$shim/$class_file" "$dest_dir/"
find ./parallel-world -path './parallel-world/spark3*/'"$class_file" | xargs rm || \
exit 255
}
export -f remove_duplicates

echo "Deleting duplicates of spark3xx-common classes"
xargs --arg-file="$SPARK3XX_COMMON_TXT" -P 6 -n 1 -I% bash -c "
shim=\$(echo '%' | cut -d'/' -f 2)
class_file=\$(echo '%' | cut -d'/' -f 3-)
class_dir=\$(dirname \$class_file)
dest_dir=$SPARK3XX_COMMON_DIR/\$class_dir
mkdir -p \$dest_dir && \
cp ./parallel-world/\$shim\/\$class_file \$dest_dir/ && \
find ./parallel-world -path './parallel-world/spark3*/'\$class_file -exec rm {} + || exit 255
"
# https://stackoverflow.com/questions/11003418/calling-shell-functions-with-xargs
xargs --arg-file="$SPARK3XX_COMMON_TXT" -P 6 -n 1 -I% bash -c 'remove_duplicates "$@"' _ %

mv "$SPARK3XX_COMMON_DIR" parallel-world/

Expand Down Expand Up @@ -102,5 +109,6 @@ for classFile in $(< $UNSHIMMED_LIST_TXT); do
done

# Remove unshimmed classes from parallel worlds
echo Removing duplicates of unshimmed classes
xargs --arg-file="$UNSHIMMED_LIST_TXT" -P 6 -n 100 -I% \
find . -path './parallel-world/spark*/%' -exec rm {} +
find . -path './parallel-world/spark*/%' | xargs rm || exit 255

0 comments on commit 03df549

Please sign in to comment.