[gentoo-dev] [PATCH 4/4] toolchain-funcs.eclass: Add helpful tc-is-{gcc,clang} wrappers

2016-06-24 Thread Michał Górny
---
 eclass/tests/toolchain-funcs.sh | 28 
 eclass/toolchain-funcs.eclass   | 12 
 2 files changed, 40 insertions(+)

diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh
index 6f37996..e6a1538 100755
--- a/eclass/tests/toolchain-funcs.sh
+++ b/eclass/tests/toolchain-funcs.sh
@@ -120,6 +120,20 @@ export CC=gcc
 )
 tend $?
 
+tbegin "tc-is-gcc (gcc)"
+(
+export CC=gcc
+tc-is-gcc
+)
+tend $?
+
+tbegin "! tc-is-clang (gcc)"
+(
+export CC=gcc
+! tc-is-clang
+)
+tend $?
+
 if type -P clang &>/dev/null; then
tbegin "tc-get-compiler-type (clang)"
(
@@ -127,6 +141,20 @@ if type -P clang &>/dev/null; then
[[ $(tc-get-compiler-type) == clang ]]
)
tend $?
+
+   tbegin "! tc-is-gcc (clang)"
+   (
+   export CC=clang
+   ! tc-is-gcc
+   )
+   tend $?
+
+   tbegin "tc-is-clang (clang)"
+   (
+   export CC=clang
+   tc-is-clang
+   )
+   tend $?
 fi
 
 if type -P pathcc &>/dev/null; then
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index a29784c..d3abfb5 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -607,6 +607,18 @@ tc-get-compiler-type() {
esac
 }
 
+# @FUNCTION: tc-is-gcc
+# @RETURN: Shell true if the current compiler is GCC, false otherwise.
+tc-is-gcc() {
+   [[ $(tc-get-compiler-type) == gcc ]]
+}
+
+# @FUNCTION: tc-is-clang
+# @RETURN: Shell true if the current compiler is clang, false otherwise.
+tc-is-clang() {
+   [[ $(tc-get-compiler-type) == clang ]]
+}
+
 # Internal func.  The first argument is the version info to expand.
 # Query the preprocessor to improve compatibility across different
 # compilers rather than maintaining a --version flag matrix. #335943
-- 
2.9.0




[gentoo-dev] [PATCH 3/4] toolchain-funcs.eclass: Add tc-get-compiler-type()

2016-06-24 Thread Michał Górny
Add a tc-get-compiler-type() function that can be used to identify
the compiler being used, using the preprocessor defines. Alike
gcc-*version() routines, it uses CPP (which in turn uses CC).

The major usage would be applying compiler-specific quirks and limiting
gcc version checks to compilers that actually are gcc, since e.g. clang
reports gcc version 4.2 -- which would incorrectly cause numerous gcc
version checks in ebuilds to fail.
---
 eclass/tests/toolchain-funcs.sh | 40 
 eclass/toolchain-funcs.eclass   | 22 ++
 2 files changed, 62 insertions(+)

diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh
index 41c1ae5..6f37996 100755
--- a/eclass/tests/toolchain-funcs.sh
+++ b/eclass/tests/toolchain-funcs.sh
@@ -111,5 +111,45 @@ tc-ld-disable-gold
 )
 tend $?
 
+unset CPP
+
+tbegin "tc-get-compiler-type (gcc)"
+(
+export CC=gcc
+[[ $(tc-get-compiler-type) == gcc ]]
+)
+tend $?
+
+if type -P clang &>/dev/null; then
+   tbegin "tc-get-compiler-type (clang)"
+   (
+   export CC=clang
+   [[ $(tc-get-compiler-type) == clang ]]
+   )
+   tend $?
+fi
+
+if type -P pathcc &>/dev/null; then
+   tbegin "tc-get-compiler-type (pathcc)"
+   (
+   export CC=pathcc
+   [[ $(tc-get-compiler-type) == pathcc ]]
+   )
+   tend $?
+
+   tbegin "! tc-is-gcc (pathcc)"
+   (
+   export CC=pathcc
+   ! tc-is-gcc
+   )
+   tend $?
+
+   tbegin "! tc-is-clang (pathcc)"
+   (
+   export CC=pathcc
+   ! tc-is-clang
+   )
+   tend $?
+fi
 
 texit
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 1baab96..a29784c 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -585,6 +585,28 @@ tc-endian() {
esac
 }
 
+# @FUNCTION: tc-get-compiler-type
+# @RETURN: keyword identifying the compiler: gcc, clang, pathcc, unknown
+tc-get-compiler-type() {
+   local code='
+#if defined(__PATHSCALE__)
+   HAVE_PATHCC
+#elif defined(__clang__)
+   HAVE_CLANG
+#elif defined(__GNUC__)
+   HAVE_GCC
+#endif
+'
+   local res=$($(tc-getCPP "$@") -E -P - <<<"${code}")
+
+   case ${res} in
+   *HAVE_PATHCC*)  echo pathcc;;
+   *HAVE_CLANG*)   echo clang;;
+   *HAVE_GCC*) echo gcc;;
+   *)  echo unknown;;
+   esac
+}
+
 # Internal func.  The first argument is the version info to expand.
 # Query the preprocessor to improve compatibility across different
 # compilers rather than maintaining a --version flag matrix. #335943
-- 
2.9.0




[gentoo-dev] [PATCH 2/4] toolchain-funcs.eclass: Assume CPP="$(tc-getCC) -E" when unset, #582822

2016-06-24 Thread Michał Górny
Modify the tc-getCPP and tc-getBUILD_CPP functions to use "$(tc-getCC)
-E" (i.e. the C compiler's preprocessing call) instead of falling back
to 'cpp'. This ensures that in environment with CC (and CXX) overriden
the correct compiler is used rather than the one selected by gcc-config,
which in turn fixes gcc version queries.

The alternative would be to always override CPP along with CC & CXX.
However, that is uncommon and is known to break some packages.

Bug: https://bugs.gentoo.org/show_bug.cgi?id=582822
---
 eclass/toolchain-funcs.eclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 8ecc736..1baab96 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -59,7 +59,7 @@ tc-getCC() { tc-getPROG CC gcc "$@"; }
 # @FUNCTION: tc-getCPP
 # @USAGE: [toolchain prefix]
 # @RETURN: name of the C preprocessor
-tc-getCPP() { tc-getPROG CPP cpp "$@"; }
+tc-getCPP() { tc-getPROG CPP "${CC:-gcc} -E" "$@"; }
 # @FUNCTION: tc-getCXX
 # @USAGE: [toolchain prefix]
 # @RETURN: name of the C++ compiler
@@ -132,7 +132,7 @@ tc-getBUILD_CC() { tc-getBUILD_PROG CC gcc "$@"; }
 # @FUNCTION: tc-getBUILD_CPP
 # @USAGE: [toolchain prefix]
 # @RETURN: name of the C preprocessor for building binaries to run on the 
build machine
-tc-getBUILD_CPP() { tc-getBUILD_PROG CPP cpp "$@"; }
+tc-getBUILD_CPP() { tc-getBUILD_PROG CPP "$(tc-getBUILD_CC) -E" "$@"; }
 # @FUNCTION: tc-getBUILD_CXX
 # @USAGE: [toolchain prefix]
 # @RETURN: name of the C++ compiler for building binaries to run on the build 
machine
-- 
2.9.0




[gentoo-dev] [PATCH 1/4] toolchain-funcs.eclass: Fix _tc-getPROG with multi-parameter defaults

2016-06-24 Thread Michał Górny
Fix _tc-getPROG function to account correctly for default values that
contain program name along with arguments, e.g. the default for CPP
containing "$(CC) -E".
---
 eclass/toolchain-funcs.eclass | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index e794559..8ecc736 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -22,7 +22,7 @@ inherit multilib
 _tc-getPROG() {
local tuple=$1
local v var vars=$2
-   local prog=$3
+   local prog=( $3 )
 
var=${vars%% *}
for v in ${vars} ; do
@@ -34,11 +34,11 @@ _tc-getPROG() {
done
 
local search=
-   [[ -n $4 ]] && search=$(type -p "$4-${prog}")
-   [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p 
"${!tuple}-${prog}")
-   [[ -n ${search} ]] && prog=${search##*/}
+   [[ -n $4 ]] && search=$(type -p $4-${prog[0]})
+   [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p 
${!tuple}-${prog[0]})
+   [[ -n ${search} ]] && prog[0]=${search##*/}
 
-   export ${var}=${prog}
+   export ${var}="${prog[*]}"
echo "${!var}"
 }
 tc-getBUILD_PROG() { _tc-getPROG CBUILD "BUILD_$1 $1_FOR_BUILD HOST$1" 
"${@:2}"; }
-- 
2.9.0




[gentoo-dev] [PATCH v4] tc-get-compiler-type() + wrappers

2016-06-24 Thread Michał Górny
Here's a quick v4.

Changes:
- fixed CHOST-search logic for multi-parameter default,
- replaced redundant tc-getCC call in tc-getCPP by plain ${CC:-gcc}
  since tc-getCPP will perform search anyway,
- changed docs for tc-get* to @OUTPUT.




Re: [gentoo-dev] Re: [PATCH 4/4] toolchain-funcs.eclass: Add helpful tc-is-{gcc,clang} wrappers

2016-06-24 Thread Mike Frysinger
On 24 Jun 2016 07:40, Michał Górny wrote:
> On Thu, 23 Jun 2016 21:32:34 -0400 Mike Frysinger wrote:
> > On 22 Jun 2016 22:06, Michał Górny wrote:
> > > +# @FUNCTION: tc-is-gcc
> > > +# @DESCRIPTION:
> > > +# Return true if the current compiler is pure GCC.  
> > 
> > "pure" doesn't make much sense and is just confusing
> > 
> > shouldn't this be a @RETURN instead of @DESCRIPTION ?  same for clang below.
> 
> I've followed suit with other functions in the eclass. They use @RETURN
> for stuff that is echoed, and @DESCRIPTION for exit codes.

right ... bash doesn't allow you to @RETURN a string
-mike


signature.asc
Description: Digital signature