Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: toolchain@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 0/4] toolchain-funcs.eclass: fix for version checks (v2) + compiler identification
Date: Wed, 22 Jun 2016 20:07:15
Message-Id: 20160622200654.6961-1-mgorny@gentoo.org
1 Hello, everyone.
2
3 Here's my second attempt at improving version checks
4 in toolchain-funcs.eclass. Currently the functions use $(tc-getCPP)
5 to determine gcc version. This doesn't trigger expected results when CC
6 & CXX are overriden but CPP is not which is a common case -- it causes
7 the eclass to fallback to 'cpp' and therefore use active gcc version
8 rather than the CC being used.
9
10 My initial fix was limited to defaulting the preprocessor to '$(CC) -E'
11 rather than 'cpp'. However, as eroen pointed out clang reports gcc
12 version 4.2 which would cause numerous ebuild checks to fail. Therefore,
13 I've decided to extend the patchset with means to prevent that.
14
15 Aside to fixing tc-getCPP and therefore gcc-*version functions to use
16 the active compiler, it also introduces a generic tc-get-compiler-type
17 function that identifies the compiler as either gcc and clang (support
18 for more compilers welcome). Two friendly wrappers are provided as well:
19 tc-is-gcc and tc-is-clang.
20
21 Note that unlike common less and more successful CC/CXX comparisons,
22 the functions actually use preprocessor macros to identify the compiler.
23
24
25 The common use cases:
26
27 a. checking for a specific gcc version:
28
29 [[ $(gcc-major-version) = 5 && $(gcc-minor-version) -le 2 ]]
30
31 would become:
32
33 tc-is-gcc && [[ $(gcc-major-version) = 5 && $(gcc-minor-version) -le 2 ]]
34
35 i.e. it would not trigger for clang.
36
37 b. applying clang-specific quirks (discouraged but people still do
38 that):
39
40 [[ ${CC} == *clang* ]] && ...
41
42 would become:
43
44 tc-is-clang && ...
45
46
47
48 Michał Górny (4):
49 toolchain-funcs.eclass: Fix _tc-getPROG with multi-parameter defaults
50 toolchain-funcs.eclass: Assume CPP="$(tc-getCC) -E" when unset,
51 #582822
52 toolchain-funcs.eclass: Add tc-get-compiler-type()
53 toolchain-funcs.eclass: Add helpful tc-is-{gcc,clang} wrappers
54
55 eclass/tests/toolchain-funcs.sh | 15 ++++++++++++++
56 eclass/toolchain-funcs.eclass | 43 ++++++++++++++++++++++++++++++++++++-----
57 2 files changed, 53 insertions(+), 5 deletions(-)
58
59 --
60 2.9.0

Replies