You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.2 KiB

  1. #!/bin/sh
  2. set -e
  3. [ -z "$SOURCE_DATE_EPOCH" ] || {
  4. PYTHONHASHSEED="$SOURCE_DATE_EPOCH"
  5. export PYTHONHASHSEED
  6. }
  7. process_filespec() {
  8. local src_dir="$1"
  9. local dst_dir="$2"
  10. local filespec="$3"
  11. echo "$filespec" | (
  12. IFS='|'
  13. while read fop fspec fperm; do
  14. local fop=`echo "$fop" | tr -d ' \t\n'`
  15. if [ "$fop" = "+" ]; then
  16. if [ ! -e "${src_dir}${fspec}" ]; then
  17. echo "File not found '${src_dir}${fspec}'"
  18. exit 1
  19. fi
  20. dpath=`dirname "$fspec"`
  21. if [ -z "$fperm" ]; then
  22. dperm=`stat -c "%a" ${src_dir}${dpath}`
  23. fi
  24. mkdir -p -m$dperm ${dst_dir}${dpath}
  25. echo "copying: '$fspec'"
  26. cp -fpR ${src_dir}${fspec} ${dst_dir}${dpath}/
  27. if [ -n "$fperm" ]; then
  28. chmod -R $fperm ${dst_dir}${fspec}
  29. fi
  30. elif [ "$fop" = "-" ]; then
  31. echo "removing: '$fspec'"
  32. rm -fR ${dst_dir}${fspec}
  33. elif [ "$fop" = "=" ]; then
  34. echo "setting permissions: '$fperm' on '$fspec'"
  35. chmod -R $fperm ${dst_dir}${fspec}
  36. fi
  37. done
  38. )
  39. }
  40. ver="$1"
  41. src_dir="$2"
  42. dst_dir="$3"
  43. python="$4"
  44. mode="$5"
  45. filespec="$6"
  46. process_filespec "$src_dir" "$dst_dir" "$filespec" || {
  47. echo "process filespec error-ed"
  48. exit 1
  49. }
  50. if [ "$mode" == "sources" ] ; then
  51. # Copy only python source files
  52. find $dst_dir -not -type d -not -name "*\.py" | xargs rm -f
  53. # Delete empty folders (if the case)
  54. if [ -d "$dst_dir/usr" ] ; then
  55. find $dst_dir/usr -type d | xargs rmdir --ignore-fail-on-non-empty
  56. rmdir --ignore-fail-on-non-empty $dst_dir/usr
  57. fi
  58. exit 0
  59. fi
  60. legacy=
  61. [ "$ver" == "3" ] && legacy="-b"
  62. # XXX [So that you won't goof as I did]
  63. # Note: Yes, I tried to use the -O & -OO flags here.
  64. # However the generated byte-codes were not portable.
  65. # So, we just stuck to un-optimized byte-codes,
  66. # which is still way better/faster than running
  67. # Python sources all the time.
  68. $python -m compileall $legacy -d '/' $dst_dir || {
  69. echo "python -m compileall err-ed"
  70. exit 1
  71. }
  72. # Delete source files and pyc [ un-optimized bytecode files ]
  73. # We may want to make this optimization thing configurable later, but not sure atm
  74. find $dst_dir -type f -name "*\.py" | xargs rm -f
  75. # Delete empty folders (if the case)
  76. if [ -d "$dst_dir/usr" ] ; then
  77. find $dst_dir/usr -type d | xargs rmdir --ignore-fail-on-non-empty
  78. rmdir --ignore-fail-on-non-empty $dst_dir/usr
  79. fi
  80. exit 0