├── CHANGELOG.md ├── LICENSE ├── README.md ├── bin ├── lua-build ├── luaenv-install └── luaenv-uninstall ├── install.sh ├── share └── lua-build │ ├── 5.1.5 │ ├── 5.2.1 │ ├── 5.2.2 │ ├── 5.2.3 │ ├── 5.2.4 │ ├── 5.3.0 │ ├── 5.3.1 │ ├── 5.3.2 │ ├── 5.3.3 │ ├── 5.3.4 │ ├── 5.3.5 │ ├── 5.3.6 │ ├── 5.4.0 │ ├── 5.4.1 │ ├── 5.4.2 │ ├── 5.4.3 │ ├── 5.4.4 │ ├── 5.4.5 │ ├── 5.4.6 │ ├── 5.4.7 │ ├── luajit-2.0.1 │ ├── luajit-2.0.1-p1 │ ├── luajit-2.0.2 │ ├── luajit-2.0.3 │ ├── luajit-2.0.4 │ ├── luajit-2.0.5 │ ├── luajit-2.1-dev │ ├── luajit-2.1.0-beta2 │ ├── luajit-2.1.0-beta3 │ ├── luvit-0.6.0 │ ├── luvit-0.6.1 │ └── luvit-dev └── test ├── cache.bats ├── checksum.bats ├── fixtures ├── definitions │ ├── with-checksum │ ├── with-invalid-checksum │ └── without-checksum └── package-1.0.0.tar.gz ├── mirror.bats ├── stubs ├── curl │ └── curl ├── md5 │ └── md5 └── stub ├── test_helper.bash └── tmp └── .gitignore /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Version History 2 | 3 | #### 20130302 4 | * Converted from ruby-build to lua-build 5 | * Initial public release. 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Sam Stephenson, Chris Hoffman 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lua-build 2 | 3 | lua-build is an [luaenv](https://github.com/cehoffman/luaenv) plugin 4 | that provides a `luaenv install` command to compile and install 5 | different versions of Lua on UNIX-like systems. It works just like 6 | [ruby-build](https://github.com/sstephenson/ruby-build) since it is ruby-build 7 | but for lua. 8 | 9 | You can also use lua-build without luaenv in environments where you 10 | need precise control over Lua version installation. 11 | 12 | 13 | ## Installation 14 | 15 | ### Installing as an luaenv plugin (recommended) 16 | 17 | Installing lua-build as an luaenv plugin will give you access to the 18 | `luaenv install` command. 19 | 20 | git clone git://github.com/cehoffman/lua-build.git ~/.luaenv/plugins/lua-build 21 | 22 | This will install the latest development version of lua-build into 23 | the `~/.luaenv/plugins/lua-build` directory. From that directory, you 24 | can check out a specific release tag. To update lua-build, run `git 25 | pull` to download the latest changes. 26 | 27 | ### Installing as a standalone program (advanced) 28 | 29 | Installing lua-build as a standalone program will give you access to 30 | the `lua-build` command for precise control over Lua version 31 | installation. If you have luaenv installed, you will also be able to 32 | use the `luaenv install` command. 33 | 34 | git clone git://github.com/cehoffman/lua-build.git 35 | cd lua-build 36 | ./install.sh 37 | 38 | This will install lua-build into `/usr/local`. If you do not have 39 | write permission to `/usr/local`, you will need to run `sudo 40 | ./install.sh` instead. You can install to a different prefix by 41 | setting the `PREFIX` environment variable. 42 | 43 | To update lua-build after it has been installed, run `git pull` in 44 | your cloned copy of the repository, then re-run the install script. 45 | 46 | ### Installing with Homebrew (for macOS users) 47 | 48 | macOS users can install lua-build with the 49 | [Homebrew](https://brew.sh) package manager. This 50 | will give you access to the `lua-build` command. If you have luaenv 51 | installed, you will also be able to use the `luaenv install` command. 52 | 53 | *This is the recommended method of installation if you installed luaenv 54 | with Homebrew.* 55 | 56 | brew install lua-build 57 | 58 | Or, if you would like to install the latest development release: 59 | 60 | brew install --HEAD lua-build 61 | 62 | 63 | ## Usage 64 | 65 | ### Using `luaenv install` with luaenv 66 | 67 | To install a Lua version for use with luaenv, run `luaenv install` with 68 | the exact name of the version you want to install. For example, 69 | 70 | luaenv install 5.2.1 71 | 72 | Lua versions will be installed into a directory of the same name 73 | under `~/.luaenv/versions`. 74 | 75 | To see a list of all available Lua versions, run `luaenv install --list`. 76 | You may also tab-complete available Lua 77 | versions if your luaenv installation is properly configured. 78 | 79 | ### Using `lua-build` standalone 80 | 81 | If you have installed lua-build as a standalone program, you can use 82 | the `lua-build` command to compile and install Lua versions into 83 | specific locations. 84 | 85 | Run the `lua-build` command with the exact name of the version you 86 | want to install and the full path where you want to install it. For 87 | example, 88 | 89 | lua-build 5.1.5 ~/local/lua-5.1.5 90 | 91 | To see a list of all available Lua versions, run `lua-build 92 | --definitions`. 93 | 94 | Pass the `-v` or `--verbose` flag to `lua-build` as the first 95 | argument to see what's happening under the hood. 96 | 97 | ### Custom definitions 98 | 99 | Both `luaenv install` and `lua-build` accept a path to a custom 100 | definition file in place of a version name. Custom definitions let you 101 | develop and install versions of Lua that are not yet supported by 102 | lua-build. 103 | 104 | See the [lua-build built-in 105 | definitions](https://github.com/cehoffman/lua-build/tree/master/share/lua-build) 106 | as a starting point for custom definition files. 107 | 108 | ### Special environment variables 109 | 110 | You can set certain environment variables to control the build 111 | process. 112 | 113 | * `TMPDIR` sets the location where lua-build stores temporary files. 114 | * `LUA_BUILD_BUILD_PATH` sets the location in which sources are 115 | downloaded and built. By default, this is a subdirectory of 116 | `TMPDIR`. 117 | * `LUA_BUILD_CACHE_PATH`, if set, specifies a directory to use for 118 | caching downloaded package files. 119 | * `LUA_BUILD_MIRROR_URL` overrides the default mirror URL root to one 120 | of your choosing. 121 | * `LUA_BUILD_SKIP_MIRROR`, if set, forces lua-build to download 122 | packages from their original source URLs instead of using a mirror. 123 | * `CC` sets the path to the C compiler. 124 | * `CONFIGURE_OPTS` lets you pass additional options to `./configure`. 125 | * `MAKE` lets you override the command to use for `make`. Useful for 126 | specifying GNU make (`gmake`) on some systems. 127 | * `MAKE_OPTS` (or `MAKEOPTS`) lets you pass additional options to 128 | `make`. 129 | * `LUA_CONFIGURE_OPTS` and `LUA_MAKE_OPTS` allow you to specify 130 | configure and make options for buildling MRI. These variables will 131 | be passed to Lua only, not any dependent packages (e.g. libyaml). 132 | 133 | ### Checksum verification 134 | 135 | If you have the `md5`, `openssl`, or `md5sum` tool installed, 136 | lua-build will automatically verify the MD5 checksum of each 137 | downloaded package before installing it. 138 | 139 | Checksums are optional and specified as anchors on the package URL in 140 | each definition. (All bundled definitions include checksums.) 141 | 142 | ### Package download mirrors 143 | 144 | lua-build will first attempt to download package files from a mirror 145 | hosted on Amazon CloudFront. If a package is not available on the 146 | mirror, if the mirror is down, or if the download is corrupt, 147 | lua-build will fall back to the official URL specified in the 148 | defintion file. 149 | 150 | You can point lua-build to another mirror by specifying the 151 | `LUA_BUILD_MIRROR_URL` environment variable--useful if you'd like to 152 | run your own local mirror, for example. Package mirror URLs are 153 | constructed by joining this variable with the MD5 checksum of the 154 | package file. 155 | 156 | If you don't have an MD5 program installed, lua-build will skip the 157 | download mirror and use official URLs instead. You can force 158 | lua-build to bypass the mirror by setting the 159 | `LUA_BUILD_SKIP_MIRROR` environment variable. 160 | 161 | ### Package download caching 162 | 163 | You can instruct lua-build to keep a local cache of downloaded 164 | package files by setting the `LUA_BUILD_CACHE_PATH` environment 165 | variable. When set, package files will be kept in this directory after 166 | the first successful download and reused by subsequent invocations of 167 | `lua-build` and `luaenv install`. 168 | 169 | The `luaenv install` command defaults this path to `~/.luaenv/cache`, so 170 | in most cases you can enable download caching simply by creating that 171 | directory. 172 | 173 | ### Keeping the build directory after installation 174 | 175 | Both `lua-build` and `luaenv install` accept the `-k` or `--keep` 176 | flag, which tells lua-build to keep the downloaded source after 177 | installation. This can be useful if you need to use `gdb` and 178 | `memprof` with Lua. 179 | 180 | Source code will be kept in a parallel directory tree 181 | `~/.luaenv/sources` when using `--keep` with the `luaenv install` 182 | command. You should specify the location of the source code with the 183 | `LUA_BUILD_BUILD_PATH` environment variable when using `--keep` with 184 | `lua-build`. 185 | 186 | 187 | ## Getting Help 188 | 189 | Please see the [lua-build 190 | wiki](https://github.com/cehoffman/lua-build/wiki) for solutions to 191 | common problems. 192 | 193 | If you can't find an answer on the wiki, open an issue on the [issue 194 | tracker](https://github.com/cehoffman/lua-build/issues). Be sure to 195 | include the full build log for build failures. 196 | 197 | 198 | ### License 199 | 200 | (The MIT License) 201 | 202 | Copyright (c) 2013 Sam Stephenson, Chris Hoffman 203 | 204 | Permission is hereby granted, free of charge, to any person obtaining 205 | a copy of this software and associated documentation files (the 206 | "Software"), to deal in the Software without restriction, including 207 | without limitation the rights to use, copy, modify, merge, publish, 208 | distribute, sublicense, and/or sell copies of the Software, and to 209 | permit persons to whom the Software is furnished to do so, subject to 210 | the following conditions: 211 | 212 | The above copyright notice and this permission notice shall be 213 | included in all copies or substantial portions of the Software. 214 | 215 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 216 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 217 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 218 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 219 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 220 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 221 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 222 | -------------------------------------------------------------------------------- /bin/lua-build: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | LUA_BUILD_VERSION="20130302" 4 | 5 | set -E 6 | exec 3<&2 # preserve original stderr at fd 3 7 | 8 | 9 | lib() { 10 | parse_options() { 11 | OPTIONS=() 12 | ARGUMENTS=() 13 | local arg option index 14 | 15 | for arg in "$@"; do 16 | if [ "${arg:0:1}" = "-" ]; then 17 | if [ "${arg:1:1}" = "-" ]; then 18 | OPTIONS[${#OPTIONS[*]}]="${arg:2}" 19 | else 20 | index=1 21 | while option="${arg:$index:1}"; do 22 | [ -n "$option" ] || break 23 | OPTIONS[${#OPTIONS[*]}]="$option" 24 | index=$(($index+1)) 25 | done 26 | fi 27 | else 28 | ARGUMENTS[${#ARGUMENTS[*]}]="$arg" 29 | fi 30 | done 31 | } 32 | 33 | if [ "$1" == "--$FUNCNAME" ]; then 34 | declare -f "$FUNCNAME" 35 | echo "$FUNCNAME \"\$1\";" 36 | exit 37 | fi 38 | } 39 | lib "$1" 40 | 41 | 42 | resolve_link() { 43 | $(type -p greadlink readlink | head -1) "$1" 44 | } 45 | 46 | abs_dirname() { 47 | local cwd="$(pwd)" 48 | local path="$1" 49 | 50 | while [ -n "$path" ]; do 51 | cd "${path%/*}" 52 | local name="${path##*/}" 53 | path="$(resolve_link "$name" || true)" 54 | done 55 | 56 | pwd 57 | cd "$cwd" 58 | } 59 | 60 | capitalize() { 61 | printf "%s" "$1" | tr a-z A-Z 62 | } 63 | 64 | lowercase() { 65 | printf "%s" "$1" | tr A-Z a-z 66 | } 67 | 68 | build_failed() { 69 | { echo 70 | echo "BUILD FAILED" 71 | echo 72 | 73 | if ! rmdir "${BUILD_PATH}" 2>/dev/null; then 74 | echo "Inspect or clean up the working tree at ${BUILD_PATH}" 75 | 76 | if file_is_not_empty "$LOG_PATH"; then 77 | echo "Results logged to ${LOG_PATH}" 78 | echo 79 | echo "Last 10 log lines:" 80 | tail -n 10 "$LOG_PATH" 81 | fi 82 | fi 83 | } >&3 84 | exit 1 85 | } 86 | 87 | file_is_not_empty() { 88 | local filename="$1" 89 | local line_count="$(wc -l "$filename" 2>/dev/null || true)" 90 | 91 | if [ -n "$line_count" ]; then 92 | words=( $line_count ) 93 | [ "${words[0]}" -gt 0 ] 94 | else 95 | return 1 96 | fi 97 | } 98 | 99 | install_package() { 100 | install_package_using "tarball" 1 "$@" 101 | } 102 | 103 | install_git() { 104 | install_package_using "git" 2 "$@" 105 | } 106 | 107 | install_svn() { 108 | install_package_using "svn" 2 "$@" 109 | } 110 | 111 | install_package_using() { 112 | local package_type="$1" 113 | local package_type_nargs="$2" 114 | local package_name="$3" 115 | shift 3 116 | 117 | local fetch_args=( "$package_name" "${@:1:$package_type_nargs}" ) 118 | local make_args=( "$package_name" ) 119 | local arg last_arg 120 | 121 | for arg in "${@:$(( $package_type_nargs + 1 ))}"; do 122 | if [ "$last_arg" = "--if" ]; then 123 | "$arg" || return 0 124 | elif [ "$arg" != "--if" ]; then 125 | make_args["${#make_args[@]}"]="$arg" 126 | fi 127 | last_arg="$arg" 128 | done 129 | 130 | pushd "$BUILD_PATH" >&4 131 | "fetch_${package_type}" "${fetch_args[@]}" 132 | make_package "${make_args[@]}" 133 | popd >&4 134 | 135 | { echo "Installed ${package_name} to ${PREFIX_PATH}" 136 | echo 137 | } >&2 138 | } 139 | 140 | make_package() { 141 | local package_name="$1" 142 | shift 143 | 144 | pushd "$package_name" >&4 145 | before_install_package "$package_name" 146 | build_package "$package_name" $* 147 | after_install_package "$package_name" 148 | fix_directory_permissions 149 | popd >&4 150 | } 151 | 152 | compute_md5() { 153 | if type md5 &>/dev/null; then 154 | md5 -q 155 | elif type openssl &>/dev/null; then 156 | local output="$(openssl md5)" 157 | echo "${output##* }" 158 | elif type md5sum &>/dev/null; then 159 | local output="$(md5sum -b)" 160 | echo "${output% *}" 161 | else 162 | return 1 163 | fi 164 | } 165 | 166 | verify_checksum() { 167 | # If there's no MD5 support, return success 168 | [ -n "$HAS_MD5_SUPPORT" ] || return 0 169 | 170 | # If the specified filename doesn't exist, return success 171 | local filename="$1" 172 | [ -e "$filename" ] || return 0 173 | 174 | # If there's no expected checksum, return success 175 | local expected_checksum="$2" 176 | [ -n "$expected_checksum" ] || return 0 177 | 178 | # If the computed checksum is empty, return failure 179 | local computed_checksum="$(compute_md5 < "$filename")" 180 | [ -n "$computed_checksum" ] || return 1 181 | 182 | if [ "$expected_checksum" != "$computed_checksum" ]; then 183 | { echo 184 | echo "checksum mismatch: ${filename} (file is corrupt)" 185 | echo "expected $expected_checksum, got $computed_checksum" 186 | echo 187 | } >&4 188 | return 1 189 | fi 190 | } 191 | 192 | http() { 193 | local method="$1" 194 | local url="$2" 195 | [ -n "$url" ] || return 1 196 | 197 | if type curl &>/dev/null; then 198 | "http_${method}_curl" "$url" 199 | elif type wget &>/dev/null; then 200 | "http_${method}_wget" "$url" 201 | else 202 | echo "error: please install \`curl\` or \`wget\` and try again" >&2 203 | exit 1 204 | fi 205 | } 206 | 207 | http_head_curl() { 208 | curl -qsILf "$1" >&4 2>&1 209 | } 210 | 211 | http_get_curl() { 212 | curl -qsSLf "$1" 213 | } 214 | 215 | http_head_wget() { 216 | wget -q --spider "$1" >&4 2>&1 217 | } 218 | 219 | http_get_wget() { 220 | wget -nv -O- "$1" 221 | } 222 | 223 | fetch_tarball() { 224 | local package_name="$1" 225 | local package_url="$2" 226 | local mirror_url 227 | local checksum 228 | 229 | if [ "$package_url" != "${package_url/\#}" ]; then 230 | checksum="${package_url#*#}" 231 | package_url="${package_url%%#*}" 232 | 233 | if [ -n "$LUA_BUILD_MIRROR_URL" ]; then 234 | mirror_url="${LUA_BUILD_MIRROR_URL}/$checksum" 235 | fi 236 | fi 237 | 238 | local package_filename="${package_name}.tar.gz" 239 | symlink_tarball_from_cache "$package_filename" "$checksum" || { 240 | echo "Downloading ${package_filename}..." >&2 241 | { http head "$mirror_url" && 242 | download_tarball "$mirror_url" "$package_filename" "$checksum" 243 | } || 244 | download_tarball "$package_url" "$package_filename" "$checksum" 245 | } 246 | 247 | { tar xzvf "$package_filename" 248 | rm -f "$package_filename" 249 | } >&4 2>&1 250 | } 251 | 252 | symlink_tarball_from_cache() { 253 | [ -n "$LUA_BUILD_CACHE_PATH" ] || return 1 254 | 255 | local package_filename="$1" 256 | local cached_package_filename="${LUA_BUILD_CACHE_PATH}/$package_filename" 257 | local checksum="$2" 258 | 259 | [ -e "$cached_package_filename" ] || return 1 260 | verify_checksum "$cached_package_filename" "$checksum" >&4 2>&1 || return 1 261 | ln -s "$cached_package_filename" "$package_filename" >&4 2>&1 || return 1 262 | } 263 | 264 | download_tarball() { 265 | local package_url="$1" 266 | [ -n "$package_url" ] || return 1 267 | 268 | local package_filename="$2" 269 | local checksum="$3" 270 | 271 | echo "-> $package_url" >&2 272 | 273 | { http get "$package_url" > "$package_filename" 274 | verify_checksum "$package_filename" "$checksum" 275 | } >&4 2>&1 || return 1 276 | 277 | if [ -n "$LUA_BUILD_CACHE_PATH" ]; then 278 | local cached_package_filename="${LUA_BUILD_CACHE_PATH}/$package_filename" 279 | { mv "$package_filename" "$cached_package_filename" 280 | ln -s "$cached_package_filename" "$package_filename" 281 | } >&4 2>&1 || return 1 282 | fi 283 | } 284 | 285 | fetch_git() { 286 | local package_name="$1" 287 | local git_url="$2" 288 | local git_ref="$3" 289 | 290 | echo "Cloning ${git_url}..." >&2 291 | 292 | if type git &>/dev/null; then 293 | git clone --recursive --depth 1 --branch "$git_ref" "$git_url" "${package_name}" >&4 2>&1 294 | else 295 | echo "error: please install \`git\` and try again" >&2 296 | exit 1 297 | fi 298 | } 299 | 300 | fetch_svn() { 301 | local package_name="$1" 302 | local svn_url="$2" 303 | local svn_rev="$3" 304 | 305 | echo "Checking out ${svn_url}..." >&2 306 | 307 | if type svn &>/dev/null; then 308 | svn co -r "$svn_rev" "$svn_url" "${package_name}" >&4 2>&1 309 | else 310 | echo "error: please install \`svn\` and try again" >&2 311 | exit 1 312 | fi 313 | } 314 | 315 | build_package() { 316 | local package_name="$1" 317 | shift 318 | 319 | if [ "$#" -eq 0 ]; then 320 | local commands="lua" 321 | else 322 | local commands="$*" 323 | fi 324 | 325 | echo "Installing ${package_name}..." >&2 326 | 327 | for command in $commands; do 328 | "build_package_${command}" "$package_name" 329 | done 330 | } 331 | 332 | package_option() { 333 | local package_name="$1" 334 | local command_name="$2" 335 | local variable="$(capitalize "${package_name}_${command_name}")_OPTS_ARRAY" 336 | local array="$variable[@]" 337 | shift 2 338 | local value=( "${!array}" "$@" ) 339 | eval "$variable=( \"\${value[@]}\" )" 340 | } 341 | 342 | build_package_configure() { 343 | local package_name="$1" 344 | 345 | if [ "${MAKEOPTS+defined}" ]; then 346 | MAKE_OPTS="$MAKEOPTS" 347 | elif [ -z "${MAKE_OPTS+defined}" ]; then 348 | MAKE_OPTS="-j 2" 349 | fi 350 | 351 | # Support YAML_CONFIGURE_OPTS, LUA_CONFIGURE_OPTS, etc. 352 | local package_var_name="$(capitalize "${package_name%%-*}")" 353 | local PACKAGE_CONFIGURE="${package_var_name}_CONFIGURE" 354 | local PACKAGE_PREFIX_PATH="${package_var_name}_PREFIX_PATH" 355 | local PACKAGE_CONFIGURE_OPTS="${package_var_name}_CONFIGURE_OPTS" 356 | local PACKAGE_CONFIGURE_OPTS_ARRAY="${package_var_name}_CONFIGURE_OPTS_ARRAY[@]" 357 | local PACKAGE_MAKE_OPTS="${package_var_name}_MAKE_OPTS" 358 | local PACKAGE_MAKE_OPTS_ARRAY="${package_var_name}_MAKE_OPTS_ARRAY[@]" 359 | local PACKAGE_CFLAGS="${package_var_name}_CFLAGS" 360 | 361 | { CFLAGS="$CFLAGS ${!PACKAGE_CFLAGS}" ${!PACKAGE_CONFIGURE:-./configure} --prefix="${!PACKAGE_PREFIX_PATH:-$PREFIX_PATH}" $CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" 362 | "$MAKE" $MAKE_OPTS ${!PACKAGE_MAKE_OPTS} "${!PACKAGE_MAKE_OPTS_ARRAY}" 363 | "$MAKE" install 364 | } >&4 2>&1 365 | } 366 | 367 | build_package_lua() { 368 | local package_name="$1" 369 | 370 | if [ "${MAKEOPTS+defined}" ]; then 371 | MAKE_OPTS="$MAKEOPTS" 372 | elif [ -z "${MAKE_OPTS+defined}" ]; then 373 | MAKE_OPTS="-j 2" 374 | fi 375 | 376 | local os_name=$(uname -s | tr '[A-Z]' '[a-z]') 377 | local platform 378 | [ "$os_name" == darwin ] && platform=macosx 379 | [ "$os_name" == *cygwin* ] && platform=posix 380 | [ "$os_name" == *mingw* ] && platform=mingw 381 | [ "$os_name" == *bsd* ] && platform=bsd 382 | [ "$os_name" == *freebsd* ] && platform=freebsd 383 | [ "$os_name" == linux ] && platform=linux 384 | [ "$os_name" == *sunos* ] && platform=solaris 385 | [ "$os_name" == *aix* ] && platform=aix 386 | 387 | { mv src/luaconf.h src/luaconf.h.orig 388 | sed -e "s:LUA_ROOT[ ]*\"/usr/local/\":LUA_ROOT \"${PREFIX_PATH}/\":g" src/luaconf.h.orig > src/luaconf.h 389 | "$MAKE" $MAKE_OPTS "${platform:-posix}" INSTALL_TOP="$PREFIX_PATH" INSTALL_MAN="$PREFIX_PATH/share/man/man1" 390 | "$MAKE" $MAKE_OPTS install INSTALL_TOP="$PREFIX_PATH" INSTALL_MAN="$PREFIX_PATH/share/man/man1" 391 | } >&4 2>&1 392 | } 393 | 394 | build_package_autoconf() { 395 | { autoconf 396 | } >&4 2>&1 397 | } 398 | 399 | build_package_luajit() { 400 | local PACKAGE_CFLAGS="${package_var_name}_CFLAGS" 401 | { "$MAKE" $MAKE_OPTS amalg PREFIX="$PREFIX_PATH" XCFLAGS="${!PACKAGE_CFLAGS:--DLUAJIT_ENABLE_LUA52COMPAT}" 402 | "$MAKE" $MAKE_OPTS install PREFIX="$PREFIX_PATH" 403 | cd "${PREFIX_PATH}/bin" 404 | ln -sf "$(lowercase "$package_name")" lua 405 | ln -sf "$(lowercase "$package_name")" luajit 406 | } >&4 2>&1 407 | } 408 | 409 | build_package_luvit() { 410 | { env -u CPPFLAGS -u LDFLAGS "$MAKE" $MAKE_OPTS PREFIX="$PREFIX_PATH" 411 | "$MAKE" $MAKE_OPTS install PREFIX="$PREFIX_PATH" 412 | cd "${PREFIX_PATH}/bin" 413 | ln -sf luvit lua 414 | } >&4 2>&1 415 | } 416 | 417 | # build_package_luasrc() { 418 | # local package_name="$1" 419 | 420 | # { "$LUA_BIN" setup.rb 421 | # } >&4 2>&1 422 | # } 423 | 424 | remove_windows_files() { 425 | cd "$PREFIX_PATH" 426 | rm -f bin/*.exe bin/*.dll bin/*.bat bin/jlua.sh 427 | } 428 | 429 | build_package_copy() { 430 | mkdir -p "$PREFIX_PATH" 431 | cp -R . "$PREFIX_PATH" 432 | } 433 | 434 | before_install_package() { 435 | local stub=1 436 | } 437 | 438 | after_install_package() { 439 | local stub=1 440 | } 441 | 442 | fix_directory_permissions() { 443 | # Ensure installed directories are not world-writable, just good practice 444 | find "$PREFIX_PATH" -type d \( -perm -020 -o -perm -002 \) -exec chmod go-w {} \; 445 | } 446 | 447 | version() { 448 | echo "lua-build ${LUA_BUILD_VERSION}" 449 | } 450 | 451 | usage() { 452 | { version 453 | echo "usage: lua-build [-k|--keep] [-v|--verbose] definition prefix" 454 | echo " lua-build --definitions" 455 | } >&2 456 | 457 | if [ -z "$1" ]; then 458 | exit 1 459 | fi 460 | } 461 | 462 | list_definitions() { 463 | { for definition in "${LUA_BUILD_ROOT}/share/lua-build/"*; do 464 | echo "${definition##*/}" 465 | done 466 | } | sort 467 | } 468 | 469 | 470 | 471 | unset VERBOSE 472 | unset KEEP_BUILD_PATH 473 | LUA_BUILD_ROOT="$(abs_dirname "$0")/.." 474 | 475 | parse_options "$@" 476 | 477 | for option in "${OPTIONS[@]}"; do 478 | case "$option" in 479 | "h" | "help" ) 480 | usage without_exiting 481 | { echo 482 | echo " -k/--keep Do not remove source tree after installation" 483 | echo " -v/--verbose Verbose mode: print compilation status to stdout" 484 | echo " --definitions List all built-in definitions" 485 | echo 486 | } >&2 487 | exit 0 488 | ;; 489 | "definitions" ) 490 | list_definitions 491 | exit 0 492 | ;; 493 | "k" | "keep" ) 494 | KEEP_BUILD_PATH=true 495 | ;; 496 | "v" | "verbose" ) 497 | VERBOSE=true 498 | ;; 499 | "version" ) 500 | version 501 | exit 0 502 | ;; 503 | esac 504 | done 505 | 506 | DEFINITION_PATH="${ARGUMENTS[0]}" 507 | if [ -z "$DEFINITION_PATH" ]; then 508 | usage 509 | elif [ ! -e "$DEFINITION_PATH" ]; then 510 | BUILTIN_DEFINITION_PATH="${LUA_BUILD_ROOT}/share/lua-build/${DEFINITION_PATH}" 511 | if [ -e "$BUILTIN_DEFINITION_PATH" ]; then 512 | DEFINITION_PATH="$BUILTIN_DEFINITION_PATH" 513 | else 514 | echo "lua-build: definition not found: ${DEFINITION_PATH}" >&2 515 | exit 1 516 | fi 517 | fi 518 | 519 | PREFIX_PATH="${ARGUMENTS[1]}" 520 | if [ -z "$PREFIX_PATH" ]; then 521 | usage 522 | fi 523 | 524 | if [ -z "$TMPDIR" ]; then 525 | TMP="/tmp" 526 | else 527 | TMP="${TMPDIR%/}" 528 | fi 529 | 530 | if [ -z "$MAKE" ]; then 531 | export MAKE="make" 532 | fi 533 | 534 | if [ -n "$LUA_BUILD_CACHE_PATH" ] && [ -d "$LUA_BUILD_CACHE_PATH" ]; then 535 | LUA_BUILD_CACHE_PATH="${LUA_BUILD_CACHE_PATH%/}" 536 | else 537 | unset LUA_BUILD_CACHE_PATH 538 | fi 539 | 540 | if [ -z "$LUA_BUILD_MIRROR_URL" ]; then 541 | LUA_BUILD_SKIP_MIRROR=1 542 | else 543 | LUA_BUILD_MIRROR_URL="${LUA_BUILD_MIRROR_URL%/}" 544 | fi 545 | 546 | if [ -n "$LUA_BUILD_SKIP_MIRROR" ]; then 547 | unset LUA_BUILD_MIRROR_URL 548 | fi 549 | 550 | if echo test | compute_md5 >/dev/null; then 551 | HAS_MD5_SUPPORT=1 552 | else 553 | unset HAS_MD5_SUPPORT 554 | unset LUA_BUILD_MIRROR_URL 555 | fi 556 | 557 | SEED="$(date "+%Y%m%d%H%M%S").$$" 558 | LOG_PATH="${TMP}/lua-build.${SEED}.log" 559 | LUA_BIN="${PREFIX_PATH}/bin/lua" 560 | CWD="$(pwd)" 561 | 562 | if [ -z "$LUA_BUILD_BUILD_PATH" ]; then 563 | BUILD_PATH="${TMP}/lua-build.${SEED}" 564 | else 565 | BUILD_PATH="$LUA_BUILD_BUILD_PATH" 566 | fi 567 | 568 | exec 4<> "$LOG_PATH" # open the log file at fd 4 569 | if [ -n "$VERBOSE" ]; then 570 | tail -f "$LOG_PATH" & 571 | TAIL_PID=$! 572 | trap "kill $TAIL_PID" SIGINT SIGTERM EXIT 573 | fi 574 | 575 | export LDFLAGS="-L'${PREFIX_PATH}/lib' ${LDFLAGS}" 576 | export CPPFLAGS="-I'${PREFIX_PATH}/include' ${CPPFLAGS}" 577 | 578 | unset LUAOPT 579 | unset LUALIB 580 | 581 | trap build_failed ERR 582 | mkdir -p "$BUILD_PATH" 583 | source "$DEFINITION_PATH" 584 | [ -z "${KEEP_BUILD_PATH}" ] && rm -fr "$BUILD_PATH" 585 | trap - ERR 586 | -------------------------------------------------------------------------------- /bin/luaenv-install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Summary: Install a Lua version using the lua-build plugin 4 | # 5 | # Usage: luaenv install [-f|--force] [-k|--keep] [-v|--verbose] 6 | # luaenv install [-f|--force] [-k|--keep] [-v|--verbose] 7 | # luaenv install -l|--list 8 | # 9 | # -l/--list List all available versions 10 | # -f/--force Install even if the version appears to be installed already 11 | # -s/--skip-existing Skip if the version appears to be installed already 12 | # 13 | # lua-build options: 14 | # 15 | # -k/--keep Keep source tree in $LUAENV_BUILD_ROOT after installation 16 | # (defaults to $LUAENV_ROOT/sources) 17 | # -v/--verbose Verbose mode: print compilation status to stdout 18 | # 19 | # For detailed information on installing Lua versions with 20 | # lua-build, including a list of environment variables for adjusting 21 | # compilation, see: https://github.com/sstephenson/lua-build#usage 22 | # 23 | set -e 24 | [ -n "$LUAENV_DEBUG" ] && set -x 25 | 26 | # Provide luaenv completions 27 | if [ "$1" = "--complete" ]; then 28 | exec lua-build --definitions 29 | fi 30 | 31 | if [ -z "$LUAENV_ROOT" ]; then 32 | LUAENV_ROOT="${HOME}/.luaenv" 33 | fi 34 | 35 | # Load shared library functions 36 | eval "$(lua-build --lib)" 37 | 38 | usage() { 39 | luaenv-help install 2>/dev/null 40 | [ -z "$1" ] || exit "$1" 41 | } 42 | 43 | unset FORCE 44 | unset SKIP_EXISTING 45 | unset KEEP 46 | unset VERBOSE 47 | 48 | parse_options "$@" 49 | for option in "${OPTIONS[@]}"; do 50 | case "$option" in 51 | "h" | "help" ) 52 | usage 0 53 | ;; 54 | "l" | "list" ) 55 | echo "Available versions:" 56 | lua-build --definitions | sed 's/^/ /' 57 | exit 58 | ;; 59 | "f" | "force" ) 60 | FORCE=true 61 | ;; 62 | "s" | "skip-existing" ) 63 | SKIP_EXISTING=true 64 | ;; 65 | "k" | "keep" ) 66 | [ -n "${LUAENV_BUILD_ROOT}" ] || LUAENV_BUILD_ROOT="${LUAENV_ROOT}/sources" 67 | ;; 68 | "v" | "verbose" ) 69 | VERBOSE="-v" 70 | ;; 71 | "version" ) 72 | exec lua-build --version 73 | ;; 74 | * ) 75 | usage 1 76 | ;; 77 | esac 78 | done 79 | 80 | unset VERSION_NAME 81 | 82 | # The first argument contains the definition to install. If the 83 | # argument is missing, try to install whatever local app-specific 84 | # version is specified by luaenv. Show usage instructions if a local 85 | # version is not specified. 86 | DEFINITION="${ARGUMENTS[0]}" 87 | [ -n "$DEFINITION" ] || DEFINITION="$(luaenv local 2>/dev/null || true)" 88 | [ -n "$DEFINITION" ] || usage 1 89 | 90 | 91 | # Define `before_install` and `after_install` functions that allow 92 | # plugin hooks to register a string of code for execution before or 93 | # after the installation process. 94 | declare -a before_hooks after_hooks 95 | 96 | before_install() { 97 | local hook="$1" 98 | before_hooks["${#before_hooks[@]}"]="$hook" 99 | } 100 | 101 | after_install() { 102 | local hook="$1" 103 | after_hooks["${#after_hooks[@]}"]="$hook" 104 | } 105 | 106 | # Load plugin hooks. 107 | for script in $(luaenv-hooks install); do 108 | source "$script" 109 | done 110 | 111 | 112 | # Set VERSION_NAME from $DEFINITION, if it is not already set. Then 113 | # compute the installation prefix. 114 | [ -n "$VERSION_NAME" ] || VERSION_NAME="${DEFINITION##*/}" 115 | PREFIX="${LUAENV_ROOT}/versions/${VERSION_NAME}" 116 | 117 | [ -d "${PREFIX}" ] && PREFIX_EXISTS=1 118 | 119 | # If the installation prefix exists, prompt for confirmation unless 120 | # the --force option was specified. 121 | if [ -d "${PREFIX}/bin" ]; then 122 | if [ -z "$FORCE" ] && [ -z "$SKIP_EXISTING" ]; then 123 | echo "luaenv: $PREFIX already exists" >&2 124 | read -p "continue with installation? (y/N) " 125 | 126 | case "$REPLY" in 127 | y* | Y* ) ;; 128 | * ) exit 1 ;; 129 | esac 130 | elif [ -n "$SKIP_EXISTING" ]; then 131 | # Since we know the lua version is already installed, and are opting to 132 | # not force installation of existing versions, we just `exit 0` here to 133 | # leave things happy 134 | exit 0 135 | fi 136 | fi 137 | 138 | # If LUAENV_BUILD_ROOT is set, always pass keep options to lua-build. 139 | if [ -n "${LUAENV_BUILD_ROOT}" ]; then 140 | export LUA_BUILD_BUILD_PATH="${LUAENV_BUILD_ROOT}/${VERSION_NAME}" 141 | KEEP="-k" 142 | fi 143 | 144 | # Set LUA_BUILD_CACHE_PATH to $LUAENV_ROOT/cache, if the directory 145 | # exists and the variable is not already set. 146 | if [ -z "${LUA_BUILD_CACHE_PATH}" ] && [ -d "${LUAENV_ROOT}/cache" ]; then 147 | export LUA_BUILD_CACHE_PATH="${LUAENV_ROOT}/cache" 148 | fi 149 | 150 | 151 | # Execute `before_install` hooks. 152 | for hook in "${before_hooks[@]}"; do eval "$hook"; done 153 | 154 | # Plan cleanup on unsuccessful installation. 155 | cleanup() { 156 | [ -z "${PREFIX_EXISTS}" ] && rm -rf "$PREFIX" 157 | } 158 | 159 | trap cleanup SIGINT 160 | 161 | # Invoke `lua-build` and record the exit status in $STATUS. Run 162 | # `luaenv rehash` after a successful installation. 163 | STATUS=0 164 | lua-build $KEEP $VERBOSE "$DEFINITION" "$PREFIX" || STATUS="$?" 165 | 166 | # Execute `after_install` hooks. 167 | for hook in "${after_hooks[@]}"; do eval "$hook"; done 168 | 169 | # Run `luaenv-rehash` after a successful installation. 170 | if [ "$STATUS" == "0" ]; then 171 | luaenv rehash 172 | else 173 | cleanup 174 | fi 175 | 176 | exit "$STATUS" 177 | -------------------------------------------------------------------------------- /bin/luaenv-uninstall: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Summary: Uninstall a specific Lua version 4 | # 5 | # Usage: luaenv uninstall [-f|--force] 6 | # 7 | # -f Attempt to remove the specified version without prompting 8 | # for confirmation. If the version does not exist, do not 9 | # display an error message. 10 | # 11 | # See `luaenv versions` for a complete list of installed versions. 12 | # 13 | set -e 14 | 15 | # Provide luaenv completions 16 | if [ "$1" = "--complete" ]; then 17 | exec luaenv versions --bare 18 | fi 19 | 20 | if [ -z "$LUAENV_ROOT" ]; then 21 | LUAENV_ROOT="${HOME}/.luaenv" 22 | fi 23 | 24 | unset FORCE 25 | if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then 26 | FORCE=true 27 | shift 28 | fi 29 | 30 | DEFINITION="$1" 31 | case "$DEFINITION" in 32 | "" | -* ) 33 | # We can remove the sed fallback once luaenv 0.4.0 is widely available. 34 | { luaenv-help uninstall 2>/dev/null || 35 | sed -ne '/^#/!q;s/.\{1,2\}//;1,4d;p' < "$0" 36 | } >&2 37 | exit 1 38 | ;; 39 | esac 40 | 41 | VERSION_NAME="${DEFINITION##*/}" 42 | PREFIX="${LUAENV_ROOT}/versions/${VERSION_NAME}" 43 | 44 | if [ -z "$FORCE" ]; then 45 | if [ ! -d "$PREFIX" ]; then 46 | echo "luaenv: version \`$VERSION_NAME' not installed" >&2 47 | exit 1 48 | fi 49 | 50 | read -p "luaenv: remove $PREFIX? " 51 | case "$REPLY" in 52 | y* | Y* ) ;; 53 | * ) exit 1 ;; 54 | esac 55 | fi 56 | 57 | if [ -d "$PREFIX" ]; then 58 | rm -rf "$PREFIX" 59 | luaenv rehash 60 | fi 61 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if [ -z "${PREFIX}" ]; then 6 | PREFIX="/usr/local" 7 | fi 8 | 9 | BIN_PATH="${PREFIX}/bin" 10 | SHARE_PATH="${PREFIX}/share/lua-build" 11 | 12 | mkdir -p "${BIN_PATH}" 13 | mkdir -p "${SHARE_PATH}" 14 | 15 | for file in bin/*; do 16 | cp "${file}" "${BIN_PATH}" 17 | done 18 | 19 | for file in share/lua-build/*; do 20 | cp "${file}" "${SHARE_PATH}" 21 | done 22 | 23 | echo "Installed lua-build at ${PREFIX}" 24 | -------------------------------------------------------------------------------- /share/lua-build/5.1.5: -------------------------------------------------------------------------------- 1 | install_package "lua-5.1.5" "https://www.lua.org/ftp/lua-5.1.5.tar.gz#2e115fe26e435e33b0d5c022e4490567" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.2.1: -------------------------------------------------------------------------------- 1 | install_package "lua-5.2.1" "https://www.lua.org/ftp/lua-5.2.1.tar.gz#ae08f641b45d737d12d30291a5e5f6e3" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.2.2: -------------------------------------------------------------------------------- 1 | install_package "lua-5.2.2" "https://www.lua.org/ftp/lua-5.2.2.tar.gz#efbb645e897eae37cad4344ce8b0a614" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.2.3: -------------------------------------------------------------------------------- 1 | install_package "lua-5.2.3" "https://www.lua.org/ftp/lua-5.2.3.tar.gz#dc7f94ec6ff15c985d2d6ad0f1b35654" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.2.4: -------------------------------------------------------------------------------- 1 | install_package "lua-5.2.4" "https://www.lua.org/ftp/lua-5.2.4.tar.gz#913fdb32207046b273fdb17aad70be13" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.3.0: -------------------------------------------------------------------------------- 1 | install_package "lua-5.3.0" "https://www.lua.org/ftp/lua-5.3.0.tar.gz#a1b0a7e92d0c85bbff7a8d27bf29f8af" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.3.1: -------------------------------------------------------------------------------- 1 | install_package "lua-5.3.1" "https://www.lua.org/ftp/lua-5.3.1.tar.gz#797adacada8d85761c079390ff1d9961" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.3.2: -------------------------------------------------------------------------------- 1 | install_package "lua-5.3.2" "https://www.lua.org/ftp/lua-5.3.2.tar.gz#33278c2ab5ee3c1a875be8d55c1ca2a1" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.3.3: -------------------------------------------------------------------------------- 1 | install_package "lua-5.3.3" "https://www.lua.org/ftp/lua-5.3.3.tar.gz#703f75caa4fdf4a911c1a72e67a27498" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.3.4: -------------------------------------------------------------------------------- 1 | install_package "lua-5.3.4" "https://www.lua.org/ftp/lua-5.3.4.tar.gz#53a9c68bcc0eda58bdc2095ad5cdfc63" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.3.5: -------------------------------------------------------------------------------- 1 | install_package "lua-5.3.5" "https://www.lua.org/ftp/lua-5.3.5.tar.gz#4f4b4f323fd3514a68e0ab3da8ce3455" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.3.6: -------------------------------------------------------------------------------- 1 | install_package "lua-5.3.6" "https://www.lua.org/ftp/lua-5.3.6.tar.gz#83f23dbd5230140a3770d5f54076948d" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.4.0: -------------------------------------------------------------------------------- 1 | install_package "lua-5.4.0" "https://www.lua.org/ftp/lua-5.4.0.tar.gz#dbf155764e5d433fc55ae80ea7060b60" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.4.1: -------------------------------------------------------------------------------- 1 | install_package "lua-5.4.1" "https://www.lua.org/ftp/lua-5.4.1.tar.gz#1d575faef1c907292edd79e7a2784d30" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.4.2: -------------------------------------------------------------------------------- 1 | install_package "lua-5.4.2" "https://www.lua.org/ftp/lua-5.4.2.tar.gz#49c92d6a49faba342c35c52e1ac3f81e" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.4.3: -------------------------------------------------------------------------------- 1 | install_package "lua-5.4.3" "https://www.lua.org/ftp/lua-5.4.3.tar.gz#ef63ed2ecfb713646a7fcc583cf5f352" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.4.4: -------------------------------------------------------------------------------- 1 | install_package "lua-5.4.4" "https://www.lua.org/ftp/lua-5.4.4.tar.gz#bd8ce7069ff99a400efd14cf339a727b" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.4.5: -------------------------------------------------------------------------------- 1 | install_package "lua-5.4.5" "https://www.lua.org/ftp/lua-5.4.5.tar.gz#70fe23790cfb956d595806b2b6f4ce27" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.4.6: -------------------------------------------------------------------------------- 1 | install_package "lua-5.4.6" "https://www.lua.org/ftp/lua-5.4.6.tar.gz#25a429319dff20dfbfb9956c2b5be911" 2 | -------------------------------------------------------------------------------- /share/lua-build/5.4.7: -------------------------------------------------------------------------------- 1 | install_package "lua-5.4.7" "https://www.lua.org/ftp/lua-5.4.7.tar.gz#fc3f3291353bbe6ee6dec85ee61331e8" 2 | -------------------------------------------------------------------------------- /share/lua-build/luajit-2.0.1: -------------------------------------------------------------------------------- 1 | install_package "LuaJIT-2.0.1" "https://luajit.org/download/LuaJIT-2.0.1.tar.gz" luajit 2 | -------------------------------------------------------------------------------- /share/lua-build/luajit-2.0.1-p1: -------------------------------------------------------------------------------- 1 | build_package_hotfix() { 2 | local package_name="$1" 3 | local PACKAGE_CFLAGS="${package_var_name}_CFLAGS" 4 | 5 | { 6 | curl -L https://luajit.org/download/v2.0.1_hotfix1.patch | patch -p1 7 | "$MAKE" $MAKE_OPTS amalg PREFIX="$PREFIX_PATH" XCFLAGS="${!PACKAGE_CFLAGS:--DLUAJIT_ENABLE_LUA52COMPAT}" 8 | "$MAKE" $MAKE_OPTS install PREFIX="$PREFIX_PATH" 9 | cd "${PREFIX_PATH}/bin" 10 | ln -sf luajit lua 11 | } >&4 2>&1 12 | } 13 | 14 | install_package "LuaJIT-2.0.1" "https://luajit.org/download/LuaJIT-2.0.1.tar.gz" hotfix 15 | -------------------------------------------------------------------------------- /share/lua-build/luajit-2.0.2: -------------------------------------------------------------------------------- 1 | install_package "LuaJIT-2.0.2" "https://luajit.org/download/LuaJIT-2.0.2.tar.gz" luajit 2 | -------------------------------------------------------------------------------- /share/lua-build/luajit-2.0.3: -------------------------------------------------------------------------------- 1 | install_package "LuaJIT-2.0.3" "https://luajit.org/download/LuaJIT-2.0.3.tar.gz" luajit 2 | -------------------------------------------------------------------------------- /share/lua-build/luajit-2.0.4: -------------------------------------------------------------------------------- 1 | install_package "LuaJIT-2.0.4" "https://luajit.org/download/LuaJIT-2.0.4.tar.gz" luajit 2 | -------------------------------------------------------------------------------- /share/lua-build/luajit-2.0.5: -------------------------------------------------------------------------------- 1 | install_package "LuaJIT-2.0.5" "https://luajit.org/download/LuaJIT-2.0.5.tar.gz#48353202cbcacab84ee41a5a70ea0a2c" luajit 2 | -------------------------------------------------------------------------------- /share/lua-build/luajit-2.1-dev: -------------------------------------------------------------------------------- 1 | install_git "luajit-2.1.0-beta3" "https://github.com/LuaJIT/LuaJIT.git" v2.1 luajit 2 | -------------------------------------------------------------------------------- /share/lua-build/luajit-2.1.0-beta2: -------------------------------------------------------------------------------- 1 | install_package "LuaJIT-2.1.0-beta2" "https://luajit.org/download/LuaJIT-2.1.0-beta2.tar.gz#fa14598d0d775a7ffefb138a606e0d7b" luajit 2 | -------------------------------------------------------------------------------- /share/lua-build/luajit-2.1.0-beta3: -------------------------------------------------------------------------------- 1 | install_package "LuaJIT-2.1.0-beta3" "https://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz#eae40bc29d06ee5e3078f9444fcea39b" luajit 2 | -------------------------------------------------------------------------------- /share/lua-build/luvit-0.6.0: -------------------------------------------------------------------------------- 1 | install_git "luvit-0.6.0" "https://github.com/luvit/luvit.git" 0.6.0 luvit 2 | -------------------------------------------------------------------------------- /share/lua-build/luvit-0.6.1: -------------------------------------------------------------------------------- 1 | install_git "luvit-0.6.1" "https://github.com/luvit/luvit.git" 0.6.1 luvit 2 | -------------------------------------------------------------------------------- /share/lua-build/luvit-dev: -------------------------------------------------------------------------------- 1 | install_git "luvit-dev" "https://github.com/luvit/luvit.git" master luvit 2 | -------------------------------------------------------------------------------- /test/cache.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load test_helper 4 | export RUBY_BUILD_SKIP_MIRROR=1 5 | export RUBY_BUILD_CACHE_PATH="$TMP/cache" 6 | 7 | setup() { 8 | mkdir "$RUBY_BUILD_CACHE_PATH" 9 | } 10 | 11 | 12 | @test "packages are saved to download cache" { 13 | stub md5 true 14 | stub curl "-*S* : cat package-1.0.0.tar.gz" 15 | 16 | install_fixture definitions/without-checksum 17 | [ "$status" -eq 0 ] 18 | [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] 19 | 20 | unstub curl 21 | unstub md5 22 | } 23 | 24 | 25 | @test "cached package without checksum" { 26 | stub md5 true 27 | stub curl 28 | 29 | cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH" 30 | 31 | install_fixture definitions/without-checksum 32 | [ "$status" -eq 0 ] 33 | [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] 34 | 35 | unstub curl 36 | unstub md5 37 | } 38 | 39 | 40 | @test "cached package with valid checksum" { 41 | stub md5 true "echo 83e6d7725e20166024a1eb74cde80677" 42 | stub curl 43 | 44 | cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH" 45 | 46 | install_fixture definitions/with-checksum 47 | [ "$status" -eq 0 ] 48 | [ -x "${INSTALL_ROOT}/bin/package" ] 49 | [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] 50 | 51 | unstub curl 52 | unstub md5 53 | } 54 | 55 | 56 | @test "cached package with invalid checksum falls back to mirror and updates cache" { 57 | export RUBY_BUILD_SKIP_MIRROR= 58 | local checksum="83e6d7725e20166024a1eb74cde80677" 59 | 60 | stub md5 true "echo invalid" "echo $checksum" 61 | stub curl "-*I* : true" "-*S* http://?*/$checksum : cat package-1.0.0.tar.gz" 62 | 63 | touch "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" 64 | 65 | install_fixture definitions/with-checksum 66 | [ "$status" -eq 0 ] 67 | [ -x "${INSTALL_ROOT}/bin/package" ] 68 | [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] 69 | diff -q "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" "${FIXTURE_ROOT}/package-1.0.0.tar.gz" 70 | 71 | unstub curl 72 | unstub md5 73 | } 74 | 75 | 76 | @test "nonexistent cache directory is ignored" { 77 | stub md5 true 78 | stub curl "-*S* : cat package-1.0.0.tar.gz" 79 | 80 | export RUBY_BUILD_CACHE_PATH="${TMP}/nonexistent" 81 | 82 | install_fixture definitions/without-checksum 83 | [ "$status" -eq 0 ] 84 | [ -x "${INSTALL_ROOT}/bin/package" ] 85 | [ ! -d "$RUBY_BUILD_CACHE_PATH" ] 86 | 87 | unstub curl 88 | unstub md5 89 | } 90 | -------------------------------------------------------------------------------- /test/checksum.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load test_helper 4 | export RUBY_BUILD_SKIP_MIRROR=1 5 | export RUBY_BUILD_CACHE_PATH= 6 | 7 | 8 | @test "package URL without checksum" { 9 | stub md5 true 10 | stub curl "-*S* : cat package-1.0.0.tar.gz" 11 | 12 | install_fixture definitions/without-checksum 13 | [ "$status" -eq 0 ] 14 | [ -x "${INSTALL_ROOT}/bin/package" ] 15 | 16 | unstub curl 17 | unstub md5 18 | } 19 | 20 | 21 | @test "package URL with valid checksum" { 22 | stub md5 true "echo 83e6d7725e20166024a1eb74cde80677" 23 | stub curl "-*S* : cat package-1.0.0.tar.gz" 24 | 25 | install_fixture definitions/with-checksum 26 | [ "$status" -eq 0 ] 27 | [ -x "${INSTALL_ROOT}/bin/package" ] 28 | 29 | unstub curl 30 | unstub md5 31 | } 32 | 33 | 34 | @test "package URL with invalid checksum" { 35 | stub md5 true "echo 83e6d7725e20166024a1eb74cde80677" 36 | stub curl "-*S* : cat package-1.0.0.tar.gz" 37 | 38 | install_fixture definitions/with-invalid-checksum 39 | [ "$status" -eq 1 ] 40 | [ ! -f "${INSTALL_ROOT}/bin/package" ] 41 | 42 | unstub curl 43 | unstub md5 44 | } 45 | 46 | 47 | @test "package URL with checksum but no MD5 support" { 48 | stub md5 false 49 | stub curl "-*S* : cat package-1.0.0.tar.gz" 50 | 51 | install_fixture definitions/with-checksum 52 | [ "$status" -eq 0 ] 53 | [ -x "${INSTALL_ROOT}/bin/package" ] 54 | 55 | unstub curl 56 | unstub md5 57 | } 58 | 59 | 60 | @test "package with invalid checksum" { 61 | stub md5 true "echo invalid" 62 | stub curl "-*S* : cat package-1.0.0.tar.gz" 63 | 64 | install_fixture definitions/with-checksum 65 | [ "$status" -eq 1 ] 66 | [ ! -f "${INSTALL_ROOT}/bin/package" ] 67 | 68 | unstub curl 69 | unstub md5 70 | } 71 | -------------------------------------------------------------------------------- /test/fixtures/definitions/with-checksum: -------------------------------------------------------------------------------- 1 | install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#83e6d7725e20166024a1eb74cde80677" copy 2 | -------------------------------------------------------------------------------- /test/fixtures/definitions/with-invalid-checksum: -------------------------------------------------------------------------------- 1 | install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#invalid" copy 2 | -------------------------------------------------------------------------------- /test/fixtures/definitions/without-checksum: -------------------------------------------------------------------------------- 1 | install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz" copy 2 | -------------------------------------------------------------------------------- /test/fixtures/package-1.0.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cehoffman/lua-build/880559bad4380dc9b3ac64145e44e1064238c056/test/fixtures/package-1.0.0.tar.gz -------------------------------------------------------------------------------- /test/mirror.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load test_helper 4 | export RUBY_BUILD_SKIP_MIRROR= 5 | export RUBY_BUILD_CACHE_PATH= 6 | export RUBY_BUILD_MIRROR_URL=http://mirror.example.com 7 | 8 | 9 | @test "package URL without checksum bypasses mirror" { 10 | stub md5 true 11 | stub curl "-*S* http://example.com/* : cat package-1.0.0.tar.gz" 12 | 13 | install_fixture definitions/without-checksum 14 | [ "$status" -eq 0 ] 15 | [ -x "${INSTALL_ROOT}/bin/package" ] 16 | 17 | unstub curl 18 | unstub md5 19 | } 20 | 21 | 22 | @test "package URL with checksum but no MD5 support bypasses mirror" { 23 | stub md5 false 24 | stub curl "-*S* http://example.com/* : cat package-1.0.0.tar.gz" 25 | 26 | install_fixture definitions/with-checksum 27 | [ "$status" -eq 0 ] 28 | [ -x "${INSTALL_ROOT}/bin/package" ] 29 | 30 | unstub curl 31 | unstub md5 32 | } 33 | 34 | 35 | @test "package URL with checksum hits mirror first" { 36 | local checksum="83e6d7725e20166024a1eb74cde80677" 37 | local mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum" 38 | 39 | stub md5 true "echo $checksum" 40 | stub curl "-*I* $mirror_url : true" "-*S* $mirror_url : cat package-1.0.0.tar.gz" 41 | 42 | install_fixture definitions/with-checksum 43 | [ "$status" -eq 0 ] 44 | [ -x "${INSTALL_ROOT}/bin/package" ] 45 | 46 | unstub curl 47 | unstub md5 48 | } 49 | 50 | 51 | @test "package is fetched from original URL if mirror download fails" { 52 | local checksum="83e6d7725e20166024a1eb74cde80677" 53 | local mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum" 54 | local original_url="http://example.com/packages/package-1.0.0.tar.gz" 55 | 56 | stub md5 true "echo $checksum" 57 | stub curl "-*I* $mirror_url : false" "-*S* $original_url : cat package-1.0.0.tar.gz" 58 | 59 | install_fixture definitions/with-checksum 60 | [ "$status" -eq 0 ] 61 | [ -x "${INSTALL_ROOT}/bin/package" ] 62 | 63 | unstub curl 64 | unstub md5 65 | } 66 | 67 | 68 | @test "package is fetched from original URL if mirror download checksum is invalid" { 69 | local checksum="83e6d7725e20166024a1eb74cde80677" 70 | local mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum" 71 | local original_url="http://example.com/packages/package-1.0.0.tar.gz" 72 | 73 | stub md5 true "echo invalid" "echo $checksum" 74 | stub curl "-*I* $mirror_url : true" "-*S* $mirror_url : cat package-1.0.0.tar.gz" "-*S* $original_url : cat package-1.0.0.tar.gz" 75 | 76 | install_fixture definitions/with-checksum 77 | [ "$status" -eq 0 ] 78 | [ -x "${INSTALL_ROOT}/bin/package" ] 79 | 80 | unstub curl 81 | unstub md5 82 | } 83 | 84 | 85 | @test "default mirror URL" { 86 | export RUBY_BUILD_MIRROR_URL= 87 | local checksum="83e6d7725e20166024a1eb74cde80677" 88 | 89 | stub md5 true "echo $checksum" 90 | stub curl "-*I* : true" "-*S* http://?*/$checksum : cat package-1.0.0.tar.gz" 91 | 92 | install_fixture definitions/with-checksum 93 | [ "$status" -eq 0 ] 94 | [ -x "${INSTALL_ROOT}/bin/package" ] 95 | 96 | unstub curl 97 | unstub md5 98 | } 99 | -------------------------------------------------------------------------------- /test/stubs/curl/curl: -------------------------------------------------------------------------------- 1 | ../stub -------------------------------------------------------------------------------- /test/stubs/md5/md5: -------------------------------------------------------------------------------- 1 | ../stub -------------------------------------------------------------------------------- /test/stubs/stub: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | status=0 5 | program="${0##*/}" 6 | PROGRAM="$(echo "$program" | tr a-z A-Z)" 7 | [ -n "$TMPDIR" ] || TMPDIR="/tmp" 8 | 9 | _STUB_PLAN="${PROGRAM}_STUB_PLAN" 10 | _STUB_RUN="${PROGRAM}_STUB_RUN" 11 | _STUB_DIR="${PROGRAM}_STUB_DIR" 12 | _STUB_INDEX="${PROGRAM}_STUB_INDEX" 13 | _STUB_RESULT="${PROGRAM}_STUB_RESULT" 14 | _STUB_END="${PROGRAM}_STUB_END" 15 | 16 | [ -e "${!_STUB_PLAN}" ] || exit 1 17 | [ -n "${!_STUB_RUN}" ] || eval "${_STUB_RUN}"="${TMPDIR}/${program}-stub-run" 18 | 19 | 20 | # Initialize or load the stub run information. 21 | eval "${_STUB_INDEX}"=1 22 | eval "${_STUB_RESULT}"=0 23 | [ ! -e "${!_STUB_RUN}" ] || source "${!_STUB_RUN}" 24 | 25 | 26 | # Loop over each line in the plan. 27 | index=0 28 | while IFS= read -r line; do 29 | index=$(($index + 1)) 30 | 31 | if [ -z "${!_STUB_END}" ] && [ $index -eq "${!_STUB_INDEX}" ]; then 32 | # We found the plan line we're interested in. 33 | # Start off by assuming success. 34 | result=0 35 | 36 | # Split the line into an array of arguments to 37 | # match and a command to run to produce output. 38 | command=" $line" 39 | if [ "$command" != "${command/ : }" ]; then 40 | patterns="${command%% : *}" 41 | command="${command#* : }" 42 | fi 43 | 44 | # Naively split patterns by whitespace for now. 45 | # In the future, use a sed script to split while 46 | # respecting quoting. 47 | patterns=($patterns) 48 | arguments=("$@") 49 | 50 | # Match the expected argument patterns to actual 51 | # arguments. 52 | for (( i=0; i<${#patterns[@]}; i++ )); do 53 | pattern="${patterns[$i]}" 54 | argument="${arguments[$i]}" 55 | 56 | case "$argument" in 57 | $pattern ) ;; 58 | * ) result=1 ;; 59 | esac 60 | done 61 | 62 | # If the arguments matched, evaluate the command 63 | # in a subshell. Otherwise, log the failure. 64 | if [ $result -eq 0 ] ; then 65 | dir="$(pwd)" 66 | [ ! -d "${!_STUB_DIR}" ] || dir="${!_STUB_DIR}" 67 | set +e 68 | ( cd "$dir" ; eval "$command" ) 69 | status="$?" 70 | set -e 71 | else 72 | eval "${_STUB_RESULT}"=1 73 | fi 74 | fi 75 | done < "${!_STUB_PLAN}" 76 | 77 | 78 | if [ -n "${!_STUB_END}" ]; then 79 | # Clean up the run file. 80 | rm -f "${!_STUB_RUN}" 81 | 82 | # If the number of lines in the plan is larger than 83 | # the requested index, we failed. 84 | if [ $index -ge "${!_STUB_INDEX}" ]; then 85 | eval "${_STUB_RESULT}"=1 86 | fi 87 | 88 | # Return the result. 89 | exit "${!_STUB_RESULT}" 90 | 91 | else 92 | # If the requested index is larger than the number 93 | # of lines in the plan file, we failed. 94 | if [ "${!_STUB_INDEX}" -gt $index ]; then 95 | eval "${_STUB_RESULT}"=1 96 | fi 97 | 98 | # Write out the run information. 99 | { echo "${_STUB_INDEX}=$((${!_STUB_INDEX} + 1))" 100 | echo "${_STUB_RESULT}=${!_STUB_RESULT}" 101 | } > "${!_STUB_RUN}" 102 | 103 | exit "$status" 104 | 105 | fi 106 | -------------------------------------------------------------------------------- /test/test_helper.bash: -------------------------------------------------------------------------------- 1 | export PATH="$BATS_TEST_DIRNAME/../bin:$PATH" 2 | export TMP="$BATS_TEST_DIRNAME/tmp" 3 | export FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures" 4 | export INSTALL_ROOT="$TMP/install" 5 | 6 | teardown() { 7 | rm -fr "$TMP"/* 8 | } 9 | 10 | stub() { 11 | local program="$1" 12 | local prefix="$(echo "$program" | tr a-z A-Z)" 13 | shift 14 | 15 | export "${prefix}_STUB_PLAN"="${TMP}/${program}-stub-plan" 16 | export "${prefix}_STUB_RUN"="${TMP}/${program}-stub-run" 17 | export "${prefix}_STUB_DIR"="$FIXTURE_ROOT" 18 | export "${prefix}_STUB_END"= 19 | 20 | export PATH="${BATS_TEST_DIRNAME}/stubs/${program}:$PATH" 21 | 22 | rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run" 23 | touch "${TMP}/${program}-stub-plan" 24 | for arg in "$@"; do printf "%s\n" "$arg" >> "${TMP}/${program}-stub-plan"; done 25 | } 26 | 27 | unstub() { 28 | local program="$1" 29 | local prefix="$(echo "$program" | tr a-z A-Z)" 30 | 31 | export "${prefix}_STUB_DIR"= 32 | export "${prefix}_STUB_END"=1 33 | 34 | local path="${BATS_TEST_DIRNAME}/stubs/$program" 35 | local escaped_path="${path//\//\\/}" 36 | export PATH="${PATH/${escaped_path}:}" 37 | 38 | "${path}/$program" 39 | } 40 | 41 | install_fixture() { 42 | local name="$1" 43 | local destination="$2" 44 | [ -n "$destination" ] || destination="$INSTALL_ROOT" 45 | 46 | run ruby-build "$FIXTURE_ROOT/$name" "$destination" 47 | } 48 | -------------------------------------------------------------------------------- /test/tmp/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | --------------------------------------------------------------------------------