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.

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