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.

282 rivejä
7.5 KiB

9 vuotta sitten
9 vuotta sitten
  1. #!/usr/bin/env bats
  2. load test_helper
  3. export PYTHON_BUILD_CACHE_PATH="$TMP/cache"
  4. export MAKE=make
  5. export MAKE_OPTS="-j 2"
  6. export CC=cc
  7. export TMP_FIXTURES="$TMP/fixtures"
  8. setup() {
  9. mkdir -p "$INSTALL_ROOT"
  10. stub md5 false
  11. stub curl false
  12. }
  13. executable() {
  14. local file="$1"
  15. mkdir -p "${file%/*}"
  16. cat > "$file"
  17. chmod +x "$file"
  18. }
  19. cached_tarball() {
  20. mkdir -p "$PYTHON_BUILD_CACHE_PATH"
  21. pushd "$PYTHON_BUILD_CACHE_PATH" >/dev/null
  22. tarball "$@"
  23. popd >/dev/null
  24. }
  25. tarball() {
  26. local name="$1"
  27. local path="$PWD/$name"
  28. local configure="$path/configure"
  29. shift 1
  30. executable "$configure" <<OUT
  31. #!$BASH
  32. echo "$name: CPPFLAGS=\\"\$CPPFLAGS\\" LDFLAGS=\\"\$LDFLAGS\\"" >> build.log
  33. echo "$name: \$@" \${PYTHONOPT:+PYTHONOPT=\$PYTHONOPT} >> build.log
  34. OUT
  35. for file; do
  36. mkdir -p "$(dirname "${path}/${file}")"
  37. touch "${path}/${file}"
  38. done
  39. tar czf "${path}.tar.gz" -C "${path%/*}" "$name"
  40. }
  41. stub_make_install() {
  42. stub "$MAKE" \
  43. " : echo \"$MAKE \$@\" >> build.log" \
  44. "install : echo \"$MAKE \$@\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'"
  45. }
  46. assert_build_log() {
  47. run cat "$INSTALL_ROOT/build.log"
  48. assert_output
  49. }
  50. install_patch() {
  51. local name="$1"
  52. local patch="$2"
  53. [ -n "$patch" ] || patch="python.patch"
  54. mkdir -p "${TMP_FIXTURES}/${name%/*}/patches/${name##*/}/${patch%/*}"
  55. cat > "${TMP_FIXTURES}/${name%/*}/patches/${name##*/}/${patch}"
  56. }
  57. install_tmp_fixture() {
  58. local args
  59. while [ "${1#-}" != "$1" ]; do
  60. args="$args $1"
  61. shift 1
  62. done
  63. local name="$1"
  64. local destination="$2"
  65. [ -n "$destination" ] || destination="$INSTALL_ROOT"
  66. # Copy fixture to temporary path
  67. mkdir -p "${TMP_FIXTURES}/${name%/*}"
  68. cp "${FIXTURE_ROOT}/${name}" "${TMP_FIXTURES}/${name}"
  69. run python-build $args "$TMP_FIXTURES/$name" "$destination"
  70. }
  71. resolve_link() {
  72. $(type -p greadlink readlink | head -1) "$1"
  73. }
  74. @test "apply built-in python patch before building" {
  75. cached_tarball "Python-3.2.1"
  76. stub brew false
  77. stub_make_install
  78. stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
  79. echo | install_patch definitions/vanilla-python "Python-3.2.1/empty.patch"
  80. TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null
  81. assert_success
  82. assert_build_log <<OUT
  83. patch -p0 --force -i $TMP/python-patch.XXX
  84. Python-3.2.1: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
  85. Python-3.2.1: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
  86. make -j 2
  87. make install
  88. OUT
  89. unstub make
  90. unstub patch
  91. }
  92. @test "apply built-in python patches should be sorted by its name" {
  93. cached_tarball "Python-3.2.1"
  94. stub brew false
  95. stub_make_install
  96. stub patch ' : for arg; do [[ "$arg" == "-"* ]] || sed -e "s/^/patch: /" "$arg"; done >> build.log'
  97. echo "foo" | install_patch definitions/vanilla-python "Python-3.2.1/foo.patch"
  98. echo "bar" | install_patch definitions/vanilla-python "Python-3.2.1/bar.patch"
  99. echo "baz" | install_patch definitions/vanilla-python "Python-3.2.1/baz.patch"
  100. TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null
  101. assert_success
  102. assert_build_log <<OUT
  103. patch: bar
  104. patch: baz
  105. patch: foo
  106. Python-3.2.1: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
  107. Python-3.2.1: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
  108. make -j 2
  109. make install
  110. OUT
  111. unstub make
  112. unstub patch
  113. }
  114. @test "allow custom make install target" {
  115. cached_tarball "Python-3.2.1"
  116. stub brew false
  117. stub "$MAKE" \
  118. " : echo \"$MAKE \$@\" >> build.log" \
  119. " : echo \"$MAKE \$@\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'"
  120. PYTHON_MAKE_INSTALL_TARGET="altinstall" TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null
  121. assert_success
  122. assert_build_log <<OUT
  123. Python-3.2.1: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
  124. Python-3.2.1: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
  125. make -j 2
  126. make altinstall
  127. OUT
  128. unstub make
  129. }
  130. @test "ensurepip without altinstall" {
  131. mkdir -p "${INSTALL_ROOT}/bin"
  132. cat <<OUT > "${INSTALL_ROOT}/bin/python"
  133. #!$BASH
  134. echo "python \$@" >> "${INSTALL_ROOT}/build.log"
  135. OUT
  136. chmod +x "${INSTALL_ROOT}/bin/python"
  137. PYTHON_MAKE_INSTALL_TARGET="" TMPDIR="$TMP" run_inline_definition <<OUT
  138. build_package_ensurepip
  139. OUT
  140. assert_success
  141. assert_build_log <<OUT
  142. python -s -m ensurepip
  143. OUT
  144. }
  145. @test "ensurepip with altinstall" {
  146. mkdir -p "${INSTALL_ROOT}/bin"
  147. cat <<OUT > "${INSTALL_ROOT}/bin/python"
  148. #!$BASH
  149. echo "python \$@" >> "${INSTALL_ROOT}/build.log"
  150. OUT
  151. chmod +x "${INSTALL_ROOT}/bin/python"
  152. PYTHON_MAKE_INSTALL_TARGET="altinstall" TMPDIR="$TMP" run_inline_definition <<OUT
  153. build_package_ensurepip
  154. OUT
  155. assert_success
  156. assert_build_log <<OUT
  157. python -s -m ensurepip --altinstall
  158. OUT
  159. }
  160. @test "python3-config" {
  161. mkdir -p "${INSTALL_ROOT}/bin"
  162. touch "${INSTALL_ROOT}/bin/python3"
  163. chmod +x "${INSTALL_ROOT}/bin/python3"
  164. touch "${INSTALL_ROOT}/bin/python3.4"
  165. chmod +x "${INSTALL_ROOT}/bin/python3.4"
  166. touch "${INSTALL_ROOT}/bin/python3-config"
  167. chmod +x "${INSTALL_ROOT}/bin/python3-config"
  168. touch "${INSTALL_ROOT}/bin/python3.4-config"
  169. chmod +x "${INSTALL_ROOT}/bin/python3.4-config"
  170. TMPDIR="$TMP" run_inline_definition <<OUT
  171. verify_python python3.4
  172. OUT
  173. assert_success
  174. [ -L "${INSTALL_ROOT}/bin/python" ]
  175. [ -L "${INSTALL_ROOT}/bin/python-config" ]
  176. [[ "$(resolve_link "${INSTALL_ROOT}/bin/python")" == "python3.4" ]]
  177. [[ "$(resolve_link "${INSTALL_ROOT}/bin/python-config")" == "python3.4-config" ]]
  178. }
  179. @test "--enable-framework" {
  180. mkdir -p "${INSTALL_ROOT}/Python.framework/Versions/Current/bin"
  181. touch "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3"
  182. chmod +x "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3"
  183. touch "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3.4"
  184. chmod +x "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3.4"
  185. touch "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3-config"
  186. chmod +x "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3-config"
  187. touch "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3.4-config"
  188. chmod +x "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3.4-config"
  189. stub uname '-s : echo Darwin'
  190. PYTHON_CONFIGURE_OPTS="--enable-framework" TMPDIR="$TMP" run_inline_definition <<OUT
  191. echo "PYTHON_CONFIGURE_OPTS_ARRAY=(\${PYTHON_CONFIGURE_OPTS_ARRAY[@]})"
  192. verify_python python3.4
  193. OUT
  194. assert_success
  195. assert_output <<EOS
  196. PYTHON_CONFIGURE_OPTS_ARRAY=(--libdir=${TMP}/install/lib --enable-framework=${TMP}/install)
  197. EOS
  198. [ -L "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python" ]
  199. [ -L "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python-config" ]
  200. }
  201. @test "--enable-universalsdk" {
  202. stub uname '-s : echo Darwin'
  203. PYTHON_CONFIGURE_OPTS="--enable-universalsdk" TMPDIR="$TMP" run_inline_definition <<OUT
  204. echo "PYTHON_CONFIGURE_OPTS_ARRAY=(\${PYTHON_CONFIGURE_OPTS_ARRAY[@]})"
  205. OUT
  206. assert_success
  207. assert_output <<EOS
  208. PYTHON_CONFIGURE_OPTS_ARRAY=(--libdir=${TMP}/install/lib --enable-universalsdk=/ --with-universal-archs=intel)
  209. EOS
  210. }
  211. @test "default MACOSX_DEPLOYMENT_TARGET" {
  212. stub uname '-s : echo Darwin'
  213. stub sw_vers '-productVersion : echo 10.10'
  214. TMPDIR="$TMP" run_inline_definition <<OUT
  215. echo "\${MACOSX_DEPLOYMENT_TARGET}"
  216. OUT
  217. assert_success
  218. assert_output "10.10"
  219. }
  220. @test "use custom MACOSX_DEPLOYMENT_TARGET if defined" {
  221. stub uname '-s : echo Darwin'
  222. MACOSX_DEPLOYMENT_TARGET="10.4" TMPDIR="$TMP" run_inline_definition <<OUT
  223. echo "\${MACOSX_DEPLOYMENT_TARGET}"
  224. OUT
  225. assert_success
  226. assert_output "10.4"
  227. }