travis-build
travis-build copied to clipboard
Allow C++ compiler versions to be specified in yaml-file
Using a specific compiler version required up to now to manually export $CC and $CXX (a hack that is very common in the wild, see linked issues). This changeset should solve this so you can simply do compiler: gcc-4.9
. Closes #3871, partly implements #979, replaces PR#542 (which accurately describes the problem, but just makes the hack easier).
Additionally, this solves the minor problem that announce
displays the given compiler: anystring
without sanitising the string, such that it prints a different version (the specified anystring
) than the one that is actually used (the system default if not either g++
or clang++
is specified). Finally, this changeset also sets the default OS X compiler to clang
instead of gcc
.
Okay, seems like the spec
needs to be updated for the CI check to pass, but I could use some help for that. I basically learned a bit of Ruby just to fix this issue and I'm not even 100% sure what a spec
is :-) (some sort of Ruby testing/coverage framework is what I can deduce).
Sorry for the delay.
The failure is coming from here: https://github.com/travis-ci/travis-build/blob/bbe7c12b6f2c8bdc6cd9a7d3e839a729048648ae/spec/build/script/cpp_spec.rb#L88
This is testing whether gcc --version
should be run when compiler: gcc
. And I think it should.
Well, maybe it is legitimate to show g++ --version
output when we have compiler: gcc
. Then the spec should be changed.
I would love it if we could go forward with this. https://github.com/travis-ci/travis-ci/issues/3871 is very annoying.
@BanzaiMan I could use some more input on best Ruby/Travis practices, before starting to update the spec
. Notably, how to set platform specific DEFAULTS
.
Actually, I don't understand why it's not possible to simply avoid modifying the compiler
in the cxx
and cc
methods, i.e. instead of
def cxx
case compiler
when /^gcc/i, /^g\+\+/i then
'g++'
when /^clang/i, /^clang\+\+/i then
'clang++'
else
'g++'
end
end
just use
def cxx
compiler
end
This way, whatever is being set in compiler: xxx
in the script will be used as CXX
, which I think is what we want.
It seems like we don't need all the logic added in this PR (and the removal of the default compiler); we just need to stop overwriting the compiler set by the user.
@ldionne It's more nice to have than strictly necessary. It's just some string sanitising to prevent users from making mistakes and to make matching pairs of C and C++ compilers. Anyway, I managed to make the spec pass now. I guess I should add some new test cases too and then wait for @BanzaiMan's input before I squash the commits to merge.
@jpauwels Ok, I agree. For what it's worth, this LGTM. The only thing that I can imagine could break builds is the fact that you changed the default to clang++
on OS X, but that should be fine since Clang has been the default compiler on OS X for a while and g++
is even aliased to clang++
.
Is this pull request going anywhere?
yeah, it would be nice if travis could automatically switch to whatever compiler version I want without manually having to do sudo apt-get install <insert compiler here>
manually in my .travis.yml
.
Bump. This is becoming increasingly necessary for those of us who want to build only with the supported GCC versions (currently 6 and 7). My current workaround is to set language: c and export CXX in a before_install script based on the value of $CC... not ideal.
A possible alternative to consider would be giving access to the compiler field through some environment variable (${TRAVIS_COMPILER}?).
I was thinking of this and well what if one wants gcc 8.x but travis has up to 7.x. This has so know if it should install gcc 8 on it’s own or whatever the current version is until travis provides that version too.
Also the end of hacking gcc 4.6 or so or clang 2/3 which are default with travis to whatever versions people preset in yml would help a lot to prevent useless or time consuming compiler installs or hacks for them.