Skip to content

Commit 0532a99

Browse files
committed
Fix nits
1 parent 0d9a2cf commit 0532a99

File tree

13 files changed

+108
-116
lines changed

13 files changed

+108
-116
lines changed

bin/check-cmake.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ function getProjectModules(): array
191191
'FindPackageMessage' => ['find_package_message'],
192192
'ProcessorCount' => ['processorcount'],
193193
'PHP/AddCustomCommand' => ['php_add_custom_command'],
194+
'PHP/Bison' => ['php_bison', '/find_package\([\n ]*BISON/'],
194195
'PHP/CheckAttribute' => [
195196
'php_check_function_attribute',
196197
'php_check_variable_attribute',
@@ -199,6 +200,7 @@ function getProjectModules(): array
199200
'PHP/ConfigureFile' => ['php_configure_file'],
200201
'PHP/Install' => ['php_install'],
201202
'PHP/PkgConfigGenerator' => ['pkgconfig_generate_pc'],
203+
'PHP/Re2c' => ['php_re2c', '/find_package\([\n ]*RE2C/'],
202204
'PHP/SearchLibraries' => ['php_search_libraries'],
203205
'PHP/Set' => ['php_set'],
204206
'PHP/SystemExtensions' => ['PHP::SystemExtensions'],
@@ -273,24 +275,29 @@ function checkCMakeInclude(Iterator $files, array $modules): int
273275
$content = getCMakeCode($file);
274276

275277
// Check for redundant includes.
276-
foreach ($modules as $module => $commands) {
278+
foreach ($modules as $module => $patterns) {
277279
$hasModule = false;
278280
$moduleEscaped = str_replace('/', '\/', $module);
279281

280282
if (1 === preg_match('/^[ \t]*include[ \t]*\(' . $moduleEscaped . '[ \t]*\)/m', $content)) {
281283
$hasModule = true;
282284
}
283285

284-
$hasCommand = false;
285-
foreach ($commands as $command) {
286-
if (
286+
$hasPattern = false;
287+
foreach ($patterns as $pattern) {
288+
if (isRegularExpression($pattern)) {
289+
if (1 === preg_match($pattern, $content)) {
290+
$hasPattern = true;
291+
break;
292+
}
293+
} elseif (
287294
(
288-
1 === preg_match('/::/', $command)
289-
&& 1 === preg_match('/[^A-Za-z0-9_]' . $command . '[^A-Za-z0-9_]/m', $content)
295+
1 === preg_match('/::/', $pattern)
296+
&& 1 === preg_match('/[^A-Za-z0-9_]' . $pattern . '[^A-Za-z0-9_]/m', $content)
290297
)
291-
|| 1 === preg_match('/^[ \t]*' . $command . '[ \t]*\(/m', $content)
298+
|| 1 === preg_match('/^[ \t]*' . $pattern . '[ \t]*\(/m', $content)
292299
) {
293-
$hasCommand = true;
300+
$hasPattern = true;
294301
break;
295302
}
296303
}
@@ -304,12 +311,12 @@ function checkCMakeInclude(Iterator $files, array $modules): int
304311
continue;
305312
}
306313

307-
if ($hasModule && !$hasCommand) {
314+
if ($hasModule && !$hasPattern) {
308315
$status = 1;
309316
output("E: redundant include($module) in $file");
310317
}
311318

312-
if (!$hasModule && $hasCommand) {
319+
if (!$hasModule && $hasPattern) {
313320
$status = 1;
314321
output("E: missing include($module) in $file");
315322
}
@@ -319,6 +326,18 @@ function checkCMakeInclude(Iterator $files, array $modules): int
319326
return $status;
320327
};
321328

329+
/**
330+
* Check if given string is regular expression.
331+
*/
332+
function isRegularExpression(string $string): bool
333+
{
334+
set_error_handler(static function () {}, E_WARNING);
335+
$isRegularExpression = false !== preg_match($string, '');
336+
restore_error_handler();
337+
338+
return $isRegularExpression;
339+
}
340+
322341
/**
323342
* Check for set(<variable>) usages with only one argument. These should be
324343
* replaced with set(<variable> "").

cmake/Zend/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ if(TARGET Zend::MaxExecutionTimers)
523523
endif()
524524

525525
################################################################################
526-
# Generate lexer and parser files.
526+
# Generate parser and lexer files.
527527
################################################################################
528528

529529
include(cmake/GenerateGrammar.cmake)

cmake/Zend/cmake/GenerateGrammar.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generate lexer and parser files.
1+
# Generate parser and lexer files.
22

33
if(CMAKE_SCRIPT_MODE_FILE STREQUAL CMAKE_CURRENT_LIST_FILE)
44
message(FATAL_ERROR "This file should be used with include().")
@@ -32,9 +32,9 @@ php_bison(
3232
CODEGEN
3333
)
3434

35-
# Tweak zendparse to be exported through ZEND_API. This has to be revisited
36-
# once bison supports foreign skeletons and that bison version is used. Read
37-
# https://git.savannah.gnu.org/cgit/bison.git/tree/data/README.md for more.
35+
# Tweak zendparse to be exported through ZEND_API. This has to be revisited if
36+
# Bison will support foreign skeletons.
37+
# See: https://git.savannah.gnu.org/cgit/bison.git/tree/data/README.md
3838
block()
3939
string(
4040
CONCAT patch
@@ -79,7 +79,7 @@ block()
7979
endif()
8080
]])
8181

82-
# Run patch based on whether building or running inside a CMake script.
82+
# Run patch based on whether building or running inside a script.
8383
if(CMAKE_SCRIPT_MODE_FILE)
8484
cmake_language(EVAL CODE "${patch}")
8585
else()

cmake/cmake/Configuration.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,7 @@ set_package_properties(
259259
DESCRIPTION "Compression library"
260260
)
261261

262-
# Set base directory for the ExternalProject CMake module across the PHP.
263-
set_directory_properties(PROPERTIES EP_BASE ${PHP_BINARY_DIR}/_deps/EP)
262+
# Set base directory for ExternalProject CMake module.
263+
set_directory_properties(
264+
PROPERTIES EP_BASE ${PHP_BINARY_DIR}/CMakeFiles/PHP/ExternalProject
265+
)

cmake/cmake/modules/FindBISON.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ set_package_properties(
1616
DESCRIPTION "General-purpose parser generator"
1717
)
1818

19-
# Include CMake find module. Absolute path prevents the maximum
20-
# nesting/recursion depth error on some systems, like macOS.
19+
# Find package with upstream CMake find module. Absolute path prevents the
20+
# maximum nesting/recursion depth error on some systems, like macOS.
2121
include(${CMAKE_ROOT}/Modules/FindBISON.cmake)

cmake/cmake/modules/FindRE2C.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ set_package_properties(
3131
# Find the executable.
3232
################################################################################
3333

34+
set(_re2cRequiredVars RE2C_EXECUTABLE)
3435
set(_reason "")
3536

3637
find_program(
@@ -48,14 +49,15 @@ endif()
4849
# Check version.
4950
################################################################################
5051

51-
block(PROPAGATE RE2C_VERSION _reason)
52+
block(PROPAGATE RE2C_VERSION _reason _re2cRequiredVars)
5253
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.29)
5354
set(test IS_EXECUTABLE)
5455
else()
5556
set(test EXISTS)
5657
endif()
5758

5859
if(${test} ${RE2C_EXECUTABLE})
60+
list(APPEND _re2cRequiredVars RE2C_VERSION)
5961
execute_process(
6062
COMMAND ${RE2C_EXECUTABLE} --version
6163
OUTPUT_VARIABLE version
@@ -65,12 +67,9 @@ block(PROPAGATE RE2C_VERSION _reason)
6567
)
6668

6769
if(NOT result EQUAL 0)
68-
string(APPEND _reason "Command \"${RE2C_EXECUTABLE} --version\" failed. ")
70+
string(APPEND _reason "Command '${RE2C_EXECUTABLE} --version' failed. ")
6971
elseif(version MATCHES "^re2c ([0-9.]+[^\n]+)")
70-
find_package_check_version("${CMAKE_MATCH_1}" valid)
71-
if(valid)
72-
set(RE2C_VERSION "${CMAKE_MATCH_1}")
73-
endif()
72+
set(RE2C_VERSION "${CMAKE_MATCH_1}")
7473
else()
7574
string(APPEND _reason "Invalid version format. ")
7675
endif()
@@ -79,10 +78,11 @@ endblock()
7978

8079
find_package_handle_standard_args(
8180
RE2C
82-
REQUIRED_VARS RE2C_EXECUTABLE RE2C_VERSION
81+
REQUIRED_VARS ${_re2cRequiredVars}
8382
VERSION_VAR RE2C_VERSION
8483
HANDLE_VERSION_RANGE
8584
REASON_FAILURE_MESSAGE "${_reason}"
8685
)
8786

87+
unset(_re2cRequiredVars)
8888
unset(_reason)

cmake/cmake/modules/PHP/Bison.cmake

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ php_bison(
2525
)
2626
```
2727

28-
This creates a CMake target `<name>` and adds a command that generates parser
29-
file `<output>` from the given `<input>` template file using the `bison` parser
28+
This creates a target `<name>` and adds a command that generates parser file
29+
`<output>` from the given `<input>` template file using the Bison parser
3030
generator. Relative source file path `<input>` is interpreted as being relative
3131
to the current source directory. Relative `<output>` file path is interpreted as
3232
being relative to the current binary directory. If generated files are already
3333
available (for example, shipped with the released archive), and Bison is not
34-
found, it will create a custom target but skip the `bison` command-line
35-
execution.
34+
found, it will create a target but skip the `bison` command-line execution.
3635

37-
When used in CMake command-line script mode (see `CMAKE_SCRIPT_MODE_FILE`) it
36+
When used in command-line script mode (see `CMAKE_SCRIPT_MODE_FILE`) it
3837
generates the parser right away without creating a target.
3938

4039
#### Options
@@ -57,38 +56,36 @@ generates the parser right away without creating a target.
5756
* `DEPENDS <depends>...` - Optional list of dependent files to regenerate the
5857
output file.
5958

60-
* `VERBOSE` - This adds the `--verbose` (`-v`) command-line option to and will
61-
create extra output file `<parser-output-filename>.output` containing verbose
62-
descriptions of the grammar and parser. File will be by default created in the
63-
current binary directory.
59+
* `VERBOSE` - Adds the `--verbose` (`-v`) command-line option and creates extra
60+
output file `<parser-output-filename>.output` in the current binary directory.
61+
Report contains verbose grammar and parser descriptions.
6462

65-
* `REPORT_FILE <file>` - This adds the `--report-file=<file>` command-line
66-
option and will create verbose information report in the specified `<file>`.
67-
This option must be used together with the `VERBOSE` option. Relative file
68-
path is interpreted as being relative to the current binary directory.
63+
* `REPORT_FILE <file>` - Adds the `--report-file=<file>` command-line option and
64+
creates verbose information report in the specified `<file>`. This option must
65+
be used with the `VERBOSE` option. Relative file path is interpreted as being
66+
relative to the current binary directory.
6967

70-
* `CODEGEN` - This adds the `CODEGEN` option to the `add_custom_command()` call.
71-
Works as of CMake 3.31 when policy `CMP0171` is set to `NEW`, which provides a
72-
global CMake `codegen` target for convenience to call only the
73-
code-generation-related targets and skip the majority of the build:
68+
* `CODEGEN` - Adds the `CODEGEN` option to the `add_custom_command()` call. This
69+
option is available starting with CMake 3.31 when the policy `CMP0171` is set
70+
to `NEW`. It provides a `codegen` target for convenience, allowing to run only
71+
code-generation-related targets while skipping the majority of the build:
7472

7573
```sh
7674
cmake --build <dir> --target codegen
7775
```
7876

79-
* `WORKING_DIRECTORY <working-directory>` - The path where the `bison` is
80-
executed. Relative `<working-directory>` path is interpreted as being relative
81-
to the current binary directory. If not set, `bison` is by default executed in
82-
the `PHP_SOURCE_DIR` when building the php-src repository. Otherwise it is
77+
* `WORKING_DIRECTORY <directory>` - The path where the `re2c` is executed.
78+
Relative `<directory>` path is interpreted as being relative to the current
79+
binary directory. If not set, `bison` is by default executed in the
80+
`PHP_SOURCE_DIR` when building the php-src repository. Otherwise it is
8381
executed in the directory of the `<output>` file. If variable
8482
`PHP_BISON_WORKING_DIRECTORY` is set before calling the `php_bison()` without
8583
this option, it will set the default working directory to that instead.
8684

8785
* `ABSOLUTE_PATHS` - Whether to use absolute file paths in the `bison`
88-
command-line invocations. By default all file paths are added to `bison` as
89-
relative to the working directory. Using relative paths is convenient when
90-
line directives (`#line ...`) are generated in the output files to not show
91-
the full path on the disk, if file is committed to Git repository.
86+
command-line invocations. By default all file paths are added as relative to
87+
the working directory. Using relative paths is convenient when line directives
88+
(`#line ...`) are generated in the output files committed to Git repository.
9289

9390
When this option is enabled:
9491

@@ -119,7 +116,7 @@ These variables can be set before using this module to configure behavior:
119116

120117
* `PHP_BISON_WORKING_DIRECTORY` - Set the default global working directory
121118
for all `php_bison()` invocations in the directory scope where the
122-
`WORKING_DIRECTORY <dir>` option is not set.
119+
`WORKING_DIRECTORY <directory>` option is not set.
123120

124121
## Examples
125122

@@ -159,9 +156,9 @@ php_bison(foo foo.y foo.c OPTIONS $<$<CONFIG:Debug>:--debug> --yacc)
159156
# bison --yacc foo.y --output foo.c
160157
```
161158

162-
### Custom target usage
159+
### Target usage
163160

164-
To specify dependencies with the custom target created by `php_bison()`:
161+
Target created by `php_bison()` can be used to specify additional dependencies:
165162

166163
```cmake
167164
# CMakeLists.txt
@@ -172,29 +169,20 @@ php_bison(foo_parser parser.y parser.c)
172169
add_dependencies(some_target foo_parser)
173170
```
174171

175-
Or to run only the specific `foo_parser` target, which generates the
176-
parser-related files:
172+
Running only the `foo_parser` target to generate the parser-related files:
177173

178174
```sh
179175
cmake --build <dir> --target foo_parser
180176
```
181177

182178
### Module configuration
183179

184-
To specify minimum required Bison version other than the module's default,
185-
`find_package(BISON)` can be called before the `php_bison()`:
180+
To specify different minimum required Bison version than the module's default,
181+
the `find_package(BISON)` can be called before `php_bison()`:
186182

187183
```cmake
188-
find_package(BISON 3.7)
189-
include(PHP/Bison)
190-
php_bison(...)
191-
```
192-
193-
Set `PHP_BISON_*` variables to override module default configuration:
194-
195-
```cmake
196-
set(PHP_BISON_VERSION_DOWNLOAD 3.7)
197184
include(PHP/Bison)
185+
find_package(BISON 3.7)
198186
php_bison(...)
199187
```
200188
#]=============================================================================]
@@ -204,12 +192,12 @@ php_bison(...)
204192
################################################################################
205193

206194
macro(_php_bison_config)
207-
# Minimum required bison version.
195+
# Minimum required Bison version.
208196
if(NOT PHP_BISON_VERSION)
209197
set(PHP_BISON_VERSION 3.0.0)
210198
endif()
211199

212-
# If bison is not found on the system, set which version to download.
200+
# If Bison is not found on the system, set which version to download.
213201
if(NOT PHP_BISON_VERSION_DOWNLOAD)
214202
set(PHP_BISON_VERSION_DOWNLOAD 3.8.2)
215203
endif()
@@ -354,7 +342,7 @@ function(php_bison name input output)
354342
BASE_DIRECTORY ${CMAKE_BINARY_DIR}
355343
OUTPUT_VARIABLE relativePath
356344
)
357-
set(message "[bison] Generating ${relativePath} with Bison ${BISON_VERSION}")
345+
set(message "[Bison] Generating ${relativePath} with Bison ${BISON_VERSION}")
358346

359347
if(CMAKE_SCRIPT_MODE_FILE)
360348
message(STATUS "${message}")
@@ -632,7 +620,6 @@ function(_php_bison_download)
632620
LOG_INSTALL TRUE
633621
)
634622

635-
# Set bison executable.
636623
ExternalProject_Get_Property(bison INSTALL_DIR)
637624
set_property(CACHE BISON_EXECUTABLE PROPERTY VALUE ${INSTALL_DIR}/bin/bison)
638625

0 commit comments

Comments
 (0)