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.

95 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. delete_empty_dirs() {
  41. local dst_dir="$1"
  42. if [ -d "$dst_dir/usr" ] ; then
  43. find "$dst_dir/usr" -empty -type d -delete
  44. fi
  45. }
  46. ver="$1"
  47. src_dir="$2"
  48. dst_dir="$3"
  49. python="$4"
  50. mode="$5"
  51. filespec="$6"
  52. find "$src_dir" -name "*.exe" -delete
  53. process_filespec "$src_dir" "$dst_dir" "$filespec" || {
  54. echo "process filespec error-ed"
  55. exit 1
  56. }
  57. if [ "$mode" == "sources" ] ; then
  58. # Copy only python source files
  59. find "$dst_dir" -not -type d -not -name "*.py" -delete
  60. delete_empty_dirs "$dst_dir"
  61. exit 0
  62. fi
  63. if [ "$ver" == "3" ] ; then
  64. legacy="-b"
  65. fi
  66. # default max recursion is 10
  67. max_recursion_level=20
  68. # XXX [So that you won't goof as I did]
  69. # Note: Yes, I tried to use the -O & -OO flags here.
  70. # However the generated byte-codes were not portable.
  71. # So, we just stuck to un-optimized byte-codes,
  72. # which is still way better/faster than running
  73. # Python sources all the time.
  74. $python -m compileall -r "$max_recursion_level" $legacy -d '/' "$dst_dir" || {
  75. echo "python -m compileall err-ed"
  76. exit 1
  77. }
  78. # Delete source files and pyc [ un-optimized bytecode files ]
  79. # We may want to make this optimization thing configurable later, but not sure atm
  80. find "$dst_dir" -type f -name "*.py" -delete
  81. delete_empty_dirs "$dst_dir"
  82. exit 0