Skip to content

Commit 1ed6b9c

Browse files
committed
update based on vtquery
1 parent 4c2f13c commit 1ed6b9c

File tree

6 files changed

+46
-84
lines changed

6 files changed

+46
-84
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ matrix:
111111
# Overrides `script` to publish coverage data to codecov
112112
before_script:
113113
- npm test
114-
- mason install llvm-cov ${MASON_LLVM_RELEASE}
115-
- mason link llvm-cov ${MASON_LLVM_RELEASE}
114+
- ./node_modules/.bin/mason-js install llvm-cov=${MASON_LLVM_RELEASE} --type=compiled
115+
- ./node_modules/.bin/mason-js link llvm-cov=${MASON_LLVM_RELEASE} --type=compiled
116116
- which llvm-cov
117117
- curl -S -f https://codecov.io/bash -o codecov
118118
- chmod +x codecov

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ release: node_modules mason_packages/.link
2020
V=1 ./node_modules/.bin/node-pre-gyp configure build --error_on_warnings=$(WERROR) --loglevel=error
2121
@echo "run 'make clean' for full rebuild"
2222

23-
debug: node_modules mason_packages/.link
23+
debug: node_modules mason_packages/.link/include
2424
V=1 ./node_modules/.bin/node-pre-gyp configure build --error_on_warnings=$(WERROR) --loglevel=error --debug
2525
@echo "run 'make clean' for full rebuild"
2626

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"scripts": {
1212
"test": "tape test/*.test.js",
1313
"prepublishOnly": "npm ls",
14-
"install": "mason-js install && node-pre-gyp install --fallback-to-build",
14+
"mason": "mason-js install && mason-js link",
15+
"install": "npm run mason && node-pre-gyp install --fallback-to-build",
1516
"docs": "documentation build src/standalone_async/*.cpp src/standalone/*.cpp src/object_sync/*.cpp src/object_async/*.cpp --polyglot -f md -o API.md"
1617
},
1718
"author": "Mapbox",

scripts/clang-format.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,29 @@ Return `1` if there are files to be formatted, and automatically formats them.
1212
Returns `0` if everything looks properly formatted.
1313
1414
'
15-
# Set up the environment by installing mason and clang++
16-
# See https://github.com/mapbox/node-cpp-skel/blob/master/docs/extended-tour.md#configuration-files
17-
./scripts/setup.sh --config local.env
15+
16+
PATH_TO_FORMAT_SCRIPT="$(pwd)/mason_packages/.link/bin/clang-format"
17+
18+
# to speed up re-runs, only re-create environment if needed
19+
if [[ ! -f local.env ]] || [[ ! -f ${PATH_TO_FORMAT_SCRIPT} ]]; then
20+
# automatically setup environment
21+
./scripts/setup.sh --config local.env
22+
fi
23+
24+
# source the environment
1825
source local.env
1926

20-
# Add clang-format as a dep
21-
mason install clang-format ${MASON_LLVM_RELEASE}
22-
mason link clang-format ${MASON_LLVM_RELEASE}
27+
# to speed up re-runs, only install clang-format if needed
28+
if [[ ! -f ${PATH_TO_FORMAT_SCRIPT} ]]; then
29+
# The MASON_LLVM_RELEASE variable comes from `local.env`
30+
node_modules/.bin/mason-js install clang-format=${MASON_LLVM_RELEASE} --type=compiled
31+
node_modules/.bin/mason-js link clang-format=${MASON_LLVM_RELEASE} --type=compiled
32+
# We link the tools to make it easy to know ${PATH_TO_FORMAT_SCRIPT}
33+
fi
2334

2435
# Run clang-format on all cpp and hpp files in the /src directory
2536
find src/ -type f -name '*.hpp' -o -name '*.cpp' \
26-
| xargs -I{} clang-format -i -style=file {}
37+
| xargs -I{} ${PATH_TO_FORMAT_SCRIPT} -i -style=file {}
2738

2839
# Print list of modified files
2940
dirty=$(git ls-files --modified src/)

scripts/clang-tidy.sh

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,26 @@ set -o pipefail
66
# https://clang.llvm.org/extra/clang-tidy/
77

88
: '
9-
109
Runs clang-tidy on the code in src/
11-
1210
Return `1` if there are files automatically fixed by clang-tidy.
13-
1411
Returns `0` if no fixes by clang-tidy.
15-
1612
TODO: should also return non-zero if clang-tidy emits warnings
1713
or errors about things it cannot automatically fix. However I cannot
1814
figure out how to get this working yet as it seems that clang-tidy
1915
always returns 0 even on errors.
20-
2116
'
2217

18+
PATH_TO_CLANG_TIDY_SCRIPT="$(pwd)/mason_packages/.link/share/run-clang-tidy.py"
19+
2320
# to speed up re-runs, only re-create environment if needed
24-
if [[ ! -f local.env ]]; then
21+
if [[ ! -f local.env ]] || [[ ! -f ${PATH_TO_CLANG_TIDY_SCRIPT} ]]; then
2522
# automatically setup environment
2623
./scripts/setup.sh --config local.env
2724
fi
2825

2926
# source the environment
3027
source local.env
3128

32-
PATH_TO_CLANG_TIDY_SCRIPT="$(pwd)/mason_packages/.link/share/run-clang-tidy.py"
33-
34-
# to speed up re-runs, only install clang-tidy if needed
35-
if [[ ! -f PATH_TO_CLANG_TIDY_SCRIPT ]]; then
36-
# The MASON_LLVM_RELEASE variable comes from `local.env`
37-
mason install clang-tidy ${MASON_LLVM_RELEASE}
38-
# We link the tools to make it easy to know ${PATH_TO_CLANG_TIDY_SCRIPT}
39-
mason link clang-tidy ${MASON_LLVM_RELEASE}
40-
fi
41-
4229
# build the compile_commands.json file if it does not exist
4330
if [[ ! -f build/compile_commands.json ]]; then
4431
# We need to clean otherwise when we make the project
@@ -53,6 +40,14 @@ if [[ ! -f build/compile_commands.json ]]; then
5340
make | scripts/generate_compile_commands.py > build/compile_commands.json
5441
fi
5542

43+
# to speed up re-runs, only install clang-tidy if needed
44+
if [[ ! -f ${PATH_TO_CLANG_TIDY_SCRIPT} ]]; then
45+
# The MASON_LLVM_RELEASE variable comes from `local.env`
46+
node_modules/.bin/mason-js install clang-tidy=${MASON_LLVM_RELEASE} --type=compiled
47+
node_modules/.bin/mason-js link clang-tidy=${MASON_LLVM_RELEASE} --type=compiled
48+
# We link the tools to make it easy to know ${PATH_TO_CLANG_TIDY_SCRIPT}
49+
fi
50+
5651
# change into the build directory so that clang-tidy can find the files
5752
# at the right paths (since this is where the actual build happens)
5853
cd build
@@ -70,4 +65,3 @@ if [[ $dirty ]]; then
7065
else
7166
exit 0
7267
fi
73-

scripts/setup.sh

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,7 @@
33
set -eu
44
set -o pipefail
55

6-
export MASON_RELEASE="${MASON_RELEASE:-v0.14.1}"
7-
export MASON_LLVM_RELEASE="${MASON_LLVM_RELEASE:-4.0.1}"
8-
9-
PLATFORM=$(uname | tr A-Z a-z)
10-
if [[ ${PLATFORM} == 'darwin' ]]; then
11-
PLATFORM="osx"
12-
fi
13-
14-
MASON_URL="https://s3.amazonaws.com/mason-binaries/${PLATFORM}-$(uname -m)"
15-
16-
llvm_toolchain_dir="$(pwd)/.toolchain"
6+
export MASON_LLVM_RELEASE="${MASON_LLVM_RELEASE:-5.0.0}"
177

188
function run() {
199
local config=${1}
@@ -23,57 +13,23 @@ function run() {
2313
echo 'shell_session_update() { :; }' > ~/.direnvrc
2414
fi
2515

26-
#
27-
# COMPILER TOOLCHAIN
28-
#
29-
30-
# We install clang++ without the mason client for a couple reasons:
31-
# 1) decoupling makes it viable to use a custom branch of mason that might
32-
# modify the upstream s3 bucket in a such a way that does not give
33-
# it access to build tools like clang++
34-
# 2) Allows us to short-circuit and use a global clang++ install if it
35-
# is available to save space for local builds.
36-
GLOBAL_CLANG="${HOME}/.mason/mason_packages/${PLATFORM}-$(uname -m)/clang++/${MASON_LLVM_RELEASE}"
37-
GLOBAL_LLVM="${HOME}/.mason/mason_packages/${PLATFORM}-$(uname -m)/llvm/${MASON_LLVM_RELEASE}"
38-
if [[ -d ${GLOBAL_LLVM} ]]; then
39-
echo "Detected '${GLOBAL_LLVM}/bin/clang++', using it"
40-
local llvm_toolchain_dir=${GLOBAL_LLVM}
41-
elif [[ -d ${GLOBAL_CLANG} ]]; then
42-
echo "Detected '${GLOBAL_CLANG}/bin/clang++', using it"
43-
local llvm_toolchain_dir=${GLOBAL_CLANG}
44-
elif [[ -d ${GLOBAL_CLANG} ]]; then
45-
echo "Detected '${GLOBAL_CLANG}/bin/clang++', using it"
46-
local llvm_toolchain_dir=${GLOBAL_CLANG}
47-
elif [[ ! -d ${llvm_toolchain_dir} ]]; then
48-
BINARY="${MASON_URL}/clang++/${MASON_LLVM_RELEASE}.tar.gz"
49-
echo "Downloading ${BINARY}"
50-
mkdir -p ${llvm_toolchain_dir}
51-
curl -sSfL ${BINARY} | tar --gunzip --extract --strip-components=1 --directory=${llvm_toolchain_dir}
16+
# Ensure toolchain is installed via mason-js
17+
if [[ ! -f ./node_modules/.bin/mason-js ]]; then
18+
npm install mason-js-sdk
5219
fi
5320

54-
#
55-
# MASON
56-
#
57-
58-
function setup_mason() {
59-
local install_dir=${1}
60-
local mason_release=${2}
61-
mkdir -p ${install_dir}
62-
curl -sSfL https://github.com/mapbox/mason/archive/${mason_release}.tar.gz | tar --gunzip --extract --strip-components=1 --directory=${install_dir}
63-
}
64-
65-
setup_mason $(pwd)/.mason ${MASON_RELEASE}
21+
node_modules/.bin/mason-js install clang++=${MASON_LLVM_RELEASE} --type=compiled
22+
node_modules/.bin/mason-js link clang++=${MASON_LLVM_RELEASE} --type=compiled
6623

6724
#
6825
# ENV SETTINGS
6926
#
7027

71-
echo "export PATH=${llvm_toolchain_dir}/bin:$(pwd)/.mason:$(pwd)/mason_packages/.link/bin:"'${PATH}' > ${config}
72-
echo "export CXX=${CXX:-${llvm_toolchain_dir}/bin/clang++}" >> ${config}
73-
echo "export MASON_RELEASE=${MASON_RELEASE}" >> ${config}
28+
echo "export PATH=$(pwd)/.mason:$(pwd)/mason_packages/.link/bin:"'${PATH}' > ${config}
29+
echo "export CXX=${CXX:-$(pwd)/mason_packages/.link/bin/clang++}" >> ${config}
7430
echo "export MASON_LLVM_RELEASE=${MASON_LLVM_RELEASE}" >> ${config}
7531
# https://github.com/google/sanitizers/wiki/AddressSanitizerAsDso
76-
RT_BASE=${llvm_toolchain_dir}/lib/clang/${MASON_LLVM_RELEASE}/lib/$(uname | tr A-Z a-z)/libclang_rt
32+
RT_BASE=$(pwd)/mason_packages/.link/lib/clang/${MASON_LLVM_RELEASE}/lib/$(uname | tr A-Z a-z)/libclang_rt
7733
if [[ $(uname -s) == 'Darwin' ]]; then
7834
RT_PRELOAD=${RT_BASE}.asan_osx_dynamic.dylib
7935
else
@@ -85,8 +41,8 @@ function run() {
8541
echo "leak:v8::internal" >> ${SUPPRESSION_FILE}
8642
echo "leak:node::CreateEnvironment" >> ${SUPPRESSION_FILE}
8743
echo "leak:node::Init" >> ${SUPPRESSION_FILE}
88-
echo "export ASAN_SYMBOLIZER_PATH=${llvm_toolchain_dir}/bin/llvm-symbolizer" >> ${config}
89-
echo "export MSAN_SYMBOLIZER_PATH=${llvm_toolchain_dir}/bin/llvm-symbolizer" >> ${config}
44+
echo "export ASAN_SYMBOLIZER_PATH=$(pwd)/mason_packages/.link/bin/llvm-symbolizer" >> ${config}
45+
echo "export MSAN_SYMBOLIZER_PATH=$(pwd)/mason_packages/.link/bin/llvm-symbolizer" >> ${config}
9046
echo "export UBSAN_OPTIONS=print_stacktrace=1" >> ${config}
9147
echo "export LSAN_OPTIONS=suppressions=${SUPPRESSION_FILE}" >> ${config}
9248
echo "export ASAN_OPTIONS=symbolize=1:abort_on_error=1:detect_container_overflow=1:check_initialization_order=1:detect_stack_use_after_return=1" >> ${config}
@@ -129,4 +85,4 @@ case $i in
12985
usage
13086
;;
13187
esac
132-
done
88+
done

0 commit comments

Comments
 (0)