Skip to content

Commit 79cd216

Browse files
committed
Initial attempt at travis
1 parent afa4acb commit 79cd216

File tree

2 files changed

+292
-0
lines changed

2 files changed

+292
-0
lines changed

.travis.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
language: generic
2+
3+
sudo: false
4+
5+
matrix:
6+
include:
7+
- os: linux
8+
env: CXX=g++-4.9
9+
addons:
10+
apt:
11+
sources: [ 'ubuntu-toolchain-r-test' ]
12+
packages: [ 'g++-4.9' ]
13+
# override before_install to use apt installed compiler
14+
# rather than mason installed clang++
15+
before_install:
16+
- which ${CXX}
17+
- os: linux
18+
env: CXX=g++-5
19+
addons:
20+
apt:
21+
sources: [ 'ubuntu-toolchain-r-test' ]
22+
packages: [ 'g++-5' ]
23+
# override before_install to use apt installed compiler
24+
# rather than mason installed clang++
25+
before_install:
26+
- which ${CXX}
27+
- os: linux
28+
env: CXX=g++-6
29+
addons:
30+
apt:
31+
sources: [ 'ubuntu-toolchain-r-test' ]
32+
packages: [ 'g++-6' ]
33+
# override before_install to use apt installed compiler
34+
# rather than mason installed clang++
35+
before_install:
36+
- which ${CXX}
37+
- os: linux
38+
env: CXX=clang++ CXXFLAGS="-flto"
39+
addons:
40+
apt:
41+
sources: [ 'ubuntu-toolchain-r-test' ]
42+
packages: [ 'libstdc++-5-dev' ]
43+
- os: linux
44+
env: CXX=clang++ LLVM_VERSION="4.0.0" CXXFLAGS="-flto"
45+
addons:
46+
apt:
47+
sources: [ 'ubuntu-toolchain-r-test' ]
48+
packages: [ 'libstdc++-5-dev' ]
49+
- os: linux
50+
env: CXX=clang++ CXXFLAGS="-flto -fsanitize=cfi -fvisibility=hidden"
51+
addons:
52+
apt:
53+
sources: [ 'ubuntu-toolchain-r-test' ]
54+
packages: [ 'libstdc++-5-dev' ]
55+
- os: linux
56+
env: CXX=clang++ CXXFLAGS="-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer -fno-common"
57+
addons:
58+
apt:
59+
sources: [ 'ubuntu-toolchain-r-test' ]
60+
packages: [ 'libstdc++-5-dev' ]
61+
- os: linux
62+
env: CXX=clang++ CXXFLAGS="-fsanitize=undefined"
63+
addons:
64+
apt:
65+
sources: [ 'ubuntu-toolchain-r-test' ]
66+
packages: [ 'libstdc++-5-dev' ]
67+
- os: linux
68+
env: CXX=clang++ CXXFLAGS="-fsanitize=integer"
69+
addons:
70+
apt:
71+
sources: [ 'ubuntu-toolchain-r-test' ]
72+
packages: [ 'libstdc++-5-dev' ]
73+
# OS X / apple clang / xcode 7.x
74+
- os: osx
75+
osx_image: xcode7.3
76+
env: CXX=clang++
77+
# override before_install to use apple clang
78+
before_install:
79+
- which ${CXX}
80+
# OS X / mason clang 4.0.0 / xcode 8.x
81+
- os: osx
82+
osx_image: xcode8.2
83+
env: CXX=clang++ LLVM_VERSION="4.0.0"
84+
85+
before_install:
86+
- git submodule update --init
87+
- export LLVM_VERSION="${LLVM_VERSION:-3.9.1}"
88+
- |
89+
if [[ ${CXX} == "clang++" ]]; then
90+
./scripts/mason.sh install clang++ ${LLVM_VERSION}
91+
export PATH=$(./scripts/mason.sh prefix clang++ ${LLVM_VERSION})/bin:${PATH}
92+
./scripts/mason.sh install binutils 2.27
93+
export PATH=$(./scripts/mason.sh prefix binutils 2.27)/bin:${PATH}
94+
fi
95+
- which ${CXX}
96+
97+
before_script:
98+
- cmake .
99+
100+
script:
101+
- make -j
102+
- ./test_sa
103+

scripts/mason.sh

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#!/usr/bin/env bash
2+
3+
# Mason Client Version 1.0.0
4+
5+
# See below for `set -euo pipefail`
6+
7+
# Print file + line number when not in CLI mode
8+
if [[ "$0" != "$BASH_SOURCE" ]]; then
9+
function mason_error {
10+
local _LINE _FN _FILE
11+
read _LINE _FN _FILE <<< "`caller 1`"
12+
if [ -t 1 ]; then
13+
>&2 echo -e "\033[1m\033[31m$@ in ${_FILE} on line ${_LINE}\033[0m"
14+
else
15+
>&2 echo "$@ in ${_FILE} on line ${_LINE}"
16+
fi
17+
}
18+
else
19+
function mason_error {
20+
if [ -t 1 ]; then
21+
>&2 echo -e "\033[1m\033[31m$@\033[0m"
22+
else
23+
>&2 echo "$@"
24+
fi
25+
}
26+
fi
27+
28+
function mason_info {
29+
if [ -t 1 ]; then
30+
>&2 echo -e "\033[1m\033[36m$@\033[0m"
31+
else
32+
>&2 echo "$@"
33+
fi
34+
}
35+
36+
function mason_detect_platform {
37+
# Determine platform
38+
if [[ -z "${MASON_PLATFORM:-}" ]]; then
39+
if [[ "`uname -s`" = 'Darwin' ]]; then
40+
MASON_PLATFORM="osx"
41+
else
42+
MASON_PLATFORM="linux"
43+
fi
44+
fi
45+
46+
# Determine platform version string
47+
if [[ -z "${MASON_PLATFORM_VERSION:-}" ]]; then
48+
MASON_PLATFORM_VERSION="`uname -m`"
49+
fi
50+
}
51+
52+
function mason_trim {
53+
local _TMP="${1#"${1%%[![:space:]]*}"}"
54+
echo -n "${_TMP%"${_TMP##*[![:space:]]}"}"
55+
}
56+
57+
function mason_uppercase {
58+
echo -n "$1" | tr "[a-z]" "[A-Z]"
59+
}
60+
61+
function mason_use {
62+
local _HEADER_ONLY=false _PACKAGE _SAFE_PACKAGE _VERSION _PLATFORM_ID _SLUG _INSTALL_PATH _INSTALL_PATH_RELATIVE
63+
64+
while [[ $# -gt 0 ]]; do
65+
if [[ $1 == "--header-only" ]]; then
66+
_HEADER_ONLY=true
67+
elif [[ -z "${_PACKAGE:-}" ]]; then
68+
_PACKAGE="$1"
69+
elif [[ -z "${_VERSION:-}" ]]; then
70+
_VERSION="$1"
71+
else
72+
mason_error "[Mason] mason_use() called with unrecognized arguments: '$@'"
73+
exit 1
74+
fi
75+
shift
76+
done
77+
78+
if [[ -z "${_PACKAGE:-}" ]]; then
79+
mason_error "[Mason] No package name given"
80+
exit 1
81+
fi
82+
83+
# Create a package name that we can use as shell variable names.
84+
_SAFE_PACKAGE="${_PACKAGE//[![:alnum:]]/_}"
85+
86+
if [[ -z "${_VERSION:-}" ]]; then
87+
mason_error "[Mason] Specifying a version is required"
88+
exit 1
89+
fi
90+
91+
_PLATFORM_ID="${MASON_PLATFORM}-${MASON_PLATFORM_VERSION}"
92+
if [[ "${_HEADER_ONLY}" = true ]] ; then
93+
_PLATFORM_ID="headers"
94+
fi
95+
96+
_SLUG="${_PLATFORM_ID}/${_PACKAGE}/${_VERSION}"
97+
_INSTALL_PATH="${MASON_PACKAGE_DIR}/${_SLUG}"
98+
_INSTALL_PATH_RELATIVE="${_INSTALL_PATH#`pwd`/}"
99+
100+
if [[ ! -d "${_INSTALL_PATH}" ]]; then
101+
local _CACHE_PATH _URL _CACHE_DIR _ERROR
102+
_CACHE_PATH="${MASON_PACKAGE_DIR}/.binaries/${_SLUG}.tar.gz"
103+
if [ ! -f "${_CACHE_PATH}" ]; then
104+
# Download the package
105+
_URL="${MASON_REPOSITORY}/${_SLUG}.tar.gz"
106+
mason_info "[Mason] Downloading package ${_URL}..."
107+
_CACHE_DIR="`dirname "${_CACHE_PATH}"`"
108+
mkdir -p "${_CACHE_DIR}"
109+
if ! _ERROR=$(curl --retry 3 --silent --fail --show-error --location "${_URL}" --output "${_CACHE_PATH}.tmp" 2>&1); then
110+
mason_error "[Mason] ${_ERROR}"
111+
exit 1
112+
else
113+
# We downloaded to a temporary file to prevent half-finished downloads
114+
mv "${_CACHE_PATH}.tmp" "${_CACHE_PATH}"
115+
fi
116+
fi
117+
118+
# Unpack the package
119+
mason_info "[Mason] Unpacking package to ${_INSTALL_PATH_RELATIVE}..."
120+
mkdir -p "${_INSTALL_PATH}"
121+
tar xzf "${_CACHE_PATH}" -C "${_INSTALL_PATH}"
122+
fi
123+
124+
# Error out if there is no config file.
125+
if [[ ! -f "${_INSTALL_PATH}/mason.ini" ]]; then
126+
mason_error "[Mason] Could not find mason.ini for package ${_PACKAGE} ${_VERSION}"
127+
exit 1
128+
fi
129+
130+
# We use this instead of declare, since it declare makes local variables when run in a function.
131+
read "MASON_PACKAGE_${_SAFE_PACKAGE}_PREFIX" <<< "${_INSTALL_PATH}"
132+
133+
# Load the configuration from the ini file
134+
local _LINE _KEY _VALUE
135+
while read _LINE; do
136+
_KEY="`mason_trim "${_LINE%%=*}"`"
137+
if [[ "${_KEY}" =~ ^[a-z_]+$ ]]; then
138+
_KEY="`mason_uppercase "${_KEY}"`" # Convert to uppercase
139+
_LINE="${_LINE%%;*}" # Trim trailing comments
140+
_VALUE="`mason_trim "${_LINE#*=}"`"
141+
_VALUE="${_VALUE//\{prefix\}/${_INSTALL_PATH}}" # Replace {prefix}
142+
read "MASON_PACKAGE_${_SAFE_PACKAGE}_${_KEY}" <<< "${_VALUE}"
143+
fi
144+
done < "${_INSTALL_PATH}/mason.ini"
145+
146+
# We're using the fact that this variable is declared to pass back the package name we parsed
147+
# from the argument string to avoid polluting the global namespace.
148+
if [ ! -z ${_MASON_SAFE_PACKAGE_NAME+x} ]; then
149+
_MASON_SAFE_PACKAGE_NAME="${_SAFE_PACKAGE}"
150+
fi
151+
}
152+
153+
function mason_cli {
154+
local _MASON_SAFE_PACKAGE_NAME= _PROP _VAR
155+
if [[ $# -lt 1 ]]; then
156+
mason_error "[Mason] Usage: $0 <property> [--header-only] <name> <version>"
157+
mason_error "[Mason] <property> is one of 'include_dirs', 'definitions', 'options', 'ldflags', 'static_libs', or any custom variables in the package's mason.ini."
158+
exit 1
159+
fi
160+
161+
# Store first argument and pass the remaining arguments to mason_use
162+
_PROP="`mason_uppercase "$1"`"
163+
shift
164+
mason_use "$@"
165+
166+
# Optionally print variables
167+
_VAR="MASON_PACKAGE_${_MASON_SAFE_PACKAGE_NAME}_${_PROP}"
168+
if [[ ! -z "${!_VAR:-}" ]]; then
169+
echo "${!_VAR}"
170+
fi
171+
}
172+
173+
# Directory where Mason packages are located; typically ends with mason_packages
174+
if [[ -z "${MASON_PACKAGE_DIR:-}" ]]; then
175+
MASON_PACKAGE_DIR="`pwd`/mason_packages"
176+
fi
177+
178+
# URL prefix of where packages are located.
179+
if [[ -z "${MASON_REPOSITORY:-}" ]]; then
180+
MASON_REPOSITORY="https://mason-binaries.s3.amazonaws.com"
181+
fi
182+
183+
mason_detect_platform
184+
185+
# Print variables if this shell script is invoked directly.
186+
if [[ "$0" = "$BASH_SOURCE" ]]; then
187+
set -euo pipefail
188+
mason_cli "$@"
189+
fi

0 commit comments

Comments
 (0)