Skip to content

Commit 2db71a1

Browse files
committed
Add various improvements
- Refactor patches and add a new helper script to update patch files in the local clone instead of a separate Git repository - Fix ndbm and dbm finder modules further with checking whether the default libraries (C) has the requested package - Fix failing dba tests for ndbm and dbm handlers via patch - Refactored the code checker script a bit to not require passing a path as it is not so clear what this path should be
1 parent 156d8ff commit 2db71a1

32 files changed

+923
-300
lines changed

.github/workflows/check-cmake.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
mv normalizator.phar /usr/local/bin/normalizator
3535
3636
- name: Run checks
37-
run: ./bin/check-cmake.php cmake
37+
run: ./bin/check-cmake.php
3838

3939
- name: Run PHP CS Fixer
4040
run: php-cs-fixer check --diff --rules=@Symfony,@PER-CS --using-cache=no -- bin

bin/check-cmake.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function usage(string $script): string
2525
includes or similar.
2626
2727
SYNOPSIS:
28-
$script [<options>] <path>
28+
$script [<options>] [<path>]
2929
3030
OPTIONS:
3131
-h, --help Display this help and exit.
@@ -105,10 +105,6 @@ function options(array $overrides = [], array $argv = []): array
105105
}
106106
}
107107

108-
if (count($argv) < 2) {
109-
$options['help'] = true;
110-
}
111-
112108
foreach (array_slice($argv, $optionsIndex) as $file) {
113109
if (file_exists($file) && $file !== $argv[0]) {
114110
$options['path'] = realpath($file);
@@ -117,6 +113,10 @@ function options(array $overrides = [], array $argv = []): array
117113
}
118114
}
119115

116+
if (array_key_exists('path', $options) && $options['path'] === null) {
117+
$options['path'] = realpath(__DIR__ . '/..');
118+
}
119+
120120
validateOptions($options);
121121

122122
return $options;
@@ -139,7 +139,9 @@ function validateOptions(array $options): void
139139
|| null === $options['path']
140140
|| !file_exists($options['path'])
141141
) {
142-
output('Path argument missing');
142+
output('Error: Path not found');
143+
output();
144+
output('Usage:');
143145
output();
144146
output(usage($options['script']));
145147
exit(1);
@@ -712,16 +714,16 @@ function checkAll(array $options): int
712714
output($options['script'] . ': Working tree ' . $options['path']);
713715

714716
output($options['script'] . ': Checking CMake modules');
715-
$allCMakeFiles = getAllCMakeFiles($options['path']);
717+
$allCMakeFiles = getAllCMakeFiles($options['path'] . '/cmake');
716718

717719
$projectModules = getProjectModules();
718720
$status = checkCMakeFiles($allCMakeFiles, $projectModules);
719721

720-
$findModules = getFindModules($options['path'] . '/cmake/modules');
722+
$findModules = getFindModules($options['path'] . '/cmake/cmake/modules');
721723
$newStatus = checkFindModules($findModules, $allCMakeFiles);
722724
$status = (0 === $status) ? $newStatus : $status;
723725

724-
$modules = getModules($options['path'] . '/cmake/modules');
726+
$modules = getModules($options['path'] . '/cmake/cmake/modules');
725727
$newStatus = checkModules($modules, $allCMakeFiles);
726728
$status = (0 === $status) ? $newStatus : $status;
727729

bin/make-patches.sh

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

bin/update-patches.sh

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/sh
2+
#
3+
# Script for updating php-src patches.
4+
5+
if test -z "$REPO"; then
6+
REPO="php-src"
7+
fi
8+
9+
# A list of supported PHP versions.
10+
phpVersions="8.3 8.4 8.5"
11+
12+
# The PHP MAJOR.MINOR version currently in development (the master branch).
13+
phpVersionDev="8.5"
14+
15+
# Temporary Git branch for applying patches and rebasing the branch.
16+
temporaryBranch=cmake-patching
17+
18+
# Go to project root.
19+
cd $(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd -P)
20+
21+
while test $# -gt 0; do
22+
if test "$1" = "-h" || test "$1" = "--help"; then
23+
cat << HELP
24+
Update php-src patches
25+
26+
A simple helper that updates patches needed to use CMake with php-src source
27+
code.
28+
29+
SYNOPSIS:
30+
$0 [<options>]
31+
32+
OPTIONS:
33+
-h, --help Display this help and exit.
34+
35+
ENVIRONMENT VARIABLES:
36+
The following optional variables are supported:
37+
38+
REPO Overrides the location to the locally cloned php-src repository.
39+
REPO=php-src-repo $0
40+
HELP
41+
exit 0
42+
fi
43+
44+
shift
45+
done
46+
47+
# Check requirements.
48+
which=$(which which 2>/dev/null)
49+
git=$(which git 2>/dev/null)
50+
51+
if test -z "$which"; then
52+
echo "update-patches.sh: The 'which' command not found." >&2
53+
echo " Please install coreutils." >&2
54+
exit 1
55+
fi
56+
57+
if test -z "$git"; then
58+
echo "update-patches.sh: The 'git' command not found." >&2
59+
echo " Please install Git:" >&2
60+
echo " https://git-scm.com" >&2
61+
exit 1
62+
fi
63+
64+
# Clone a fresh latest php-src repository.
65+
if test ! -d "${REPO}"; then
66+
echo "To use this tool you need php-src Git repository."
67+
printf "Do you want to clone it now (y/N)?"
68+
read answer
69+
70+
if test "$answer" != "${answer#[Yy]}"; then
71+
echo "Cloning github.com/php/php-src. This will take a little while."
72+
"$git" clone https://github.com/php/php-src ${REPO}
73+
else
74+
exit 1
75+
fi
76+
fi
77+
78+
# Make sure we're in the php-src repository.
79+
cd ${REPO}
80+
if test ! -f "main/php_version.h" \
81+
|| test ! -f "php.ini-development"
82+
then
83+
echo "Git repository doesn't seem to be php-src." >&2
84+
exit 1
85+
fi
86+
87+
# Check if there is existing temporary Git branch to not override.
88+
if test -n "$(git show-ref refs/heads/${temporaryBranch})"; then
89+
echo "E: There is existing ${temporaryBranch} branch." >&2
90+
echo "E: Remove or rename ${temporaryBranch} branch." >&2
91+
exit 1
92+
fi
93+
94+
for php in $phpVersions; do
95+
if test "$php" = "$phpVersionDev"; then
96+
branch=master
97+
else
98+
branch=PHP-$php
99+
fi
100+
101+
# Check if php-src branch exists.
102+
if test -z "$(git show-ref refs/heads/${branch})"; then
103+
echo "E: Branch ${branch} is missing." >&2
104+
exit 1
105+
fi
106+
107+
"$git" reset --hard
108+
"$git" clean -dffx
109+
"$git" checkout ${branch}
110+
"$git" pull --rebase
111+
112+
for patch in "$PWD/../patches/$php"/*.patch; do
113+
fileName=patches/$php/$(basename "$patch")
114+
echo "-> Updating $fileName"
115+
116+
"$git" checkout -b ${temporaryBranch}
117+
"$git" am -3 $patch
118+
119+
if test "x$?" != "x0"; then
120+
echo "E: Patch ${patch} needs manual resolution." >&2
121+
echo " Go to php-src and resolve conflicts manually." >&2
122+
exit 1
123+
fi
124+
125+
"$git" --no-pager format-patch -1 ${temporaryBranch} \
126+
--stdout \
127+
--no-signature \
128+
--subject-prefix="" \
129+
> ${patch}
130+
131+
# Remove redundant patch header information.
132+
sed -i '/^From /d' ${patch}
133+
sed -i '/^Date: /d' ${patch}
134+
135+
# Replace email if needed.
136+
#sed -i 's/^From: .*/From: ElePHPant <[email protected]>/' ${patch}
137+
138+
"$git" checkout ${branch}
139+
"$git" branch -D ${temporaryBranch}
140+
done
141+
done

cmake/cmake/modules/FindACL.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ endif()
114114

115115
set(_reason "")
116116

117-
# If no compiler is loaded, ACL in C library can't be checked anyway.
117+
# If no compiler is loaded C library can't be checked anyway.
118118
if(NOT CMAKE_C_COMPILER_LOADED AND NOT CMAKE_CXX_COMPILER_LOADED)
119119
set(ACL_IS_BUILT_IN FALSE)
120120
endif()

cmake/cmake/modules/FindCrypt.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ endif()
6464

6565
set(_reason "")
6666

67-
# If no compiler is loaded, Crypt in C library can't be checked anyway.
67+
# If no compiler is loaded C library can't be checked anyway.
6868
if(NOT CMAKE_C_COMPILER_LOADED AND NOT CMAKE_CXX_COMPILER_LOADED)
6969
set(Crypt_IS_BUILT_IN FALSE)
7070
endif()

0 commit comments

Comments
 (0)