我在travis中有一个用于不同构建的矩阵。想法是使用 CLANG_SRC_VER 变量。此变量通过travis矩阵设置,在before_install部分中,我启动了一个脚本,该脚本根据变量 CLANG_SRC_VER 的值安装包。
travis.yml看起来像这样:
matrix:
include:
- os: linux
dist: trusty
sudo: required
rvm: 2.1
env:
- CLANG_SRC_VER='35'
...
- os: linux
dist: trusty
sudo: required
rvm: ruby-head
env:
- CLANG_SRC_VER='35'
- os: linux
dist: trusty
sudo: required
rvm: 2.1
env:
- CLANG_SRC_VER='37'
- os: linux
dist: trusty
sudo: required
rvm: 2.2
env:
- CLANG_SRC_VER='37'
...
- os: linux
dist: trusty
sudo: required
rvm: 2.1
env:
- CLANG_SRC_VER='36'
- os: linux
dist: trusty
sudo: required
rvm: 2.2
env:
- CLANG_SRC_VER='36'
...
before_install:
- sudo ./tools/travis_before_install.sh
- gem install bundler
script:
- bundle exec tools/travis_build_gem.sh
- bundle exec gem install --debug --verbose --local clangc-0.0.1.gem
- ./tools/travis_run_tests.sh
travis_before_install.sh看起来像那样:
#!/bin/bash
case $CLANG_SRC_VER in
35)
echo "$CLANG_SRC_VER"
apt-get update -qq
echo "install the libs for $CLANG_SRC_VER"
apt-get install -qq llvm-dev libclang-3.5-dev libclang1-3.5 libclang-common-3.5-dev build-essential ruby-dev
echo "add symbolic link for $CLANG_SRC_VER"
ln -s /usr/lib/x86_64-linux-gnu/libclang-3.5.so /usr/lib/x86_64-linux-gnu/libclang.so;;
36)
echo "${CLANG_SRC_VER}"
apt-get update -qq
echo "install the libs for $CLANG_SRC_VER"
apt-get install -qq llvm-dev libclang-3.6-dev libclang1-3.6 libclang-common-3.6-dev build-essential ruby-dev
echo "add symbolic link for $CLANG_SRC_VER"
ln -s /usr/lib/x86_64-linux-gnu/libclang-3.6.so /usr/lib/x86_64-linux-gnu/libclang.so;;
37)
echo "$CLANG_SRC_VER"
apt-get update -qq
echo "install the libs for $CLANG_SRC_VER"
apt-get install -qq llvm-dev libclang-3.7-dev libclang1-3.7 libclang-common-3.7-dev build-essential ruby-dev
echo "add symbolic link for $CLANG_SRC_VER"
ln -s /usr/lib/x86_64-linux-gnu/libclang-3.7.so /usr/lib/x86_64-linux-gnu/libclang.so;;
38)
echo "$CLANG_SRC_VER"
apt-get update -qq
echo "install the libs for $CLANG_SRC_VER"
apt-get install -qq llvm-dev libclang-3.8-dev libclang1-3.8 libclang-common-3.8-dev build-essential ruby-dev
echo "add symbolic link for $CLANG_SRC_VER"
ln -s /usr/lib/x86_64-linux-gnu/libclang-3.8.so /usr/lib/x86_64-linux-gnu/libclang.so;;
*)
echo "$CLANG_SRC_VER"
apt-get update -qq
echo "install the libs for $CLANG_SRC_VER"
apt-get install -qq llvm-dev libclang-3.5-dev libclang1-3.5 libclang-common-3.5-dev build-essential ruby-dev
echo "add symbolic link for $CLANG_SRC_VER"
ln -s /usr/lib/x86_64-linux-gnu/libclang-3.5.so /usr/lib/x86_64-linux-gnu/libclang.so;;
esac
问题是在矩阵的每种情况下,CLANG_SRC_VER都是空的。 我检查了travis输出,我有一行显示变量已设置并导出:
Setting environment variables from .travis.yml
$ export CLANG_SRC_VER='37'
答案 0 :(得分:0)
很简单,在travis.yml中我刚刚更改了这一行:
sudo ./tools/travis_before_install.sh
到
sudo CLANG_SRC_VER=$CLANG_SRC_VER ./tools/travis_before_install.sh
为了在sudo环境中定义变量。