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.

381 lines
9.8 KiB

пре 3 година
пре 3 година
пре 3 година
  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 PYTHON_BUILD_HTTP_CLIENT="curl"
  8. export TMP_FIXTURES="$TMP/fixtures"
  9. setup() {
  10. mkdir -p "$INSTALL_ROOT"
  11. stub md5 false
  12. stub curl false
  13. }
  14. executable() {
  15. local file="$1"
  16. mkdir -p "${file%/*}"
  17. cat > "$file"
  18. chmod +x "$file"
  19. }
  20. cached_tarball() {
  21. mkdir -p "$PYTHON_BUILD_CACHE_PATH"
  22. pushd "$PYTHON_BUILD_CACHE_PATH" >/dev/null
  23. tarball "$@"
  24. popd >/dev/null
  25. }
  26. tarball() {
  27. local name="$1"
  28. local path="$PWD/$name"
  29. local configure="$path/configure"
  30. shift 1
  31. executable "$configure" <<OUT
  32. #!$BASH
  33. echo "$name: CPPFLAGS=\\"\$CPPFLAGS\\" LDFLAGS=\\"\$LDFLAGS\\"" >> build.log
  34. echo "$name: \$@" \${PYTHONOPT:+PYTHONOPT=\$PYTHONOPT} >> build.log
  35. OUT
  36. for file; do
  37. mkdir -p "$(dirname "${path}/${file}")"
  38. touch "${path}/${file}"
  39. done
  40. tar czf "${path}.tar.gz" -C "${path%/*}" "$name"
  41. }
  42. stub_make_install() {
  43. stub "$MAKE" \
  44. " : echo \"$MAKE \$@\" >> build.log" \
  45. "install : echo \"$MAKE \$@\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'"
  46. }
  47. assert_build_log() {
  48. run cat "$INSTALL_ROOT/build.log"
  49. assert_output
  50. }
  51. install_patch() {
  52. local name="$1"
  53. local patch="$2"
  54. [ -n "$patch" ] || patch="python.patch"
  55. mkdir -p "${TMP_FIXTURES}/${name%/*}/patches/${name##*/}/${patch%/*}"
  56. cat > "${TMP_FIXTURES}/${name%/*}/patches/${name##*/}/${patch}"
  57. }
  58. install_tmp_fixture() {
  59. local args
  60. while [ "${1#-}" != "$1" ]; do
  61. args="$args $1"
  62. shift 1
  63. done
  64. local name="$1"
  65. local destination="$2"
  66. [ -n "$destination" ] || destination="$INSTALL_ROOT"
  67. # Copy fixture to temporary path
  68. mkdir -p "${TMP_FIXTURES}/${name%/*}"
  69. cp "${FIXTURE_ROOT}/${name}" "${TMP_FIXTURES}/${name}"
  70. run python-build $args "$TMP_FIXTURES/$name" "$destination"
  71. }
  72. resolve_link() {
  73. $(type -p greadlink readlink | head -1) "$1"
  74. }
  75. run_inline_definition_with_name() {
  76. local definition_name="build-definition"
  77. case "$1" in
  78. "--name="* )
  79. local definition_name="${1#--name=}"
  80. shift 1
  81. ;;
  82. esac
  83. local definition="${TMP}/${definition_name}"
  84. cat > "$definition"
  85. run python-build "$definition" "${1:-$INSTALL_ROOT}"
  86. }
  87. @test "apply built-in python patch before building" {
  88. cached_tarball "Python-3.6.2"
  89. stub brew false
  90. stub_make_install
  91. stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
  92. echo | install_patch definitions/vanilla-python "Python-3.6.2/empty.patch"
  93. # yyuu/pyenv#257
  94. stub uname '-s : echo Linux'
  95. stub uname '-s : echo Linux'
  96. TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null
  97. assert_success
  98. assert_build_log <<OUT
  99. patch -p0 --force -i $TMP/python-patch.XXX
  100. Python-3.6.2: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
  101. Python-3.6.2: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
  102. make -j 2
  103. make install
  104. OUT
  105. unstub make
  106. unstub patch
  107. }
  108. @test "apply built-in python patches should be sorted by its name" {
  109. cached_tarball "Python-3.6.2"
  110. stub brew false
  111. stub_make_install
  112. stub patch ' : for arg; do [[ "$arg" == "-"* ]] || sed -e "s/^/patch: /" "$arg"; done >> build.log'
  113. echo "foo" | install_patch definitions/vanilla-python "Python-3.6.2/foo.patch"
  114. echo "bar" | install_patch definitions/vanilla-python "Python-3.6.2/bar.patch"
  115. echo "baz" | install_patch definitions/vanilla-python "Python-3.6.2/baz.patch"
  116. # yyuu/pyenv#257
  117. stub uname '-s : echo Linux'
  118. stub uname '-s : echo Linux'
  119. TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null
  120. assert_success
  121. assert_build_log <<OUT
  122. patch: bar
  123. patch: baz
  124. patch: foo
  125. Python-3.6.2: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
  126. Python-3.6.2: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
  127. make -j 2
  128. make install
  129. OUT
  130. unstub make
  131. unstub patch
  132. }
  133. @test "allow custom make install target" {
  134. cached_tarball "Python-3.6.2"
  135. stub brew false
  136. stub "$MAKE" \
  137. " : echo \"$MAKE \$@\" >> build.log" \
  138. " : echo \"$MAKE \$@\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'"
  139. # yyuu/pyenv#257
  140. stub uname '-s : echo Linux'
  141. stub uname '-s : echo Linux'
  142. PYTHON_MAKE_INSTALL_TARGET="altinstall" TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null
  143. assert_success
  144. assert_build_log <<OUT
  145. Python-3.6.2: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
  146. Python-3.6.2: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
  147. make -j 2
  148. make altinstall
  149. OUT
  150. unstub make
  151. }
  152. @test "ensurepip without altinstall" {
  153. mkdir -p "${INSTALL_ROOT}/bin"
  154. cat <<OUT > "${INSTALL_ROOT}/bin/python"
  155. #!$BASH
  156. echo "python \$@" >> "${INSTALL_ROOT}/build.log"
  157. OUT
  158. chmod +x "${INSTALL_ROOT}/bin/python"
  159. PYTHON_MAKE_INSTALL_TARGET="" TMPDIR="$TMP" run_inline_definition <<OUT
  160. build_package_ensurepip
  161. OUT
  162. assert_success
  163. assert_build_log <<OUT
  164. python -s -m ensurepip
  165. OUT
  166. }
  167. @test "ensurepip with altinstall" {
  168. mkdir -p "${INSTALL_ROOT}/bin"
  169. cat <<OUT > "${INSTALL_ROOT}/bin/python"
  170. #!$BASH
  171. echo "python \$@" >> "${INSTALL_ROOT}/build.log"
  172. OUT
  173. chmod +x "${INSTALL_ROOT}/bin/python"
  174. PYTHON_MAKE_INSTALL_TARGET="altinstall" TMPDIR="$TMP" run_inline_definition <<OUT
  175. build_package_ensurepip
  176. OUT
  177. assert_success
  178. assert_build_log <<OUT
  179. python -s -m ensurepip --altinstall
  180. OUT
  181. }
  182. @test "python3-config" {
  183. mkdir -p "${INSTALL_ROOT}/bin"
  184. touch "${INSTALL_ROOT}/bin/python3"
  185. chmod +x "${INSTALL_ROOT}/bin/python3"
  186. touch "${INSTALL_ROOT}/bin/python3.4"
  187. chmod +x "${INSTALL_ROOT}/bin/python3.4"
  188. touch "${INSTALL_ROOT}/bin/python3-config"
  189. chmod +x "${INSTALL_ROOT}/bin/python3-config"
  190. touch "${INSTALL_ROOT}/bin/python3.4-config"
  191. chmod +x "${INSTALL_ROOT}/bin/python3.4-config"
  192. TMPDIR="$TMP" run_inline_definition <<OUT
  193. verify_python python3.4
  194. OUT
  195. assert_success
  196. [ -L "${INSTALL_ROOT}/bin/python" ]
  197. [ -L "${INSTALL_ROOT}/bin/python-config" ]
  198. [[ "$(resolve_link "${INSTALL_ROOT}/bin/python")" == "python3.4" ]]
  199. [[ "$(resolve_link "${INSTALL_ROOT}/bin/python-config")" == "python3.4-config" ]]
  200. }
  201. @test "enable framework" {
  202. mkdir -p "${INSTALL_ROOT}/Python.framework/Versions/Current/bin"
  203. touch "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3"
  204. chmod +x "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3"
  205. touch "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3.4"
  206. chmod +x "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3.4"
  207. touch "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3-config"
  208. chmod +x "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3-config"
  209. touch "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3.4-config"
  210. chmod +x "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python3.4-config"
  211. # yyuu/pyenv#257
  212. stub uname '-s : echo Darwin'
  213. stub uname '-s : echo Darwin'
  214. PYTHON_CONFIGURE_OPTS="--enable-framework" TMPDIR="$TMP" run_inline_definition <<OUT
  215. echo "PYTHON_CONFIGURE_OPTS_ARRAY=(\${PYTHON_CONFIGURE_OPTS_ARRAY[@]})"
  216. verify_python python3.4
  217. OUT
  218. assert_success
  219. assert_output <<EOS
  220. PYTHON_CONFIGURE_OPTS_ARRAY=(--libdir=${TMP}/install/lib --enable-framework=${TMP}/install)
  221. EOS
  222. [ -L "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python" ]
  223. [ -L "${INSTALL_ROOT}/Python.framework/Versions/Current/bin/python-config" ]
  224. }
  225. @test "enable universalsdk" {
  226. # yyuu/pyenv#257
  227. stub uname '-s : echo Darwin'
  228. stub uname '-s : echo Darwin'
  229. PYTHON_CONFIGURE_OPTS="--enable-universalsdk" TMPDIR="$TMP" run_inline_definition <<OUT
  230. echo "PYTHON_CONFIGURE_OPTS_ARRAY=(\${PYTHON_CONFIGURE_OPTS_ARRAY[@]})"
  231. OUT
  232. assert_success
  233. assert_output <<EOS
  234. PYTHON_CONFIGURE_OPTS_ARRAY=(--libdir=${TMP}/install/lib --enable-universalsdk=/ --with-universal-archs=intel)
  235. EOS
  236. }
  237. @test "enable custom unicode configuration" {
  238. cached_tarball "Python-3.6.2"
  239. stub brew false
  240. stub "$MAKE" \
  241. " : echo \"$MAKE \$@\" >> build.log" \
  242. " : echo \"$MAKE \$@\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'"
  243. PYTHON_CONFIGURE_OPTS="--enable-unicode=ucs2" TMPDIR="$TMP" install_tmp_fixture definitions/vanilla-python < /dev/null
  244. assert_success
  245. assert_build_log <<OUT
  246. Python-3.6.2: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
  247. Python-3.6.2: --prefix=$INSTALL_ROOT --enable-unicode=ucs2 --libdir=$INSTALL_ROOT/lib
  248. make -j 2
  249. make install
  250. OUT
  251. unstub make
  252. }
  253. @test "default MACOSX_DEPLOYMENT_TARGET" {
  254. # yyuu/pyenv#257
  255. stub uname '-s : echo Darwin'
  256. stub uname '-s : echo Darwin'
  257. stub sw_vers '-productVersion : echo 10.10'
  258. TMPDIR="$TMP" run_inline_definition <<OUT
  259. echo "\${MACOSX_DEPLOYMENT_TARGET}"
  260. OUT
  261. assert_success
  262. assert_output "10.10"
  263. }
  264. @test "use custom MACOSX_DEPLOYMENT_TARGET if defined" {
  265. # yyuu/pyenv#257
  266. stub uname '-s : echo Darwin'
  267. stub uname '-s : echo Darwin'
  268. MACOSX_DEPLOYMENT_TARGET="10.4" TMPDIR="$TMP" run_inline_definition <<OUT
  269. echo "\${MACOSX_DEPLOYMENT_TARGET}"
  270. OUT
  271. assert_success
  272. assert_output "10.4"
  273. }
  274. @test "use the default EZ_SETUP_URL by default" {
  275. run_inline_definition <<OUT
  276. echo "\${EZ_SETUP_URL}"
  277. OUT
  278. assert_output "https://bootstrap.pypa.io/ez_setup.py"
  279. assert_success
  280. }
  281. @test "use the default GET_PIP_URL by default" {
  282. run_inline_definition <<OUT
  283. echo "\${GET_PIP_URL}"
  284. OUT
  285. assert_output "https://bootstrap.pypa.io/get-pip.py"
  286. assert_success
  287. }
  288. @test "use the custom GET_PIP_URL for 2.6 versions" {
  289. run_inline_definition_with_name --name=2.6 <<OUT
  290. echo "\${GET_PIP_URL}"
  291. OUT
  292. assert_output "https://bootstrap.pypa.io/pip/2.6/get-pip.py"
  293. assert_success
  294. }
  295. @test "use the custom GET_PIP_URL for 3.2 versions" {
  296. run_inline_definition_with_name --name=3.2 <<OUT
  297. echo "\${GET_PIP_URL}"
  298. OUT
  299. assert_output "https://bootstrap.pypa.io/pip/3.2/get-pip.py"
  300. assert_success
  301. }
  302. @test "use the custom GET_PIP_URL for 3.3 versions" {
  303. run_inline_definition_with_name --name=3.3 <<OUT
  304. echo "\${GET_PIP_URL}"
  305. OUT
  306. assert_output "https://bootstrap.pypa.io/pip/3.3/get-pip.py"
  307. assert_success
  308. }