Skip to content

Commit

Permalink
Add patch support
Browse files Browse the repository at this point in the history
  • Loading branch information
stricte authored and smorimoto committed Feb 3, 2022
1 parent ab86d61 commit 99037fe
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
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

0 comments on commit 99037fe

Please sign in to comment.