Skip to content

Commit 76fb51c

Browse files
committed
Simplify make-docs script
1 parent 4d923a1 commit 76fb51c

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

bin/make-docs.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ function generateModuleDocs(
4040
string $file,
4141
string $namespace,
4242
string $destination,
43-
string $url,
4443
): void {
4544
if (!file_exists($file)) {
4645
return;
@@ -56,9 +55,11 @@ function generateModuleDocs(
5655
$moduleName = basename($file, '.cmake');
5756
$content = $matches[1];
5857

58+
$relativeFilename = trim(str_replace(realpath(__DIR__ . '/../cmake'), '', realpath($file)), '/');
59+
$url = 'https://github.com/petk/php-build-system/blob/master/cmake/' . $relativeFilename;
60+
5961
$markdown = "<!-- This is auto-generated file. -->\n";
60-
$markdown .= "# $namespace" . "$moduleName\n\n";
61-
$markdown .= "* Module source code: [$moduleName.cmake]($url)\n\n";
62+
$markdown .= "* Source code: [$relativeFilename]($url)\n\n";
6263
$markdown .= $content . "\n";
6364

6465
if ($namespace) {
@@ -92,12 +93,14 @@ function generateModuleDocs(
9293
the configuration phase. For example:
9394
9495
```sh
95-
cmake -S <source-dir> -B <build-dir> -DCMAKE_PREFIX_PATH="/opt/$findPackageName;/opt/some-other-package"
96+
cmake -S <source-dir> \
97+
-B <build-dir> \
98+
-DCMAKE_PREFIX_PATH="/opt/$findPackageName;/opt/some-other-package"
9699
# or
97100
cmake -S <source-dir> \
98-
-B <build-dir> \
99-
-D{$findPackageUpper}_ROOT=/opt/$findPackageName \
100-
-DSOMEOTHERPACKAGE_ROOT=/opt/some-other-package
101+
-B <build-dir> \
102+
-D{$findPackageUpper}_ROOT=/opt/$findPackageName \
103+
-DSOMEOTHERPACKAGE_ROOT=/opt/some-other-package
101104
```
102105
EOT;
103106
} else {
@@ -202,27 +205,24 @@ function generateDocs(
202205
}
203206
}
204207

205-
foreach ($files as $module) {
206-
$relativeFilename = trim(str_replace($baseDir, '', $module), '/');
207-
208-
if (str_starts_with($module, $baseDir . '/cmake/modules/')) {
209-
$namespace = trim(str_replace($baseDir . '/cmake/modules', '', dirname($module)), '/');
208+
foreach ($files as $file) {
209+
if (str_starts_with($file, $baseDir . '/cmake/modules/')) {
210+
$namespace = trim(str_replace($baseDir . '/cmake/modules', '', dirname($file)), '/');
210211
$namespace = ('' == $namespace) ? '' : $namespace . '/';
211212
$subdir = $namespace;
212213
} else {
213214
$namespace = '';
214-
if ('FindPHP.cmake' === basename($module)) {
215+
if ('FindPHP.cmake' === basename($file)) {
215216
$subdir = '';
216217
} else {
217-
$subdir = basename(dirname($module, 2));
218+
$subdir = basename(dirname($file, 2));
218219
}
219220
}
220221

221222
generateModuleDocs(
222-
$module,
223+
$file,
223224
$namespace,
224225
__DIR__ . '/../docs/cmake/modules/' . $subdir,
225-
'https://github.com/petk/php-build-system/blob/master/cmake/' . $relativeFilename,
226226
);
227227
}
228228

0 commit comments

Comments
 (0)