Skip to content

Commit 7a4f8c9

Browse files
authored
Feat/custom extension callback (#9)
* Custom post pecl build callbacks
1 parent e3a7389 commit 7a4f8c9

File tree

7 files changed

+59
-22
lines changed

7 files changed

+59
-22
lines changed

.codeclimate.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ engines:
44
enabled: false
55
shellcheck:
66
enabled: true
7+
exclude_fingerprints:
8+
- f3a504d17f12f40fdd844596ffdbf736
9+
- 4ccff9eccea3fa979ffe68b8945f0891
10+
- 46c633c75fd34040d1a09071df1fd691
711
ratings:
812
paths:
913
- "**.sh"

CHANGELOG.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# Changelog
22

3+
0.4.0 :
4+
5+
- Fix prefered download site usage
6+
- Add post pecl build callback
7+
38
0.3.0 :
49

5-
- Added variable `php_band_php_extension_dir`
6-
- Added extension building support
10+
- Add variable `php_band_php_extension_dir`
11+
- Add extension building support
712

813
0.2.0 :
914

10-
- Added a check of configuration files modification date to rebuild
11-
- Created an asset directory for testing
12-
- Added possibility to specify the root dir with environment variable PHP_BAND_ASSETS_DIR
15+
- Add a check of configuration files modification date to rebuild
16+
- Create an asset directory for testing
17+
- Add possibility to specify the root dir with environment variable PHP_BAND_ASSETS_DIR
1318

1419
0.1.0 : Initial version

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,20 @@ The pre_\* and post_\* functions are called with the working directory set to th
119119

120120
Extensions are built and installed after php itself.
121121

122-
It is of your responsability to provide the loading and parameters of the extension to php, generally by creating an extension_name.ini file in the `${php_band_php_install_dir}/conf.d/` directory.
122+
It is of your responsability to provide the loading and parameters of the extension to php, generally by either:
123+
124+
- create a post extension build callback
125+
- create an extension_name.ini file in the `${php_band_php_install_dir}/conf.d/` directory.
123126

124127
### Using pecl
125128

126129
You add some pecl extensions to build in your *configure-php.sh* file by using the function *php_band_pecl_add_package*.
127-
It takes the package name as first parameter and eventually a string representing user inputs as second parameter.
128-
The pecl package name must be a string accordingly to [pecl documentation](http://php.net/manual/en/install.pecl.pear.php).
130+
It takes the following arguments:
131+
132+
- the package name as first parameter is mandatory. Refer to [pecl documentation](http://php.net/manual/en/install.pecl.pear.php) for available formats ;
133+
- an optionnal string representing user inputs as second parameter. Add a newline character `\n` after each simulated user answer ;
134+
- an optionnal post build callback name. The default value is `post_pecl_<package name>_build`. If the function exists it will be called on successfull build.
135+
129136
For example to install the xdebug package, use either :
130137

131138
```
@@ -135,13 +142,13 @@ php_band_pecl_add_package 'xdebug'
135142
or
136143

137144
```
138-
php_band_pecl_add_package 'xdebug-2.5.0'
145+
php_band_pecl_add_package 'xdebug-2.5.0' '' 'post_pecl_xhprof_build'
139146
```
140147

141148
or
142149

143150
```
144-
php_band_pecl_add_package 'pecl.php.net/xdebug-stable'
151+
php_band_pecl_add_package 'pecl.php.net/xdebug-stable' '' 'post_pecl_xhprof_build'
145152
```
146153

147154
You may know some extensions defined in a lower config file are not compatible with a specific version (for example, xhprof does not work on 7.x).
@@ -162,7 +169,11 @@ Our `config/configure-php.sh` may look like:
162169
```bash
163170
#!/bin/bash -e
164171

165-
php_band_pecl_add_package 'xhprof-stable'
172+
php_band_pecl_add_package 'xhprof-stable' '' 'post_pecl_xhprof_build'
173+
174+
post_pecl_xhprof_build() {
175+
echo 'extension=xhprof.so' > "${php_band_php_install_dir}/conf.d/xhprof.ini"
176+
}
166177
```
167178

168179
In the `config/7/configure-php.sh` file we won't install pecl version but the git version from branch 'php7':
@@ -192,7 +203,7 @@ extension_custom_xhprof() {
192203
./configure --with-php-config=${php_band_php_install_dir}/bin/php-config
193204
make ${MAKE_OPTS} && make install
194205

195-
echo "extension=${php_band_php_extension_dir}/xhprof.so" > ${php_band_php_install_dir}/conf.d/xhprof.ini
206+
echo "extension=xhprof.so" > ${php_band_php_install_dir}/conf.d/xhprof.ini
196207
}
197208
```
198209

bin/php-band

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ EOM
4747
}
4848

4949
command_version() {
50-
echo "0.3.0"
50+
echo "0.4.0"
5151
exit 0
5252
}
5353

lib/core.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ php_band_check_for_source() {
135135
php_band_archive_filename=$(php_band_build_source_filename)
136136
srcfile="$PHP_BAND_ARCH_DIR/$php_band_archive_filename"
137137
[ -f "$srcfile" ] && [ -s "$srcfile" ] && return
138-
for i in "${php_prefered_sites:?[@]}" ; do
138+
for i in "${php_prefered_sites[@]:?}" ; do
139139
host=$(php_band_apply_shell_expansion "${i%%}")
140140
log_info "Attempting to download from $host"
141141
$WGET_BIN -P "$PHP_BAND_ARCH_DIR" -O "$srcfile" "$host"
@@ -172,12 +172,12 @@ php_band_get_php_extension_dir() {
172172

173173
php_band_pecl_add_package() {
174174
local package="$1"
175-
local user_input=$2
175+
local options=(${@:2})
176176
if [ -z "${package}" ]; then
177177
echo "Package name is mandatory"
178178
return 1
179179
fi
180-
PHP_BAND_CUSTOM_PECL_EXTENSIONS[$package]=$user_input
180+
PHP_BAND_CUSTOM_PECL_EXTENSIONS[$package]=${options[*]}
181181
return 0
182182
}
183183

@@ -194,20 +194,36 @@ php_band_pecl_remove_package() {
194194
php_band_pecl_build_extension() {
195195
local ext_channel="$1"
196196
local user_input="${2}"
197+
local post_install="${3:-post_pecl_$1_build}"
198+
local build_output
197199
log_info "Building pecl extension ${ext_channel}"
198-
echo "${user_input}" | "${php_band_php_install_dir}"/bin/pecl install "${ext_channel}" > /dev/null
199-
[ $? -eq 0 ] || log_info "Extension building failed"
200+
build_output=$(echo -e "${user_input}" | "${php_band_php_install_dir}"/bin/pecl install "${ext_channel}" 2>&1)
201+
if [ "" != "$(echo "${build_output}" | grep -i "Build process completed successfully")" ]; then
202+
log_info " Extension built successfully"
203+
elif [ "" != "$(echo "${build_output}" | grep -i "already installed")" ]; then
204+
log_info " Extension already built"
205+
else
206+
log_info " Extension building failed $(echo "${build_output}" | grep -i 'error')"
207+
return
208+
fi
209+
210+
if [ -n "${post_install}" ] && [ "$(type -t "${post_install}")" = "function" ]; then
211+
log_info " Calling post built action ${post_install}"
212+
${post_install}
213+
fi
200214
}
201215

202216
php_band_pecl_build() {
203217
local cwd
218+
local pecl_args
204219
cwd="$(pwd)"
205220
echo "Pecl Extensions to install : ${!PHP_BAND_CUSTOM_PECL_EXTENSIONS[*]}"
206221
for pecl_channel in ${!PHP_BAND_CUSTOM_PECL_EXTENSIONS[*]} ; do
207222
echo "Pecl extension $pecl_channel requested"
208223
# shellcheck disable=SC2164
209224
cd "$cwd"
210-
php_band_pecl_build_extension "$pecl_channel" "${PHP_BAND_CUSTOM_PECL_EXTENSIONS[${pecl_channel}]}"
225+
pecl_args=${PHP_BAND_CUSTOM_PECL_EXTENSIONS[${pecl_channel}]}
226+
php_band_pecl_build_extension "$pecl_channel" ${pecl_args[@]}
211227
done
212228
# shellcheck disable=SC2164
213229
cd "$cwd"
@@ -245,7 +261,7 @@ php_band_external_build() {
245261
command_to_run="extension_${ext_et}"
246262
if [ "$(type -t "$command_to_run")" = "function" ]; then
247263
command_params=${PHP_BAND_CUSTOM_EXTERNAL_EXTENSIONS[$ext_et]}
248-
$command_to_run "${command_params[@]}"
264+
$command_to_run ${command_params[@]}
249265
fi
250266
done
251267
}

test/10_simple_commands.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ load test_helper
44

55
@test "Call php-band with query version argument" {
66
run bin/php-band --version
7-
assert_output "0.3.0"
7+
assert_output "0.4.0"
88
assert_success
99
}
1010

test/20_pecl_extensions.bats

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ setup() {
1010
local output
1111
php_band_php_install_dir="${BATS_TEST_DIRNAME}/mock"
1212
output=$(php_band_pecl_build_extension 'test')
13-
assert_equals "Building pecl extension test" "$output"
13+
assert_contains "Building pecl extension test" "$output"
14+
assert_contains "Extension building failed" "$output"
1415
}
1516

1617
@test "Request installation of a pecl extension" {

0 commit comments

Comments
 (0)