travis-build
travis-build copied to clipboard
Dynamic compiler installation for Linux C/C++ builds
This PR adds the ability to install gcc and clang on the fly for Linux builds.
How is compiler versions found?
In language: c and language: cpp builds, we detect gcc and clang versions using the following regular expressions:
| C | C++ | |
|---|---|---|
| gcc | /^gcc(-\d+(\.\d+)*)?/i |
/^g(?:cc|\+\+)(-\d+(\.\d+)*)?/i |
| clang | /^clang(-\d+(\.\d+)*)?/i |
/^clang(?:\+\+)?(-\d+(\.\d+)*)?/i |
And use $1 in the match to drive package installations.
How do we decide to install new packages?
From the compiler value given in the config, we compute $CC value.
- For C builds, it is identical to the compiler value
- For C++ builds—for GCC,
gccorgcc-6; for clang,clangorclang-7
If this command is missing, we initiate package installation. For example, given:
language: c
compiler:
- gcc-6
and the command gcc-6 is not available, we proceed to install APT packages.
Which packages are installed?
First, appropriate apt repository is added.
- for GCC, ppa:ubuntu-toolchain-r/test
- for clang, see https://apt.llvm.org/
Then, the following packages will be installed:
- for C builds, value given by
compiler - for C++ builds, value computed for
CC(e.g.,gcc-6for gcc,clang-7for clang), even whencompilerlooks different (e.g.,g++-6orclang++-7).
In all cases, libstdc++-6 is also installed (if necessary).
Tests:
| Trusty | Xenial | |
|---|---|---|
| C | https://staging.travis-ci.org/BanzaiMan/travis_staging_test/builds/736324 (gcc-6 and clang-7 are installed on the fly.) | https://staging.travis-ci.org/BanzaiMan/travis_staging_test/builds/736319 (only gcc-6 is installed on the fly.) |
| C++ | https://staging.travis-ci.org/BanzaiMan/travis_staging_test/builds/736334 | https://staging.travis-ci.org/BanzaiMan/travis_staging_test/jobs/736331 |
| C++ (with g++-6, clang++-7) | https://staging.travis-ci.org/BanzaiMan/travis_staging_test/builds/736339 (See g++-6 and clang++-7 jobs) |
Hmm. The assumption that the compiler value should equal the command name appears wrong for g++-6. https://staging.travis-ci.org/BanzaiMan/travis_staging_test/jobs/736342#L246
Maybe the CC value (gcc-6 for compiler: g++-6) is the command to seek for C++ builds.
Currently, on C++ builds, we use the compiler value to announce the compiler version. We now accept compiler: g++-6, but this command is not available for gcc-6, which will be installed using this PR. I am inclined to use $CC value to announce the compiler version, but this could be confusing to some.