Merge pull request #486 from yyuu/ruby-build-20151028

Import changes from ruby-build v20151028
This commit is contained in:
Yamashita, Yuu 2015-11-21 12:12:26 +09:00
commit 94bce8abf8
4 changed files with 185 additions and 132 deletions

View file

@ -0,0 +1,20 @@
Copyright (c) 2013 Yamashita, Yuu
Copyright (c) 2012-2013 Sam Stephenson
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,11 +1,14 @@
# python-build # python-build
python-build is a [pyenv](https://github.com/yyuu/pyenv) plugin python-build is a [pyenv](https://github.com/yyuu/pyenv) plugin that
that provides a `pyenv install` command to compile and install provides a `pyenv install` command to compile and install different versions
different versions of Python on UNIX-like systems. of Python on UNIX-like systems.
You can also use python-build without pyenv in environments where you You can also use python-build without pyenv in environments where you need
need precise control over Python version installation. precise control over Python version installation.
See the [list of releases](https://github.com/yyuu/pyenv/releases)
for changes in each version.
## Installation ## Installation
@ -17,95 +20,134 @@ default.
### Installing as a standalone program (advanced) ### Installing as a standalone program (advanced)
Installing python-build as a standalone program will give you access to Installing python-build as a standalone program will give you access to the
the `python-build` command for precise control over Python version `python-build` command for precise control over Python version installation. If you
installation. If you have pyenv installed, you will also be able to have pyenv installed, you will also be able to use the `pyenv install` command.
use the `pyenv install` command.
git clone git://github.com/yyuu/pyenv.git git clone git://github.com/yyuu/pyenv.git
cd pyenv/plugins/python-build cd pyenv/plugins/python-build
./install.sh ./install.sh
This will install python-build into `/usr/local`. If you do not have This will install python-build into `/usr/local`. If you do not have write
write permission to `/usr/local`, you will need to run `sudo permission to `/usr/local`, you will need to run `sudo ./install.sh` instead.
./install.sh` instead. You can install to a different prefix by You can install to a different prefix by setting the `PREFIX` environment
setting the `PREFIX` environment variable. variable.
To update python-build after it has been installed, run `git pull` in To update python-build after it has been installed, run `git pull` in your cloned
your cloned copy of the repository, then re-run the install script. copy of the repository, then re-run the install script.
### Installing with Homebrew (for OS X users)
Mac OS X users can install python-build with the [Homebrew](http://brew.sh)
package manager. This will give you access to the `python-build` command. If you
have pyenv installed, you will also be able to use the `pyenv install` command.
*This is the recommended method of installation if you installed pyenv with
Homebrew.*
brew install pyenv
Or, if you would like to install the latest development release:
brew install --HEAD pyenv
## Usage ## Usage
Before you begin, you should ensure that your build environment has the proper
system dependencies for compiling the wanted Python Version (see our [recommendations](https://github.com/yyuu/pyenv/wiki#suggested-build-environment)).
### Using `pyenv install` with pyenv ### Using `pyenv install` with pyenv
To install a Python version for use with pyenv, run `pyenv install` with To install a Python version for use with pyenv, run `pyenv install` with
the exact name of the version you want to install. For example, exact name of the version you want to install. For example,
pyenv install 2.7.4 pyenv install 2.7.4
Python versions will be installed into a directory of the same name Python versions will be installed into a directory of the same name under
under `~/.pyenv/versions`. `~/.pyenv/versions`.
To see a list of all available Python versions, run `pyenv install --list`. To see a list of all available Python versions, run `pyenv install --list`. You
You may also tab-complete available Python may also tab-complete available Python versions if your pyenv installation is
versions if your pyenv installation is properly configured. properly configured.
### Using `python-build` standalone ### Using `python-build` standalone
If you have installed python-build as a standalone program, you can use If you have installed python-build as a standalone program, you can use the
the `python-build` command to compile and install Python versions into `python-build` command to compile and install Python versions into specific
specific locations. locations.
Run the `python-build` command with the exact name of the version you Run the `python-build` command with the exact name of the version you want to
want to install and the full path where you want to install it. For install and the full path where you want to install it. For example,
example,
python-build 2.7.4 ~/local/python-2.7.4 python-build 2.7.4 ~/local/python-2.7.4
To see a list of all available Python versions, run `python-build To see a list of all available Python versions, run `python-build --definitions`.
--definitions`.
Pass the `-v` or `--verbose` flag to `python-build` as the first Pass the `-v` or `--verbose` flag to `python-build` as the first argument to see
argument to see what's happening under the hood. what's happening under the hood.
### Custom definitions ### Custom definitions
Both `pyenv install` and `python-build` accept a path to a custom Both `pyenv install` and `python-build` accept a path to a custom definition file
definition file in place of a version name. Custom definitions let you in place of a version name. Custom definitions let you develop and install
develop and install versions of Python that are not yet supported by versions of Python that are not yet supported by python-build.
python-build.
See the [python-build built-in See the [python-build built-in definitions](https://github.com/yyuu/pyenv/tree/master/plugins/python-build/share/python-build) as a starting point for
definitions](https://github.com/yyuu/pyenv/tree/master/plugins/python-build/share/python-build) custom definition files.
as a starting point for custom definition files.
[definitions]: https://github.com/yyuu/pyenv/tree/master/plugins/python-build/share/python-build
### Special environment variables ### Special environment variables
You can set certain environment variables to control the build You can set certain environment variables to control the build process.
process.
* `TMPDIR` sets the location where python-build stores temporary files. * `TMPDIR` sets the location where python-build stores temporary files.
* `PYTHON_BUILD_BUILD_PATH` sets the location in which sources are * `PYTHON_BUILD_BUILD_PATH` sets the location in which sources are downloaded and
downloaded and built. By default, this is a subdirectory of built. By default, this is a subdirectory of `TMPDIR`.
`TMPDIR`. * `PYTHON_BUILD_CACHE_PATH`, if set, specifies a directory to use for caching
* `PYTHON_BUILD_CACHE_PATH`, if set, specifies a directory to use for downloaded package files.
caching downloaded package files. * `PYTHON_BUILD_MIRROR_URL` overrides the default mirror URL root to one of your
* `PYTHON_BUILD_MIRROR_URL` overrides the default mirror URL root to one choosing.
of your choosing. * `PYTHON_BUILD_SKIP_MIRROR`, if set, forces python-build to download packages from
* `PYTHON_BUILD_SKIP_MIRROR`, if set, forces python-build to download their original source URLs instead of using a mirror.
packages from their original source URLs instead of using a mirror. * `PYTHON_BUILD_ROOT` overrides the default location from where build definitions
in `share/python-build/` are looked up.
* `PYTHON_BUILD_DEFINITIONS` can be a list of colon-separated paths that get
additionally searched when looking up build definitions.
* `CC` sets the path to the C compiler. * `CC` sets the path to the C compiler.
* `PYTHON_CFLAGS` lets you pass additional options to the default `CFLAGS`. Use
this to override, for instance, the `-O3` option.
* `CONFIGURE_OPTS` lets you pass additional options to `./configure`. * `CONFIGURE_OPTS` lets you pass additional options to `./configure`.
* `MAKE` lets you override the command to use for `make`. Useful for * `MAKE` lets you override the command to use for `make`. Useful for specifying
specifying GNU make (`gmake`) on some systems. GNU make (`gmake`) on some systems.
* `MAKE_OPTS` (or `MAKEOPTS`) lets you pass additional options to * `MAKE_OPTS` (or `MAKEOPTS`) lets you pass additional options to `make`.
`make`. * `MAKE_INSTALL_OPTS` lets you pass additional options to `make install`.
* `PYTHON_CONFIGURE_OPTS` and `PYTHON_MAKE_OPTS` allow you to specify * `PYTHON_CONFIGURE_OPTS` and `PYTHON_MAKE_OPTS` and `PYTHON_MAKE_INSTALL_OPTS` allow
configure and make options for buildling CPython. These variables will you to specify configure and make options for buildling CPython. These variables
be passed to Python only, not any dependent packages (e.g. libyaml). will be passed to Python only, not any dependent packages (e.g. libyaml).
### Building as `--enable-shared` ### Applying patches to Python before compiling
Both `pyenv install` and `python-build` support the `--patch` (`-p`) flag that
signals that a patch from stdin should be applied to Python, Jython or PyPy
source code before the `./configure` and compilation steps.
Example usage:
```sh
# applying a single patch
$ pyenv install --patch 2.7.10 < /path/to/python.patch
# applying a patch from HTTP
$ pyenv install --patch 2.7.10 < <(curl -sSL http://git.io/python.patch)
# applying multiple patches
$ cat fix1.patch fix2.patch | pyenv install --patch 2.7.10
```
### Building with `--enable-shared`
You can build CPython with `--enable-shared` to install a version with You can build CPython with `--enable-shared` to install a version with
shared object. shared object.
@ -121,93 +163,60 @@ $ env PYTHON_CONFIGURE_OPTS="--enable-shared` pyenv install 2.7.9
### Checksum verification ### Checksum verification
If you have the `shasum`, `openssl`, or `sha256sum` tool installed, If you have the `shasum`, `openssl`, or `sha256sum` tool installed, python-build will
python-build will automatically verify the SHA2 checksum of each automatically verify the SHA2 checksum of each downloaded package before
downloaded package before installing it. installing it.
Checksums are optional and specified as anchors on the package URL in Checksums are optional and specified as anchors on the package URL in each
each definition. (All bundled definitions include checksums.) definition. (All bundled definitions include checksums.)
### Package download mirrors ### Package download mirrors
python-build will first attempt to download package files from a mirror python-build will first attempt to download package files from a mirror hosted on
hosted on Amazon CloudFront. If a package is not available on the GitHub Pages. If a package is not available on the mirror, if the mirror
mirror, if the mirror is down, or if the download is corrupt, is down, or if the download is corrupt, python-build will fall back to the
python-build will fall back to the official URL specified in the official URL specified in the defintion file.
defintion file.
You can point python-build to another mirror by specifying the You can point python-build to another mirror by specifying the
`PYTHON_BUILD_MIRROR_URL` environment variable--useful if you'd like to `PYTHON_BUILD_MIRROR_URL` environment variable--useful if you'd like to run your
run your own local mirror, for example. Package mirror URLs are own local mirror, for example. Package mirror URLs are constructed by joining
constructed by joining this variable with the SHA2 checksum of the this variable with the SHA2 checksum of the package file.
package file.
If you don't have an SHA2 program installed, python-build will skip the If you don't have an SHA2 program installed, python-build will skip the download
download mirror and use official URLs instead. You can force mirror and use official URLs instead. You can force python-build to bypass the
python-build to bypass the mirror by setting the mirror by setting the `PYTHON_BUILD_SKIP_MIRROR` environment variable.
`PYTHON_BUILD_SKIP_MIRROR` environment variable.
The official python-build download mirror is provided by [Git Hub Pages](http://yyuu.github.io/pythons/). The official python-build download mirror is provided by
[GitHub Pages](http://yyuu.github.io/pythons/).
### Package download caching ### Package download caching
You can instruct python-build to keep a local cache of downloaded You can instruct python-build to keep a local cache of downloaded package files
package files by setting the `PYTHON_BUILD_CACHE_PATH` environment by setting the `PYTHON_BUILD_CACHE_PATH` environment variable. When set, package
variable. When set, package files will be kept in this directory after files will be kept in this directory after the first successful download and
the first successful download and reused by subsequent invocations of reused by subsequent invocations of `python-build` and `pyenv install`.
`python-build` and `pyenv install`.
The `pyenv install` command defaults this path to `~/.pyenv/cache`, so The `pyenv install` command defaults this path to `~/.pyenv/cache`, so in most
in most cases you can enable download caching simply by creating that cases you can enable download caching simply by creating that directory.
directory.
### Keeping the build directory after installation ### Keeping the build directory after installation
Both `python-build` and `pyenv install` accept the `-k` or `--keep` Both `python-build` and `pyenv install` accept the `-k` or `--keep` flag, which
flag, which tells python-build to keep the downloaded source after tells python-build to keep the downloaded source after installation. This can be
installation. This can be useful if you need to use `gdb` and useful if you need to use `gdb` and `memprof` with Python.
`memprof` with Python.
Source code will be kept in a parallel directory tree Source code will be kept in a parallel directory tree `~/.pyenv/sources` when
`~/.pyenv/sources` when using `--keep` with the `pyenv install` using `--keep` with the `pyenv install` command. You should specify the
command. You should specify the location of the source code with the location of the source code with the `PYTHON_BUILD_BUILD_PATH` environment
`PYTHON_BUILD_BUILD_PATH` environment variable when using `--keep` with variable when using `--keep` with `python-build`.
`python-build`.
## Getting Help ## Getting Help
Please see the [python-build Please see the [pyenv wiki](https://github.com/yyuu/pyenv/wiki) for solutions to common problems.
wiki](https://github.com/yyuu/pyenv/wiki) for solutions to
common problems. [wiki]: https://github.com/yyuu/pyenv/wiki
If you can't find an answer on the wiki, open an issue on the [issue If you can't find an answer on the wiki, open an issue on the [issue
tracker](https://github.com/yyuu/pyenv/issues). Be sure to tracker](https://github.com/yyuu/pyenv/issues). Be sure to include
include the full build log for build failures. the full build log for build failures.
### License
(The MIT License)
* Copyright (c) 2013 Yamashita, Yuu
* Copyright (c) 2012 Sam Stephenson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -12,7 +12,9 @@
# -g/--debug Build a debug version # -g/--debug Build a debug version
# #
PYTHON_BUILD_VERSION="20150818" PYTHON_BUILD_VERSION="20151028"
OLDIFS="$IFS"
set -E set -E
exec 3<&2 # preserve original stderr at fd 3 exec 3<&2 # preserve original stderr at fd 3
@ -103,6 +105,7 @@ os_information() {
osx_version() { osx_version() {
local -a ver local -a ver
IFS=. ver=( `sw_vers -productVersion` ) IFS=. ver=( `sw_vers -productVersion` )
IFS="$OLDIFS"
echo $(( ${ver[0]}*100 + ${ver[1]} )) echo $(( ${ver[0]}*100 + ${ver[1]} ))
} }
@ -518,6 +521,8 @@ fetch_svn() {
if type svn &>/dev/null; then if type svn &>/dev/null; then
svn co -r "$svn_rev" "$svn_url" "${package_name}" >&4 2>&1 svn co -r "$svn_rev" "$svn_url" "${package_name}" >&4 2>&1
elif type svnlite &>/dev/null; then
svnlite co -r "$svn_rev" "$svn_url" "${package_name}" >&4 2>&1
else else
echo "error: please install Subversion and try again" >&2 echo "error: please install Subversion and try again" >&2
exit 1 exit 1
@ -682,7 +687,7 @@ build_package_standard() {
export CC=clang export CC=clang
fi fi
${!PACKAGE_CONFIGURE:-./configure} --prefix="${!PACKAGE_PREFIX_PATH:-$PREFIX_PATH}" \ ${!PACKAGE_CONFIGURE:-./configure} --prefix="${!PACKAGE_PREFIX_PATH:-$PREFIX_PATH}" \
$CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" $CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
) >&4 2>&1 ) >&4 2>&1
{ "$MAKE" $MAKE_OPTS ${!PACKAGE_MAKE_OPTS} "${!PACKAGE_MAKE_OPTS_ARRAY}" { "$MAKE" $MAKE_OPTS ${!PACKAGE_MAKE_OPTS} "${!PACKAGE_MAKE_OPTS_ARRAY}"
@ -1101,6 +1106,7 @@ require_gcc() {
locate_gcc() { locate_gcc() {
local gcc gccs local gcc gccs
IFS=: gccs=($(gccs_in_path)) IFS=: gccs=($(gccs_in_path))
IFS="$OLDIFS"
verify_gcc "$CC" || verify_gcc "$CC" ||
verify_gcc "$(command -v gcc || true)" || { verify_gcc "$(command -v gcc || true)" || {
@ -1116,6 +1122,7 @@ gccs_in_path() {
local gcc path paths local gcc path paths
local gccs=() local gccs=()
IFS=: paths=($PATH) IFS=: paths=($PATH)
IFS="$OLDIFS"
shopt -s nullglob shopt -s nullglob
for path in "${paths[@]}"; do for path in "${paths[@]}"; do
@ -1334,11 +1341,16 @@ build_package_verify_openssl() {
# Ensure that directories listed in LDFLAGS exist # Ensure that directories listed in LDFLAGS exist
build_package_ldflags_dirs() { build_package_ldflags_dirs() {
local arg local arg dir
for arg in $LDFLAGS; do set - $LDFLAGS
case "$arg" in while [ $# -gt 0 ]; do
-L* ) mkdir -p "${arg#-L}" ;; dir=""
case "$1" in
-L ) dir="$2" ;;
-L* ) dir="${1#-L}" ;;
esac esac
[ -z "$dir" ] || mkdir -p "$dir"
shift 1
done done
} }
@ -1646,7 +1658,6 @@ unset IPV6
PYTHON_BUILD_INSTALL_PREFIX="$(abs_dirname "$0")/.." PYTHON_BUILD_INSTALL_PREFIX="$(abs_dirname "$0")/.."
OLDIFS="$IFS"
IFS=: PYTHON_BUILD_DEFINITIONS=($PYTHON_BUILD_DEFINITIONS ${PYTHON_BUILD_ROOT:-$PYTHON_BUILD_INSTALL_PREFIX}/share/python-build) IFS=: PYTHON_BUILD_DEFINITIONS=($PYTHON_BUILD_DEFINITIONS ${PYTHON_BUILD_ROOT:-$PYTHON_BUILD_INSTALL_PREFIX}/share/python-build)
IFS="$OLDIFS" IFS="$OLDIFS"

View file

@ -489,3 +489,16 @@ OUT
run python-build "${TMP}/build-definition" "$INSTALL_ROOT" run python-build "${TMP}/build-definition" "$INSTALL_ROOT"
assert_failure "python-build: TMPDIR=$TMPDIR is set to a non-accessible location" assert_failure "python-build: TMPDIR=$TMPDIR is set to a non-accessible location"
} }
@test "initializes LDFLAGS directories" {
cached_tarball "Python-3.2.1"
export LDFLAGS="-L ${BATS_TEST_DIRNAME}/what/evs"
run_inline_definition <<DEF
install_package "Python-3.2.1" "http://python.org/ftp/python/3.2.1/Python-3.2.1.tar.gz" ldflags_dirs
DEF
assert_success
assert [ -d "${INSTALL_ROOT}/lib" ]
assert [ -d "${BATS_TEST_DIRNAME}/what/evs" ]
}