Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add patch support #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ If PHP PEAR is down you can install PHP without PEAR. Specify `PHP_WITHOUT_PEAR`
PHP_WITHOUT_PEAR=yes asdf install php <version>
```

#### Patch support

```
PHP_APPLY_PATCHES=$'dir/1.patch\n2.patch\nhttp://example.com/3.patch' asdf install php 7.1.1
```

## Usage

Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to
Expand Down
40 changes: 40 additions & 0 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ install_php() {
local install_type=$1
local version=$2
local install_path=$3
local start_dir=$(pwd)

if [ "$TMPDIR" = "" ]; then
local tmp_download_dir=$(mktemp -d)
Expand Down Expand Up @@ -79,6 +80,8 @@ install_php() {

cd $(untar_path $install_type $version $tmp_download_dir)

apply_custom_patches "$start_dir" || exit 1

# Target is OS-specific
# target=$(get_target)

Expand Down Expand Up @@ -109,6 +112,43 @@ install_composer() {
$bin_path/php -r "unlink('composer-setup.php');"
}

apply_custom_patches() {
local start_dir=$1
while read -r line; do
if [ "$line" = "" ]; then
continue
fi
# define earlier, so that the exit 1 shorthand below works
local content
if [[ "$line" =~ ^[Hh][Tt][Tt][Pp][Ss]?:// ]]; then
echo "Applying patch from URL: $line"
content=$(curl -Sfs "$line") || exit 1
else
local abs_path=$(get_absolute_path "$start_dir" "$line")
echo "Applying local patch: $abs_path"
content=$(<"$abs_path") || exit 1
fi

local striplevel=0
grep -q '^diff --git a/' <<< "$content" && striplevel=1
patch -p$striplevel --force <<< "$content" || exit 1
done <<< "$PHP_APPLY_PATCHES"
}

get_absolute_path() {
local start_dir=$1
local rel_path=$2
local rel_dir=$(dirname "$rel_path")
local rel_base=$(basename "$rel_path")

(
cd "$start_dir" \
&& cd "$rel_dir" 2>/dev/null \
&& echo "$(pwd)/$rel_base" \
|| echo "$rel_path"
)
}

construct_configure_options() {
local install_path=$1

Expand Down