Skip to content

Commit c183bfe

Browse files
authored
Merge pull request #7 from francisek/feature/build-extensions
Added ability to build pecl or custom extensions. Improved code quality.
2 parents 24d431c + efa3678 commit c183bfe

File tree

9 files changed

+292
-35
lines changed

9 files changed

+292
-35
lines changed

.codeclimate.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
engines:
3+
fixme:
4+
enabled: false
5+
shellcheck:
6+
enabled: true
7+
ratings:
8+
paths:
9+
- "**.sh"
10+
- "bin/php-band"
11+
exclude_paths:
12+
- archs/
13+
- config/
14+
- test/
15+
- inst/
16+
- src/
17+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
/bats/
2+
/inst/
3+
/src/
4+
/config/*
25

CHANGELOG.md

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

3+
0.3.0 :
4+
5+
- Added variable `php_band_php_extension_dir`
6+
- Added extension building support
7+
38
0.2.0 :
49

510
- Added a check of configuration files modification date to rebuild

README.md

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# php-band
22

33
<img src="https://circleci.com/gh/francisek/php-band/tree/master.svg?style=shield&circle-token=0e2b5681405bbc52e77bce982d74c449b46636d8" />
4+
[![Code Climate](https://codeclimate.com/github/francisek/php-band/badges/gpa.svg)](https://codeclimate.com/github/francisek/php-band)
45

56
A simple bash tool to compile php versions
67

@@ -69,6 +70,8 @@ What does php-band is :
6970
+ marks the version as built
7071
+ installs php to inst/<version>
7172
+ runs *post_install_php()* function if installation was successfull
73+
+ builds pecl extensions
74+
+ builds external extensions
7275

7376
# Custom configuration
7477

@@ -110,19 +113,108 @@ Its default value is defined to "--disable-all".
110113

111114
The pre_\* and post_\* functions are called with the working directory set to the php source directory.
112115

116+
## Building extensions
117+
118+
Extensions are built and installed after php itself.
119+
120+
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.
121+
122+
### Using pecl
123+
124+
You add some pecl extensions to build in your *configure-php.sh* file by using the function *php_band_pecl_add_package*.
125+
It takes the package name as first parameter and eventually a string representing user inputs as second parameter.
126+
The pecl package name must be a string accordingly to [pecl documentation](http://php.net/manual/en/install.pecl.pear.php).
127+
For example to install the xdebug package, use either :
128+
129+
```
130+
php_band_pecl_add_package 'xdebug'
131+
```
132+
133+
or
134+
135+
```
136+
php_band_pecl_add_package 'xdebug-2.5.0'
137+
```
138+
139+
or
140+
141+
```
142+
php_band_pecl_add_package 'pecl.php.net/xdebug-stable'
143+
```
144+
145+
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).
146+
You can remove the building extension request with the function *php_band_pecl_remove_package* :
147+
148+
```
149+
php_band_pecl_remove_package 'xhprof'
150+
```
151+
152+
### Building custom extensions
153+
154+
You can request building a custom extension with function *php_band_external_add*.
155+
It takes a request identifer string as first parameter. Any other parameter will be passed to a callback function of your own named *extension_<identifier>*.
156+
157+
For example, let's build the extension xhprof. The pecl version builds untin php 5.99.
158+
Our `config/configure-php.sh` may look like:
159+
160+
```bash
161+
#!/bin/bash -e
162+
163+
php_band_pecl_add_package 'xhprof-stable'
164+
```
165+
166+
In the `config/7/configure-php.sh` file we won't install pecl version but the git version from branch 'php7':
167+
168+
```bash
169+
#!/bin/bash -e
170+
171+
php_band_pecl_remove_package 'xhprof-stable'
172+
php_band_external_add 'custom_xhprof' 'https://github.com/RustJason/xhprof.git' 'php7'
173+
174+
# @param $1 Git repository
175+
# @param $2 Git branch
176+
extension_custom_xhprof() {
177+
local repo="$1"
178+
local branch="${2:-master}"
179+
local xhprof_src_dir="${PHP_BAND_SOURCE_DIR}/$(php_band_build_php_source_dirname)/ext/xhprof"
180+
181+
if [ -f "${php_band_php_extension_dir}/xhprof.so" ]; then
182+
echo "Xhprof already installed"
183+
return 0
184+
fi
185+
186+
[ -d "$xhprof_src_dir" ] && rm -rf "$xhprof_src_dir"
187+
git clone --depth 1 --branch "$branch" $repo "${xhprof_src_dir}"
188+
cd "$xhprof_src_dir/extension"
189+
${php_band_php_install_dir}/bin/phpize
190+
./configure --with-php-config=${php_band_php_install_dir}/bin/php-config
191+
make ${MAKE_OPTS} && make install
192+
193+
echo "extension=${php_band_php_extension_dir}/xhprof.so" > ${php_band_php_install_dir}/conf.d/xhprof.ini
194+
}
195+
```
196+
197+
And finally there is no current branch working with PHP 7.1 line, so our file `config/7/1/configure-php.sh` would look like:
198+
199+
```bash
200+
#!/bin/bash -e
201+
202+
php_band_external_remove 'custom_xhprof'
203+
```
204+
113205
## Readonly variables
114206

115207
Those variables can be used but should not be modified:
116208

117209
+ *PHP_BAND_INST_DIR* Directory for all installations
118210
+ *PHP_BAND_SOURCE_DIR* Directory for all sources
119-
+ *php_band_php_install_dir* Directory into wich the current php will installed
211+
+ *php_band_php_install_dir* Directory into which the current php version will be installed
120212
+ *php_version* The full php version string (for example 5.6.3RC2)
121213
+ *php_version_major* The php major version (for example 5)
122214
+ *php_version_minor* The php minor version (for example 6)
123215
+ *php_version_patch* The php patch version (for example 3)
124216
+ *php_version_addon* The php version (for example RC2)
125-
+ *php_band_php_install_dir* The directory where php is installed
217+
+ *php_band_php_extension_dir* The directory where php looks extensions for. Available from the post_install_php() stage.
126218

127219
## Usefull functions
128220

@@ -144,6 +236,9 @@ Some core functions may be usefull in your functions :
144236
+ {{php_version_patch}} The php patch version (for example 3)
145237
+ {{php_version_addon}} The php version (for example RC2)
146238
+ {{php_band_php_install_dir}} The directory where php is installed
239+
+ {{php_band_php_extension_dir}} The directory where php loads its extensions. Available after installation.
240+
+ *php_band_build_php_source_dirname()*
241+
Returns the php dirname where php sources resides. This is used in conjonction with *${PHP_BAND_SOURCE_DIR}*
147242

148243
# Best practises in writing configuration files
149244

bin/php-band

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

33
PHP_BAND_NAME=$(basename "$0")
4-
pushd "$(dirname $0)" > /dev/null
5-
PHP_BAND_ROOT_DIR=$(dirname $(pwd -P))
4+
pushd "$(dirname "$0")" > /dev/null
5+
PHP_BAND_ROOT_DIR=$(dirname "$(pwd -P)")
66
popd > /dev/null
77
PHP_BAND_ASSETS_DIR=${PHP_BAND_ASSETS_DIR:-$PHP_BAND_ROOT_DIR}
88
PHP_BAND_ARCH_DIR=${PHP_BAND_ASSETS_DIR}/archs
@@ -18,14 +18,16 @@ php_version_major=
1818
php_version_minor=
1919
php_version_patch=
2020
php_version_addon=
21+
# shellcheck disable=SC2016
2122
php_prefered_sites=(
2223
'http://museum.php.net/php${php_version_major}/${php_band_archive_filename}'
2324
'http://docs.php.net/distributions/${php_band_archive_filename}'
2425
)
2526
# configurable options
2627
php_band_php_install_dir=
2728
php_band_php_config_options=
28-
29+
php_band_php_extension_dir=
30+
# shellcheck source=lib/core.sh
2931
source $PHP_BAND_ROOT_DIR/lib/core.sh
3032
# Commands
3133

@@ -45,13 +47,13 @@ EOM
4547
}
4648

4749
command_version() {
48-
echo "0.2.0"
50+
echo "0.3.0"
4951
exit 0
5052
}
5153

5254
command_download() {
5355
php_band_parse_version $php_version
54-
if [ "$php_version_major" = "" -o "$php_version_minor" = "" -o "$php_version_patch" = "" ]; then
56+
if [ "$php_version_major" = "" ] || [ "$php_version_minor" = "" ] || [ "$php_version_patch" = "" ] ; then
5557
error_exit "The version format is not valid" 1
5658
fi
5759
php_band_build_source_filename
@@ -70,7 +72,8 @@ command_src_format() {
7072
}
7173

7274
command_list_installed() {
73-
local list=$(ls -1bv "$PHP_BAND_INST_DIR")
75+
local list
76+
list=$(ls -1bv "$PHP_BAND_INST_DIR")
7477
if [ "$list" != "" ]; then
7578
log_info "$list"
7679
fi

0 commit comments

Comments
 (0)