Skip to content

Commit 9e1aa86

Browse files
committed
Improve *.stubs.php processing
- Generate CMake script for running the stubs generator which includes the stub sources retrieve during the configuration and generation phase - Output locations adjusted and cleaned up a bit in the binary directory - EditorConfig adjusted for *.cmake.in templates - Patches updated
1 parent bdd0370 commit 9e1aa86

File tree

8 files changed

+67
-54
lines changed

8 files changed

+67
-54
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ trim_trailing_whitespace = false
2626
[COMMIT_EDITMSG]
2727
max_line_length = 80
2828

29-
[{*.cmake,CMakeLists.txt}]
29+
[{CMakeLists.txt,*.{cmake,cmake.in}}]
3030
indent_size = 2

cmake/cmake/modules/PHP/Stubs.cmake

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,11 @@ function(_php_stubs_get_php_command result)
3434
endif()
3535
endif()
3636

37-
set(command)
38-
3937
if(NOT CMAKE_CROSSCOMPILING)
4038
set(command $<TARGET_FILE:php_cli>)
4139
elseif(CMAKE_CROSSCOMPILING AND CMAKE_CROSSCOMPILING_EMULATOR)
4240
set(command ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:php_cli>)
43-
endif()
44-
45-
if(NOT command)
41+
else()
4642
return(PROPAGATE ${result})
4743
endif()
4844

@@ -91,13 +87,13 @@ endif()
9187
file(
9288
COPY
9389
${PROJECT_SOURCE_DIR}/build/gen_stub.php
94-
DESTINATION ${PROJECT_BINARY_DIR}/build
90+
DESTINATION ${PROJECT_BINARY_DIR}/CMakeFiles/php_stubs
9591
)
9692

9793
block()
98-
_php_stubs_get_php_command(command)
94+
_php_stubs_get_php_command(PHP_COMMAND)
9995

100-
if(NOT command)
96+
if(NOT PHP_COMMAND)
10197
return()
10298
endif()
10399

@@ -116,10 +112,13 @@ block()
116112
endif()
117113
endforeach()
118114

115+
set(PHP_SOURCES "$<JOIN:$<REMOVE_DUPLICATES:${stubs}>,$<SEMICOLON>>")
116+
file(READ ${CMAKE_CURRENT_LIST_DIR}/Stubs/PHPStubsGenerator.cmake.in content)
117+
string(CONFIGURE "${content}" content @ONLY)
119118
file(
120119
GENERATE
121-
OUTPUT ${PROJECT_BINARY_DIR}/CMakeFiles/php_stubs.txt
122-
CONTENT "$<JOIN:$<REMOVE_DUPLICATES:${stubs}>,$<SEMICOLON>>"
120+
OUTPUT ${PROJECT_BINARY_DIR}/CMakeFiles/php_stubs/PHPStubsGenerator.cmake
121+
CONTENT "${content}"
123122
)
124123

125124
if(NOT PHPSystem_EXECUTABLE)
@@ -130,9 +129,7 @@ block()
130129
php_stubs ${targetOptions}
131130
COMMAND
132131
${CMAKE_COMMAND}
133-
"-DPHP_STUBS=${PROJECT_BINARY_DIR}/CMakeFiles/php_stubs.txt"
134-
"-DPHP_COMMAND=${command};${PROJECT_BINARY_DIR}/build/gen_stub.php"
135-
-P ${CMAKE_CURRENT_LIST_DIR}/Stubs/RunCommand.cmake
132+
-P ${PROJECT_BINARY_DIR}/CMakeFiles/php_stubs/PHPStubsGenerator.cmake
136133
VERBATIM
137134
)
138135
endblock()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#[=============================================================================[
2+
Script for processing PHP stub sources.
3+
#]=============================================================================]
4+
5+
set(sources "@PHP_SOURCES@")
6+
7+
# Ensure sources include only *.stub.php files.
8+
list(FILTER sources INCLUDE REGEX [[\.stub\.php$]])
9+
10+
# Create a list of sources that must be parsed by the generator.
11+
if(@PROJECT_SOURCE_DIR@/build/gen_stub.php IS_NEWER_THAN ${CMAKE_CURRENT_LIST_FILE})
12+
file(
13+
COPY
14+
@PROJECT_SOURCE_DIR@/build/gen_stub.php
15+
DESTINATION @PROJECT_BINARY_DIR@/CMakeFiles/php_stubs
16+
)
17+
set(stubs ${sources})
18+
file(TOUCH ${CMAKE_CURRENT_LIST_FILE})
19+
else()
20+
foreach(stub ${sources})
21+
string(REGEX REPLACE [[\.stub\.php$]] [[_arginfo.h]] header "${stub}")
22+
if("${stub}" IS_NEWER_THAN "${header}")
23+
list(APPEND stubs ${stub})
24+
endif()
25+
endforeach()
26+
endif()
27+
28+
if(NOT stubs)
29+
return()
30+
endif()
31+
32+
execute_process(
33+
COMMAND
34+
${CMAKE_COMMAND}
35+
-E cmake_echo_color --blue --bold
36+
"Regenerating *_arginfo.h headers from *.stub.php sources"
37+
)
38+
39+
execute_process(
40+
COMMAND
41+
@PHP_COMMAND@ @PROJECT_BINARY_DIR@/CMakeFiles/php_stubs/gen_stub.php
42+
${stubs}
43+
)
44+
45+
# Ensure that *_arginfo.h headers are newer than their *.stub.php sources.
46+
foreach(stub ${stubs})
47+
string(REGEX REPLACE [[\.stub\.php$]] [[_arginfo.h]] header "${stub}")
48+
if("${stub}" IS_NEWER_THAN "${header}")
49+
file(TOUCH "${header}")
50+
endif()
51+
endforeach()

cmake/cmake/modules/PHP/Stubs/RunCommand.cmake

Lines changed: 0 additions & 35 deletions
This file was deleted.

patches/8.3/dmalloc.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ See: https://github.com/php/php-src/pull/8465
99
1 file changed, 2 insertions(+), 1 deletion(-)
1010

1111
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
12-
index aa54cf9c7b..0c91b9f890 100644
12+
index 585ac8ab9d..4c7cb05460 100644
1313
--- a/sapi/cli/php_cli_server.c
1414
+++ b/sapi/cli/php_cli_server.c
1515
@@ -15,6 +15,8 @@

patches/8.4/dmalloc.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ See: https://github.com/php/php-src/pull/8465
99
1 file changed, 2 insertions(+), 1 deletion(-)
1010

1111
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
12-
index 654f3ee680..723b443434 100644
12+
index bcf5af320d..0fb5537258 100644
1313
--- a/sapi/cli/php_cli_server.c
1414
+++ b/sapi/cli/php_cli_server.c
1515
@@ -15,6 +15,8 @@

patches/8.5/cmake.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ Subject: Add CMake changes for PHP-8.5 branch
1313
5 files changed, 84 insertions(+), 7 deletions(-)
1414

1515
diff --git a/.editorconfig b/.editorconfig
16-
index 7911bf8490..0ca142015f 100644
16+
index 7911bf8490..ed6ec7a642 100644
1717
--- a/.editorconfig
1818
+++ b/.editorconfig
1919
@@ -17,7 +17,7 @@ indent_style = tab
2020
indent_size = 4
2121
indent_style = space
2222

2323
-[*.{ac,m4,sh,yml}]
24-
+[{CMakeLists.txt,*.{ac,cmake,json,m4,sh,yml}}]
24+
+[{CMakeLists.txt,*.{ac,cmake,cmake.in,json,m4,sh,yml}}]
2525
indent_size = 2
2626
indent_style = space
2727

patches/8.5/dmalloc.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ See: https://github.com/php/php-src/pull/8465
99
1 file changed, 2 insertions(+), 1 deletion(-)
1010

1111
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
12-
index 654f3ee680..723b443434 100644
12+
index fc2e282995..877007bd86 100644
1313
--- a/sapi/cli/php_cli_server.c
1414
+++ b/sapi/cli/php_cli_server.c
1515
@@ -15,6 +15,8 @@

0 commit comments

Comments
 (0)