[build] convert CMake file list generation code to JavaScript

Bash sorting is weird...
This commit is contained in:
Konstantin Käfer
2018-01-10 16:04:06 -08:00
parent 13d27c700e
commit e7e6cffcf3
8 changed files with 100 additions and 120 deletions

View File

@@ -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

32
scripts/generate-cmake-files.js Executable file
View File

@@ -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' ]);

View File

@@ -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

View File

@@ -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