Skip to content

Commit 0ef8125

Browse files
committed
Add working directories and refactor bison usages
1 parent 29e4227 commit 0ef8125

File tree

6 files changed

+98
-95
lines changed

6 files changed

+98
-95
lines changed

cmake/Zend/cmake/GenerateGrammar.cmake

Lines changed: 72 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -12,85 +12,83 @@ if(
1212
endif()
1313
include(PHP/BISON)
1414

15-
if(BISON_FOUND)
16-
php_bison(
17-
zend_ini_parser
18-
zend_ini_parser.y
19-
${CMAKE_CURRENT_SOURCE_DIR}/zend_ini_parser.c
20-
COMPILE_FLAGS "${PHP_BISON_DEFAULT_OPTIONS}"
21-
VERBOSE REPORT_FILE zend_ini_parser.output
22-
DEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/zend_ini_parser.h
23-
)
15+
php_bison(
16+
zend_ini_parser
17+
zend_ini_parser.y
18+
${CMAKE_CURRENT_SOURCE_DIR}/zend_ini_parser.c
19+
COMPILE_FLAGS "${PHP_BISON_DEFAULT_OPTIONS}"
20+
VERBOSE REPORT_FILE zend_ini_parser.output
21+
DEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/zend_ini_parser.h
22+
)
2423

25-
php_bison(
26-
zend_language_parser
27-
zend_language_parser.y
28-
${CMAKE_CURRENT_SOURCE_DIR}/zend_language_parser.c
29-
COMPILE_FLAGS "${PHP_BISON_DEFAULT_OPTIONS}"
30-
VERBOSE REPORT_FILE zend_language_parser.output
31-
DEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/zend_language_parser.h
32-
)
24+
php_bison(
25+
zend_language_parser
26+
zend_language_parser.y
27+
${CMAKE_CURRENT_SOURCE_DIR}/zend_language_parser.c
28+
COMPILE_FLAGS "${PHP_BISON_DEFAULT_OPTIONS}"
29+
VERBOSE REPORT_FILE zend_language_parser.output
30+
DEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/zend_language_parser.h
31+
)
3332

34-
# Tweak zendparse to be exported through ZEND_API. This has to be revisited
35-
# once bison supports foreign skeletons and that bison version is used. Read
36-
# https://git.savannah.gnu.org/cgit/bison.git/tree/data/README.md for more.
37-
block()
33+
# Tweak zendparse to be exported through ZEND_API. This has to be revisited
34+
# once bison supports foreign skeletons and that bison version is used. Read
35+
# https://git.savannah.gnu.org/cgit/bison.git/tree/data/README.md for more.
36+
block()
37+
string(
38+
CONCAT patch
39+
"set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})\n"
40+
[[
41+
file(READ "${SOURCE_DIR}/zend_language_parser.h" content)
3842
string(
39-
CONCAT patch
40-
"set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})\n"
41-
[[
42-
file(READ "${SOURCE_DIR}/zend_language_parser.h" content)
43-
string(
44-
REPLACE
45-
"int zendparse"
46-
"ZEND_API int zendparse"
47-
content_2
48-
"${content}"
49-
)
50-
if(
51-
NOT content MATCHES "ZEND_API int zendparse"
52-
AND NOT content STREQUAL "${content_2}"
53-
)
54-
message(STATUS "[Zend] Patching zend_language_parser.h")
55-
file(WRITE "${SOURCE_DIR}/zend_language_parser.h" "${content_2}")
56-
endif()
57-
58-
file(READ "${SOURCE_DIR}/zend_language_parser.c" content)
59-
string(
60-
REPLACE
61-
"int zendparse"
62-
"ZEND_API int zendparse"
63-
content_2
64-
"${content}"
65-
)
66-
if(
67-
NOT content MATCHES "ZEND_API int zendparse"
68-
AND NOT content STREQUAL "${content_2}"
69-
)
70-
message(STATUS "[Zend] Patching zend_language_parser.c")
71-
file(WRITE "${SOURCE_DIR}/zend_language_parser.c" "${content_2}")
72-
endif()
73-
]])
43+
REPLACE
44+
"int zendparse"
45+
"ZEND_API int zendparse"
46+
content_2
47+
"${content}"
48+
)
49+
if(
50+
NOT content MATCHES "ZEND_API int zendparse"
51+
AND NOT content STREQUAL "${content_2}"
52+
)
53+
message(STATUS "[Zend] Patching zend_language_parser.h")
54+
file(WRITE "${SOURCE_DIR}/zend_language_parser.h" "${content_2}")
55+
endif()
7456

75-
# Run patch based on whether building or running inside a CMake script.
76-
if(CMAKE_SCRIPT_MODE_FILE)
77-
cmake_language(EVAL CODE "${patch}")
78-
else()
79-
file(
80-
GENERATE
81-
OUTPUT CMakeFiles/PatchLanguageParser.cmake
82-
CONTENT "${patch}"
83-
)
84-
add_custom_target(
85-
zend_patch_language_parser
86-
COMMAND ${CMAKE_COMMAND} -P CMakeFiles/PatchLanguageParser.cmake
87-
DEPENDS ${BISON_zend_language_parser_OUTPUTS}
88-
VERBATIM
89-
)
90-
add_dependencies(zend zend_patch_language_parser)
57+
file(READ "${SOURCE_DIR}/zend_language_parser.c" content)
58+
string(
59+
REPLACE
60+
"int zendparse"
61+
"ZEND_API int zendparse"
62+
content_2
63+
"${content}"
64+
)
65+
if(
66+
NOT content MATCHES "ZEND_API int zendparse"
67+
AND NOT content STREQUAL "${content_2}"
68+
)
69+
message(STATUS "[Zend] Patching zend_language_parser.c")
70+
file(WRITE "${SOURCE_DIR}/zend_language_parser.c" "${content_2}")
9171
endif()
92-
endblock()
93-
endif()
72+
]])
73+
74+
# Run patch based on whether building or running inside a CMake script.
75+
if(CMAKE_SCRIPT_MODE_FILE)
76+
cmake_language(EVAL CODE "${patch}")
77+
else()
78+
file(
79+
GENERATE
80+
OUTPUT CMakeFiles/PatchLanguageParser.cmake
81+
CONTENT "${patch}"
82+
)
83+
add_custom_target(
84+
zend_patch_language_parser
85+
COMMAND ${CMAKE_COMMAND} -P CMakeFiles/PatchLanguageParser.cmake
86+
DEPENDS ${BISON_zend_language_parser_OUTPUTS}
87+
VERBATIM
88+
)
89+
add_dependencies(zend zend_patch_language_parser)
90+
endif()
91+
endblock()
9492

9593
if(
9694
EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zend_ini_scanner.c

cmake/cmake/modules/FindBISON.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,8 @@ function(bison_execute)
100100
"[BISON][${ARGV0}] Generating parser with bison ${BISON_VERSION}"
101101
)
102102

103-
execute_process(${commands})
103+
execute_process(
104+
${commands}
105+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
106+
)
104107
endfunction()

cmake/cmake/modules/FindRE2C.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ function(${RE2C_NAMESPACE}re2c)
375375

376376
if(CMAKE_SCRIPT_MODE_FILE)
377377
message(STATUS "[RE2C] ${message}")
378-
execute_process(${commands})
378+
execute_process(${commands} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
379379
return()
380380
endif()
381381

@@ -400,6 +400,7 @@ function(${RE2C_NAMESPACE}re2c)
400400
VERBATIM
401401
COMMAND_EXPAND_LISTS
402402
${codegen}
403+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
403404
)
404405
endfunction()
405406

@@ -423,7 +424,7 @@ function(${RE2C_NAMESPACE}re2c_execute)
423424
endif()
424425

425426
message(STATUS "[RE2C] ${message}")
426-
execute_process(${commands})
427+
execute_process(${commands} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
427428
endfunction()
428429

429430
################################################################################

cmake/cmake/modules/PHP/BISON.cmake

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ block()
6868
endblock()
6969

7070
macro(php_bison)
71-
if(CMAKE_SCRIPT_MODE_FILE)
72-
bison_execute(${ARGN})
73-
else()
74-
bison_target(${ARGN})
71+
if(BISON_FOUND)
72+
if(CMAKE_SCRIPT_MODE_FILE)
73+
bison_execute(${ARGN})
74+
else()
75+
bison_target(${ARGN})
76+
endif()
7577
endif()
7678
endmacro()

cmake/cmake/scripts/GenerateGrammar.cmake

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
#
88
# cmake -P cmake/scripts/GenerateLexersParsers.cmake
99
#
10-
# bison and re2c executables can be also manually overridden:
10+
# To manually override bison and re2c executables:
1111
#
12-
# [BISON_EXECUTABLE=path/to/bison] \
13-
# [RE2C_EXECUTABLE=path/to/re2c] \
14-
# cmake -P cmake/scripts/GenerateLexersParsers.cmake
12+
# cmake \
13+
# [-D BISON_EXECUTABLE=path/to/bison] \
14+
# [-D RE2C_EXECUTABLE=path/to/re2c] \
15+
# -P cmake/scripts/GenerateLexersParsers.cmake
1516
#
1617
# TODO: Fix CS and fine tune this.
1718
#

cmake/sapi/phpdbg/cmake/GenerateGrammar.cmake

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ if(
88
endif()
99
include(PHP/BISON)
1010

11-
if(BISON_FOUND)
12-
php_bison(
13-
php_sapi_phpdbg_parser
14-
phpdbg_parser.y
15-
${CMAKE_CURRENT_SOURCE_DIR}/phpdbg_parser.c
16-
COMPILE_FLAGS "${PHP_BISON_DEFAULT_OPTIONS}"
17-
VERBOSE REPORT_FILE phpdbg_parser.output
18-
DEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/phpdbg_parser.h
19-
)
20-
endif()
11+
php_bison(
12+
php_sapi_phpdbg_parser
13+
phpdbg_parser.y
14+
phpdbg_parser.c
15+
COMPILE_FLAGS "${PHP_BISON_DEFAULT_OPTIONS}"
16+
VERBOSE REPORT_FILE phpdbg_parser.output
17+
DEFINES_FILE phpdbg_parser.h
18+
)
2119

2220
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/phpdbg_lexer.c)
2321
set(PHP_RE2C_OPTIONAL TRUE)

0 commit comments

Comments
 (0)