Skip to content

Commit 6ac4f2b

Browse files
committed
Add script for regenerating ext/standard/credits_*.h headers
1 parent 1f8dda9 commit 6ac4f2b

File tree

6 files changed

+108
-3
lines changed

6 files changed

+108
-3
lines changed

bin/check-cmake.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ function checkAll(array $options): int
708708
{
709709
$status = 0;
710710

711-
output($options['script'] . ': Working tree ' . realpath($options['path']));
711+
output($options['script'] . ': Working tree ' . $options['path']);
712712

713713
output($options['script'] . ': Checking CMake modules');
714714
$allCMakeFiles = getAllCMakeFiles($options['path']);

bin/init.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Usage:
1616

1717
cmake_minimum_required(VERSION 3.25)
1818

19+
if(NOT CMAKE_SCRIPT_MODE_FILE)
20+
message(FATAL_ERROR "This is a command-line script.")
21+
endif()
22+
1923
# The PHP MAJOR.MINOR version currently in development (the master branch).
2024
set(PHP_DEVELOPMENT_VERSION "8.5")
2125

bin/php.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Usage examples:
3535

3636
cmake_minimum_required(VERSION 3.25)
3737

38+
if(NOT CMAKE_SCRIPT_MODE_FILE)
39+
message(FATAL_ERROR "This is a command-line script.")
40+
endif()
41+
3842
################################################################################
3943
# Set default variables.
4044
################################################################################
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env -S cmake -P
2+
#
3+
# Command-line script to regenerate the ext/standard/credits_*.h headers from
4+
# CREDITS files.
5+
#
6+
# Run with: `cmake -P cmake/scripts/GenerateCredits.cmake`
7+
8+
if(NOT CMAKE_SCRIPT_MODE_FILE)
9+
message(FATAL_ERROR "This is a command-line script.")
10+
endif()
11+
12+
set(PHP_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../)
13+
14+
if(NOT EXISTS ${PHP_SOURCE_DIR}/ext/standard/credits.h)
15+
message(FATAL_ERROR "This script should be run inside the php-src repository")
16+
endif()
17+
18+
set(template [[
19+
/*
20+
DO NOT EDIT THIS FILE!
21+
22+
it has been automatically created by scripts/dev/credits from
23+
the information found in the various ext/.../CREDITS and
24+
sapi/.../CREDITS files
25+
26+
if you want to change an entry you have to edit the appropriate
27+
CREDITS file instead
28+
29+
*/
30+
31+
]])
32+
33+
file(GLOB credits ${PHP_SOURCE_DIR}/*/*/CREDITS)
34+
35+
foreach(credit ${credits})
36+
cmake_path(GET credit PARENT_PATH parent)
37+
cmake_path(GET parent PARENT_PATH parent)
38+
cmake_path(GET parent FILENAME dir)
39+
40+
list(APPEND dirs ${dir})
41+
file(STRINGS ${credit} lines ENCODING UTF-8)
42+
list(GET lines 0 title)
43+
list(GET lines 1 authors)
44+
list(APPEND ${dir}_credits "CREDIT_LINE(\"${title}\", \"${authors}\")")
45+
endforeach()
46+
47+
list(REMOVE_DUPLICATES dirs)
48+
49+
foreach(dir ${dirs})
50+
list(SORT ${dir}_credits CASE INSENSITIVE)
51+
list(JOIN ${dir}_credits ";\n" credits)
52+
set(content "${template}${credits};\n")
53+
54+
if(EXISTS ${PHP_SOURCE_DIR}/ext/standard/credits_${dir}.h)
55+
file(READ ${PHP_SOURCE_DIR}/ext/standard/credits_${dir}.h current)
56+
if(content STREQUAL "${current}")
57+
continue()
58+
endif()
59+
endif()
60+
61+
file(WRITE ${PHP_SOURCE_DIR}/ext/standard/credits_${dir}.h "${content}")
62+
message("Updated ext/standard/credits_${dir}.h")
63+
endforeach()

cmake/ext/standard/CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,41 @@ check_symbol_exists(
433433
HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR_NP
434434
)
435435

436+
################################################################################
437+
# Regenerate credits_*.h files.
438+
################################################################################
439+
440+
block()
441+
file(GLOB credits ${PHP_SOURCE_DIR}/*/*/CREDITS)
442+
443+
# The CODEGEN keyword adds the custom command to a global 'codegen' target.
444+
set(codegen)
445+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.31)
446+
set(codegen CODEGEN)
447+
endif()
448+
449+
add_custom_command(
450+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/php_credits.timestamp
451+
DEPENDS ${credits}
452+
COMMAND
453+
${CMAKE_COMMAND}
454+
-E touch ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/php_credits.timestamp
455+
COMMAND
456+
${CMAKE_COMMAND} -P ${PHP_SOURCE_DIR}/cmake/scripts/GenerateCredits.cmake
457+
COMMENT "Regenerating ext/standard/credits_*.h"
458+
VERBATIM
459+
${codegen}
460+
)
461+
462+
add_custom_target(
463+
php_standard_credits
464+
DEPENDS
465+
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/php_credits.timestamp
466+
)
467+
468+
add_dependencies(php_standard php_standard_credits)
469+
endblock()
470+
436471
# TODO: Check whether to enable the chroot() function by checking which SAPI is
437472
# being built.
438473
set(ENABLE_CHROOT_FUNC 1 CACHE INTERNAL "Whether to enable chroot() function")

cmake/scripts/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ block()
2121
)
2222
endblock()
2323

24+
# The php-config and phpize scripts.
2425
block()
2526
find_program(
2627
SED_EXECUTABLE
@@ -37,7 +38,6 @@ block()
3738
set(SED /usr/bin/sed)
3839
endif()
3940

40-
# The php-config script.
4141
message(STATUS "Creating scripts/php-config")
4242

4343
# Replace the upstream php-config script hardcoded php include directory to a
@@ -87,7 +87,6 @@ block()
8787
RENAME ${PHP_PROGRAM_PREFIX}php-config${PHP_PROGRAM_SUFFIX}
8888
)
8989

90-
# The phpize script.
9190
message(STATUS "Creating scripts/phpize")
9291

9392
# Replace the upstream phpize script hardcoded php include directory to a

0 commit comments

Comments
 (0)