Skip to content

Commit 845b500

Browse files
committed
Merge branch 'PHP-8.4'
2 parents 7348db6 + e7dda00 commit 845b500

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

bin/check-cmake.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,52 @@ function checkCMakeSet(Iterator $files): int
380380
return $status;
381381
};
382382

383+
/**
384+
* Check for obsolete usages of:
385+
* else(<condition>)
386+
* endif(<condition>)
387+
* endforeach(<loop-var>)
388+
* endwhile(<condition>)
389+
* endfunction(<name>)
390+
* endmacro(<name>)
391+
*/
392+
function checkCMakeObsoleteEndCommands(Iterator $files): int
393+
{
394+
$status = 0;
395+
396+
$commands = [
397+
'else',
398+
'endif',
399+
'endforeach',
400+
'endwhile',
401+
'endfunction',
402+
'endmacro',
403+
];
404+
405+
foreach ($files as $file) {
406+
$content = getCMakeCode($file);
407+
408+
foreach ($commands as $command) {
409+
preg_match_all(
410+
'/^[ \t]*(' . $command . ')[ \t]*\((.+)\)/mi',
411+
$content,
412+
$matches,
413+
PREG_SET_ORDER,
414+
);
415+
416+
foreach ($matches as $match) {
417+
$foundCommand = $match[1] ?? '';
418+
$foundArgument = $match[2] ?? '';
419+
420+
$status = 1;
421+
output("E: Replace $foundCommand($foundArgument) with $command()\n in $file\n");
422+
}
423+
}
424+
}
425+
426+
return $status;
427+
}
428+
383429
/**
384430
* Find all local Find* modules in the project.
385431
*/
@@ -673,6 +719,9 @@ function checkAll(array $options): int
673719
$newStatus = checkCMakeSet($allCMakeFiles);
674720
$status = (0 === $status) ? $newStatus : $status;
675721

722+
$newStatus = checkCMakeObsoleteEndCommands($allCMakeFiles);
723+
$status = (0 === $status) ? $newStatus : $status;
724+
676725
$findModules = getFindModules($options['path'] . '/cmake/cmake/modules');
677726
$newStatus = checkFindModules($findModules, $allCMakeFiles);
678727
$status = (0 === $status) ? $newStatus : $status;

docs/cmake/cmake-code-style.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,9 @@ On the contrary, variable names are case-sensitive.
126126
127127
### 2.1. End commands
128128
129-
To make the code easier to read, use empty commands for `endif()`,
130-
`endfunction()`, `endforeach()`, `endmacro()`, `endwhile()`, `else()`, and
131-
similar end commands. The optional argument in end command is legacy CMake and
132-
not recommended anymore.
129+
To make the code easier to read, use empty commands for `else()`, `endif()`,
130+
`endforeach()`, `endwhile()`, `endfunction()`, and `endmacro()`. The optional
131+
legacy argument in these commands is not recommended anymore.
133132
134133
For example, do this:
135134

0 commit comments

Comments
 (0)