Skip to content

Commit ed682e5

Browse files
committed
Implement extension load-order deps.
1 parent 22b70fc commit ed682e5

File tree

9 files changed

+133
-4
lines changed

9 files changed

+133
-4
lines changed

acinclude.m4

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,3 +1920,14 @@ AC_DEFUN(PHP_TEST_BUILD, [
19201920
LIBS=$old_LIBS
19211921
])
19221922
])
1923+
1924+
dnl This macro is currently a placeholder in the config.m4 file
1925+
dnl it is scanned by genif.sh when it builds the internal functions
1926+
dnl list, so that modules can be init'd in the correct order
1927+
dnl $1 = name of extension, $2 = extension upon which it depends
1928+
dnl $3 = optional: if true, it's ok for $2 to have not been configured
1929+
dnl default is false and should halt the build.
1930+
dnl See ADD_EXTENSION_DEP in win32 build
1931+
AC_DEFUN(PHP_ADD_EXTENSION_DEP, [])
1932+
1933+

build/genif.sh

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

3-
# $Id: genif.sh,v 1.3 2002-03-22 10:22:41 sas Exp $
3+
# $Id: genif.sh,v 1.4 2004-07-18 12:03:51 wez Exp $
44
# replacement for genif.pl
55

66
infile=$1
@@ -17,13 +17,13 @@ if test -z "$infile" || test -z "$srcdir"; then
1717
exit 1
1818
fi
1919

20-
module_ptrs=$extra_module_ptrs
2120
header_list=
2221
olddir=`pwd`
2322
cd $srcdir
2423

24+
module_ptrs="$extra_module_ptrs`echo $@ | $awk -f ./build/order_by_dep.awk`"
25+
2526
for ext in ${1+"$@"} ; do
26-
module_ptrs=" phpext_${ext}_ptr,@NEWLINE@$module_ptrs"
2727
header_list="$header_list ext/$ext/*.h"
2828
done
2929

build/order_by_dep.awk

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
BEGIN {
2+
orig_rs = RS;
3+
orig_fs = FS;
4+
RS=" ";
5+
mod_count = 0;
6+
SUBSEP=":";
7+
}
8+
9+
function get_deps(module_name, depline, cmd)
10+
{
11+
# this could probably be made *much* better
12+
RS=orig_rs;
13+
FS="[(,) \t]+"
14+
cmd = "grep PHP_ADD_EXTENSION_DEP ext/" module_name "/config*.m4"
15+
while (cmd | getline) {
16+
# printf("GOT: %s,%s,%s,%s,%s\n", $1, $2, $3, $4, $5);
17+
if (!length($5)) {
18+
$5 = 0;
19+
}
20+
mod_deps[module_name, $4] = $5;
21+
}
22+
close(cmd)
23+
RS=" ";
24+
FS=orig_fs;
25+
}
26+
27+
function get_module_index(name, i)
28+
{
29+
for (i in mods) {
30+
if (mods[i] == name) {
31+
return i;
32+
}
33+
}
34+
return -1;
35+
}
36+
37+
function do_deps(mod_idx, module_name, mod_name_len, dep, ext, val, depidx)
38+
{
39+
module_name = mods[mod_idx];
40+
mod_name_len = length(module_name);
41+
42+
for (ext in mod_deps) {
43+
if (substr(ext, 0, mod_name_len+1) != module_name SUBSEP) {
44+
continue;
45+
}
46+
val = mod_deps[ext];
47+
ext = substr(ext, mod_name_len+2, length(ext)-mod_name_len);
48+
49+
depidx = get_module_index(ext);
50+
if (depidx >= 0) {
51+
do_deps(depidx);
52+
}
53+
}
54+
55+
#printf(" phpext_%s_ptr,\n", module_name);
56+
printf(" phpext_%s_ptr,@NEWLINE@", module_name);
57+
delete mods[mod_idx];
58+
}
59+
60+
function count(arr, n, i)
61+
{
62+
n = 0;
63+
for (i in arr)
64+
n++;
65+
return n;
66+
}
67+
68+
/^[a-zA-Z0-9_-]+/ {
69+
# mini hack for pedantic awk
70+
gsub("[^a-zA-Z0-9_-]", "", $1)
71+
# add each item to array
72+
mods[mod_count++] = $1
73+
74+
# see if it has any module deps
75+
get_deps($1);
76+
}
77+
END {
78+
# order it correctly
79+
out_count = 0;
80+
81+
while (count(mods)) {
82+
# count down, since we need to assemble it in reverse order
83+
for (i = mod_count-1; i >= 0; --i) {
84+
if (i in mods) {
85+
do_deps(i);
86+
}
87+
}
88+
}
89+
}

configure.in

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,31 @@ PHP_RUNPATH_SWITCH
130130
PHP_PROG_RE2C
131131
AC_PROG_RANLIB
132132
AC_PROG_LN_S
133-
AC_PROG_AWK
133+
134+
dnl Some vendors force mawk before gawk; mawk is broken so we don't like that,
135+
dnl and check manually
136+
dnl AC_PROG_AWK
137+
AC_CHECK_PROGS(AWK, gawk nawk awk mawk, bork, /usr/xpg4/bin/:$PATH)
138+
case "$AWK" in
139+
*mawk)
140+
AC_MSG_WARN([mawk is known to have problems on some systems. You should install GNU awk])
141+
;;
142+
*gawk)
143+
;;
144+
bork)
145+
AC_MSG_ERROR([Could not find awk; Install GNU awk])
146+
;;
147+
*)
148+
AC_MSG_CHECKING([if $AWK is broken])
149+
if ! $AWK 'function foo() {}' >/dev/null 2>&1 ; then
150+
AC_MSG_RESULT([yes])
151+
AC_MSG_ERROR([You should install GNU awk])
152+
else
153+
AC_MSG_RESULT([no - good!])
154+
fi
155+
;;
156+
esac
157+
134158
AC_PROG_YACC
135159
if test "$YACC" != "bison -y"; then
136160
AC_MSG_WARN([You will need bison if you want to regenerate the PHP parsers.])

ext/dom/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if test "$PHP_DOM" != "no" && test "$PHP_LIBXML" != "no"; then
2626
typeinfo.c domerror.c domlocator.c namednodemap.c userdatahandler.c],
2727
$ext_shared)
2828
PHP_SUBST(DOM_SHARED_LIBADD)
29+
PHP_ADD_EXTENSION_DEP(dom, libxml)
2930
], [
3031
AC_MSG_ERROR([xml2-config not found. Please check your libxml2 installation.])
3132
])

ext/simplexml/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ if test "$PHP_SIMPLEXML" != "no" && test "$PHP_LIBXML" != "no"; then
1818
], [
1919
AC_MSG_ERROR([xml2-config not found. Please check your libxml2 installation.])
2020
])
21+
PHP_ADD_EXTENSION_DEP(simplexml, libxml)
2122
fi

ext/spl/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ if test "$PHP_SPL" != "no"; then
1010
fi
1111
AC_DEFINE(HAVE_SPL, 1, [Whether you want SPL (Standard PHP Library) support])
1212
PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_sxe.c, $ext_shared)
13+
PHP_ADD_EXTENSION_DEP(spl, simplexml)
1314
fi

ext/xml/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ if test "$PHP_XML" != "no" && test "$PHP_LIBXML" != "no" -o "$PHP_LIBEXPAT_DIR"
4747

4848
PHP_NEW_EXTENSION(xml, xml.c $xml_extra_sources, $ext_shared)
4949
PHP_SUBST(XML_SHARED_LIBADD)
50+
PHP_ADD_EXTENSION_DEP(xml, libxml)
5051
AC_DEFINE(HAVE_XML, 1, [ ])
5152
fi

ext/xsl/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ if test "$PHP_XSL" != "no"; then
5959
AC_DEFINE(HAVE_XSL,1,[ ])
6060
PHP_NEW_EXTENSION(xsl, php_xsl.c xsltprocessor.c, $ext_shared)
6161
PHP_SUBST(XSL_SHARED_LIBADD)
62+
PHP_ADD_EXTENSION_DEP(xsl, libxml)
6263
fi

0 commit comments

Comments
 (0)