summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-01-10 16:04:06 -0800
committerKonstantin Käfer <mail@kkaefer.com>2018-01-24 08:35:31 -0800
commite7e6cffcf354cc3d2427103b628f924bb39d7fb0 (patch)
tree0622789f5a19ecb22b4ce1195ae769f45fa04998 /scripts
parent13d27c700e4b0590c4f1c365bfa36cf2a07c437d (diff)
downloadqtlocation-mapboxgl-e7e6cffcf354cc3d2427103b628f924bb39d7fb0.tar.gz
[build] convert CMake file list generation code to JavaScript
Bash sorting is weird...
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate-benchmark-files.sh20
-rwxr-xr-xscripts/generate-cmake-files.js32
-rwxr-xr-xscripts/generate-core-files.sh20
-rwxr-xr-xscripts/generate-test-files.sh20
4 files changed, 32 insertions, 60 deletions
diff --git a/scripts/generate-benchmark-files.sh b/scripts/generate-benchmark-files.sh
deleted file mode 100755
index 0fb274cf31..0000000000
--- a/scripts/generate-benchmark-files.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-set -o pipefail
-
-echo "# Do not edit. Regenerate this with ./scripts/generate-benchmark-files.sh" > cmake/benchmark-files.cmake
-echo "" >> cmake/benchmark-files.cmake
-echo "set(MBGL_BENCHMARK_FILES" >> cmake/benchmark-files.cmake
-PREFIX=
-for FILE in $(git ls-files "benchmark/*.hpp" "benchmark/*.cpp" "benchmark/*.h" "benchmark/*.c" | sort) ; do
- CURRENT_PREFIX=$(dirname ${FILE#benchmark/})
- if [ "${PREFIX}" != "${CURRENT_PREFIX}" ]; then
- if [ ! -z "${PREFIX}" ]; then echo "" >> cmake/benchmark-files.cmake ; fi
- echo " # ${CURRENT_PREFIX}" >> cmake/benchmark-files.cmake
- PREFIX="${CURRENT_PREFIX}"
- fi
- echo " ${FILE}" >> cmake/benchmark-files.cmake
-done
-echo ")" >> cmake/benchmark-files.cmake
-git diff cmake/benchmark-files.cmake
diff --git a/scripts/generate-cmake-files.js b/scripts/generate-cmake-files.js
new file mode 100755
index 0000000000..4b6a8b8672
--- /dev/null
+++ b/scripts/generate-cmake-files.js
@@ -0,0 +1,32 @@
+#!/usr/bin/env node
+
+const child_process = require('child_process');
+const fs = require('fs');
+const ejs = require('ejs');
+
+require('./style-code');
+
+function generateCMakeListFile(name, regex, patterns) {
+ const files = child_process.execSync(`git ls-files ${patterns.map((p) => '"' + p + '"').join(' ')}`).toString().trim().split('\n');
+ var groups = {};
+ for (const file of files) {
+ const match = file.match(regex);
+ const group = match[1] || name;
+ if (!groups[group]) {
+ groups[group] = [];
+ }
+ groups[group].push(file);
+ }
+
+ const fileListCmake = ejs.compile(fs.readFileSync('cmake/files.cmake.ejs', 'utf8'), {strict: true});
+ writeIfModified(`cmake/${name}-files.cmake`, fileListCmake({ name: name, groups: groups }));
+}
+
+generateCMakeListFile('core', /^(?:src|include)\/(?:mbgl\/)?(.+)\/[^\/]+$/,
+ [ 'include/*.hpp', 'include/*.h', 'src/*.hpp', 'src/*.cpp', 'src/*.h', 'src/*.c' ]);
+
+generateCMakeListFile('benchmark', /^benchmark\/(?:(?:src|include)\/)?(?:mbgl\/)?(?:(.+)\/)?[^\/]+$/,
+ [ 'benchmark/*.hpp', 'benchmark/*.cpp', 'benchmark/*.h', 'benchmark/*.c' ]);
+
+generateCMakeListFile('test', /^test\/(?:(?:src|include)\/)?(?:mbgl\/)?(?:(.+)\/)?[^\/]+$/,
+ [ 'test/*.hpp', 'test/*.cpp', 'test/*.h', 'test/*.c' ]);
diff --git a/scripts/generate-core-files.sh b/scripts/generate-core-files.sh
deleted file mode 100755
index 27754306e1..0000000000
--- a/scripts/generate-core-files.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-set -o pipefail
-
-echo "# Do not edit. Regenerate this with ./scripts/generate-core-files.sh" > cmake/core-files.cmake
-echo "" >> cmake/core-files.cmake
-echo "set(MBGL_CORE_FILES" >> cmake/core-files.cmake
-PREFIX=
-for FILE in $(git ls-files "include/*.hpp" "include/*.h" "src/*.hpp" "src/*.cpp" "src/*.h" "src/*.c" | perl -p -e "s/^((src|include)\/(mbgl\/)?(.+)\/\w+\.\w+)$/\$4#\$1/g" | sort) ; do
- CURRENT_PREFIX="${FILE%#*}"
- if [ "${PREFIX}" != "${CURRENT_PREFIX}" ]; then
- if [ ! -z "${PREFIX}" ]; then echo "" >> cmake/core-files.cmake ; fi
- echo " # ${CURRENT_PREFIX}" >> cmake/core-files.cmake
- PREFIX="${CURRENT_PREFIX}"
- fi
- echo " ${FILE#*#}" >> cmake/core-files.cmake
-done
-echo ")" >> cmake/core-files.cmake
-git diff cmake/core-files.cmake
diff --git a/scripts/generate-test-files.sh b/scripts/generate-test-files.sh
deleted file mode 100755
index 5f507d3edf..0000000000
--- a/scripts/generate-test-files.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-set -o pipefail
-
-echo "# Do not edit. Regenerate this with ./scripts/generate-test-files.sh" > cmake/test-files.cmake
-echo "" >> cmake/test-files.cmake
-echo "set(MBGL_TEST_FILES" >> cmake/test-files.cmake
-PREFIX=
-for FILE in $(git ls-files "test/*.hpp" "test/*.cpp" "test/*.h" "test/*.c" | sort) ; do
- CURRENT_PREFIX=$(dirname ${FILE#test/})
- if [ "${PREFIX}" != "${CURRENT_PREFIX}" ]; then
- if [ ! -z "${PREFIX}" ]; then echo "" >> cmake/test-files.cmake ; fi
- echo " # ${CURRENT_PREFIX}" >> cmake/test-files.cmake
- PREFIX="${CURRENT_PREFIX}"
- fi
- echo " ${FILE}" >> cmake/test-files.cmake
-done
-echo ")" >> cmake/test-files.cmake
-git diff cmake/test-files.cmake