Use travis_setup.sh from scala-native

This commit is contained in:
exoego 2019-05-14 11:15:10 +09:00
parent 278aeeb11f
commit f71bd9163c
4 changed files with 140 additions and 6 deletions

View File

@ -1,19 +1,17 @@
dist: xenial
group: stable
sudo: required
language: scala
jdk: openjdk11
before_install:
- bash scripts/travis_setup.sh
before_script:
- export JVM_OPTS="-Dfile.encoding=UTF-8 -Xmx1G -Xms1G -server -XX:ReservedCodeCacheSize=128M"
- unset _JAVA_OPTIONS
addons:
apt:
packages:
- clang
- libunwind-dev
script: sbt scripted
cache:

74
scripts/clangfmt Executable file
View File

@ -0,0 +1,74 @@
#!/bin/bash
#
# Format C/C++ code using clang-format.
#
# To ensure reproducible formatting the script checks that clang-format
# is from the most recent version of LLVM supported by Scala Native.
#
# Usage: $0 [--test]
#
# Set CLANG_FORMAT_PATH to configure path to clang-format.
set -euo pipefail
IFS=$'\n\t'
# The required version of clang-format.
CLANG_FORMAT_VERSION=5.0
CLANG_FORMAT_VERSION_STRING="clang-format version $CLANG_FORMAT_VERSION"
die() {
while [ "$#" -gt 0 ]; do
echo >&2 "$1"; shift
done
exit 1
}
check_clang_format_version() {
cmd="$1"
[ -e "$(type -P "$cmd")" ] && \
"$cmd" --version 2> /dev/null | grep -q "$CLANG_FORMAT_VERSION_STRING"
}
clang_format=
if [ -n "${CLANG_FORMAT_PATH:-}" ]; then
check_clang_format_version "$CLANG_FORMAT_PATH" || \
die "CLANG_FORMAT_PATH does not have required version $CLANG_FORMAT_VERSION" \
"CLANG_FORMAT_PATH points to $CLANG_FORMAT_PATH"
clang_format="$CLANG_FORMAT_PATH"
else
for cmd in "clang-format-$CLANG_FORMAT_VERSION" clang-format; do
if check_clang_format_version "$cmd"; then
clang_format="$cmd"
break
fi
done
fi
if [ -z "$clang_format" ]; then
die "clang-format version $CLANG_FORMAT_VERSION not found" \
"Install LLVM version $CLANG_FORMAT_VERSION and rerun."
fi
test_mode=
while [ "$#" -gt 0 ]; do
arg="$1"
case "$arg" in
--test) test_mode=true; shift ;;
--*) die "Unknown argument: $arg" "Usage: $0 [--test]" ;;
*) break ;;
esac
done
if [ "$#" -gt 0 ]; then
"$clang_format" --style=file -i "$@"
else
find . -name "*.[ch]" -or -name "*.cpp" | xargs "$clang_format" --style=file -i
fi
if [ "$test_mode" = true ]; then
git diff --quiet --exit-code || \
die "C/C++ code formatting changes detected" \
"Run \`$0\` to reformat."
fi

20
scripts/scalafmt Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# set -x
HERE="`dirname $0`"
VERSION="1.2.0"
COURSIER="$HERE/.coursier"
SCALAFMT="$HERE/.scalafmt-$VERSION"
if [ ! -f $COURSIER ]; then
curl -L -o $COURSIER https://git.io/vgvpD
chmod +x $COURSIER
fi
if [ ! -f $SCALAFMT ]; then
$COURSIER bootstrap com.geirsson:scalafmt-cli_2.11:$VERSION --main org.scalafmt.cli.Cli -o $SCALAFMT
chmod +x $SCALAFMT
fi
$SCALAFMT "$@"

42
scripts/travis_setup.sh Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Enable strict mode and fail the script on non-zero exit code,
# unresolved variable or pipe failure.
set -euo pipefail
IFS=$'\n\t'
if [ "$(uname)" == "Darwin" ]; then
brew update
brew install sbt
brew install bdw-gc
brew link bdw-gc
brew install jq
brew install re2
brew install llvm@4
export PATH="/usr/local/opt/llvm@4/bin:$PATH"
else
sudo apt-get update
# Remove pre-bundled libunwind
sudo find /usr -name "*libunwind*" -delete
# Use pre-bundled clang
export PATH=/usr/local/clang-5.0.0/bin:$PATH
export CXX=clang++
# Install Boehm GC and libunwind
sudo apt-get install libgc-dev libunwind8-dev
# Build and install re2 from source
git clone https://code.googlesource.com/re2
pushd re2
git checkout 2017-03-01
make -j4 test
sudo make install prefix=/usr
make testinstall prefix=/usr
popd
fi