Skip to content

Commit 580fbe2

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
2 parents 9a39c6b + 72af325 commit 580fbe2

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

cmake/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ add_subdirectory(scripts)
6767
# Check thread safety.
6868
include(PHP/ThreadSafety)
6969

70+
# Generate *_arginfo.h headers from *.stub.php sources.
71+
include(PHP/Stubs)
72+
7073
# Execute all deferred calls. Calls are additionally sorted with natural
7174
# comparison method by their IDs. If call hasn't set any ID number, CMake
7275
# assigns it a default value of __<number>.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#[=============================================================================[
2+
Generate *_arginfo.h headers from the *.stub.php sources
3+
4+
The build/gen_stub.php script requires the PHP tokenizer extension.
5+
#]=============================================================================]
6+
7+
include_guard(GLOBAL)
8+
9+
# Store a list of all binary targets inside the given <dir> to the <result>
10+
# variable.
11+
function(_php_stubs_get_binary_targets result dir)
12+
get_property(targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
13+
get_property(subdirs DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
14+
15+
# Filter only binary targets.
16+
set(binaryTargets)
17+
foreach(target ${targets})
18+
get_target_property(type ${target} TYPE)
19+
if(type MATCHES "^((STATIC|MODULE|SHARED|OBJECT)_LIBRARY|EXECUTABLE)$")
20+
list(APPEND binaryTargets ${target})
21+
endif()
22+
endforeach()
23+
set(targets ${binaryTargets})
24+
25+
foreach(subdir ${subdirs})
26+
cmake_language(CALL ${CMAKE_CURRENT_FUNCTION} subdirTargets ${subdir})
27+
list(APPEND targets ${subdirTargets})
28+
endforeach()
29+
30+
set(${result} ${targets} PARENT_SCOPE)
31+
endfunction()
32+
33+
# If PHP is not found on the system, the PHP cli SAPI will be used with the
34+
# tokenizer extension.
35+
if(NOT PHPSystem_EXECUTABLE AND NOT EXT_TOKENIZER AND NOT SAPI_CLI)
36+
return()
37+
endif()
38+
39+
if(EXISTS ${PROJECT_SOURCE_DIR}/build/gen_stub.php)
40+
file(
41+
COPY
42+
${PROJECT_SOURCE_DIR}/build/gen_stub.php
43+
DESTINATION ${PROJECT_BINARY_DIR}/build
44+
)
45+
else()
46+
return()
47+
endif()
48+
49+
block()
50+
_php_stubs_get_binary_targets(targets ${PROJECT_SOURCE_DIR})
51+
52+
set(stubs)
53+
foreach(target ${targets})
54+
list(
55+
APPEND
56+
stubs
57+
$<PATH:ABSOLUTE_PATH,NORMALIZE,$<LIST:FILTER,$<TARGET_PROPERTY:${target},SOURCES>,INCLUDE,\.stub\.php$>,$<TARGET_PROPERTY:${target},SOURCE_DIR>>
58+
)
59+
60+
if(PHPSystem_EXECUTABLE)
61+
add_dependencies(${target} php_stubs)
62+
endif()
63+
endforeach()
64+
65+
file(
66+
GENERATE
67+
OUTPUT ${PROJECT_BINARY_DIR}/CMakeFiles/php_stubs.txt
68+
CONTENT "$<JOIN:$<REMOVE_DUPLICATES:${stubs}>,$<SEMICOLON>>"
69+
)
70+
71+
set(PHP_COMMAND)
72+
73+
if(PHPSystem_EXECUTABLE)
74+
set(PHP_COMMAND ${PHPSystem_EXECUTABLE})
75+
else()
76+
if(NOT CMAKE_CROSSCOMPILING)
77+
set(PHP_COMMAND $<TARGET_FILE:php_cli>)
78+
elseif(CMAKE_CROSSCOMPILING AND CMAKE_CROSSCOMPILING_EMULATOR)
79+
set(PHP_COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:php_cli>)
80+
endif()
81+
endif()
82+
83+
if(EXT_TOKENIZER_SHARED AND NOT PHPSystem_EXECUTABLE)
84+
list(
85+
APPEND
86+
PHP_COMMAND
87+
-d extension_dir=${PROJECT_BINARY_DIR}/modules
88+
-d extension=tokenizer
89+
)
90+
endif()
91+
92+
if(NOT PHPSystem_EXECUTABLE)
93+
set(targetOptions ALL DEPENDS ${targets})
94+
endif()
95+
96+
add_custom_target(
97+
php_stubs ${targetOptions}
98+
COMMAND
99+
${CMAKE_COMMAND}
100+
"-DPHP_STUBS=${PROJECT_BINARY_DIR}/CMakeFiles/php_stubs.txt"
101+
"-DPHP_COMMAND=${PHP_COMMAND};${PROJECT_BINARY_DIR}/build/gen_stub.php"
102+
-P ${CMAKE_CURRENT_LIST_DIR}/Stubs/RunCommand.cmake
103+
VERBATIM
104+
)
105+
endblock()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#[=============================================================================[
2+
Script for processing PHP stub sources.
3+
4+
Expected variables:
5+
6+
* PHP_COMMAND
7+
* PHP_STUBS
8+
#]=============================================================================]
9+
10+
if(NOT PHP_COMMAND OR NOT EXISTS "${PHP_STUBS}")
11+
return()
12+
endif()
13+
14+
file(READ ${PHP_STUBS} sources)
15+
16+
foreach(stub ${sources})
17+
string(REGEX REPLACE [[\.stub\.php$]] "_arginfo.h" header "${stub}")
18+
if(${stub} IS_NEWER_THAN ${header})
19+
list(APPEND stubs ${stub})
20+
endif()
21+
endforeach()
22+
23+
if(NOT stubs)
24+
return()
25+
endif()
26+
27+
execute_process(
28+
COMMAND
29+
${CMAKE_COMMAND}
30+
-E cmake_echo_color --blue --bold
31+
"Regenerating *_arginfo.h headers from *.stub.php sources"
32+
)
33+
34+
execute_process(COMMAND ${PHP_COMMAND} ${stubs})
35+
36+
foreach(stub ${stubs})
37+
string(REGEX REPLACE [[\.stub\.php$]] "_arginfo.h" header "${stub}")
38+
if(
39+
EXISTS "${stub}"
40+
AND EXISTS "${header}"
41+
AND "${stub}" IS_NEWER_THAN "${header}"
42+
)
43+
file(TOUCH "${header}")
44+
endif()
45+
endforeach()

0 commit comments

Comments
 (0)