1 |
commit: e00665d14c50351c4c8cd08d60d7d4d625b0a18d |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jun 2 17:41:37 2015 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jun 2 17:41:37 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=e00665d1 |
7 |
|
8 |
getgccversion: add support for Clang |
9 |
|
10 |
Since Gentoo Prefix for Mac OS X uses Clang as system compiler, portage |
11 |
picks up either gcc from the host, or complains no compiler is |
12 |
installed, which both are obviously not true. |
13 |
|
14 |
pym/_emerge/actions.py | 42 +++++++++++++++++++++++++++++++++++++++--- |
15 |
1 file changed, 39 insertions(+), 3 deletions(-) |
16 |
|
17 |
diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py |
18 |
index 047fa98..6910ac6 100644 |
19 |
--- a/pym/_emerge/actions.py |
20 |
+++ b/pym/_emerge/actions.py |
21 |
@@ -2362,14 +2362,25 @@ def getgccversion(chost): |
22 |
gcc_ver_command = ['gcc', '-dumpversion'] |
23 |
gcc_ver_prefix = 'gcc-' |
24 |
|
25 |
+ clang_ver_command = ['clang', '--version'] |
26 |
+ clang_ver_prefix = 'clang-' |
27 |
+ |
28 |
+ ubinpath = os.path.join('/', portage.const.EPREFIX, 'usr', 'bin') |
29 |
+ |
30 |
gcc_not_found_error = red( |
31 |
"!!! No gcc found. You probably need to 'source /etc/profile'\n" + |
32 |
"!!! to update the environment of this terminal and possibly\n" + |
33 |
"!!! other terminals also.\n" |
34 |
) |
35 |
|
36 |
+ def getclangversion(output): |
37 |
+ version = re.search('clang version ([0-9.]+) ', output) |
38 |
+ if version: |
39 |
+ return version.group(1) |
40 |
+ return "unknown" |
41 |
+ |
42 |
try: |
43 |
- proc = subprocess.Popen(["gcc-config", "-c"], |
44 |
+ proc = subprocess.Popen([ubinpath + "/gcc-config", "-c"], |
45 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
46 |
except OSError: |
47 |
myoutput = None |
48 |
@@ -2382,7 +2393,7 @@ def getgccversion(chost): |
49 |
|
50 |
try: |
51 |
proc = subprocess.Popen( |
52 |
- [chost + "-" + gcc_ver_command[0]] + gcc_ver_command[1:], |
53 |
+ [ubinpath + "/" + chost + "-" + gcc_ver_command[0]] + gcc_ver_command[1:], |
54 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
55 |
except OSError: |
56 |
myoutput = None |
57 |
@@ -2394,7 +2405,7 @@ def getgccversion(chost): |
58 |
return gcc_ver_prefix + myoutput |
59 |
|
60 |
try: |
61 |
- proc = subprocess.Popen(gcc_ver_command, |
62 |
+ proc = subprocess.Popen([ubinpath + "/" + gcc_ver_command[0]] + gcc_ver_command[1:], |
63 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
64 |
except OSError: |
65 |
myoutput = None |
66 |
@@ -2405,6 +2416,31 @@ def getgccversion(chost): |
67 |
if mystatus == os.EX_OK: |
68 |
return gcc_ver_prefix + myoutput |
69 |
|
70 |
+ try: |
71 |
+ proc = subprocess.Popen( |
72 |
+ [ubinpath + "/" + chost + "-" + clang_ver_command[0]] + clang_ver_command[1:], |
73 |
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
74 |
+ except OSError: |
75 |
+ myoutput = None |
76 |
+ mystatus = 1 |
77 |
+ else: |
78 |
+ myoutput = _unicode_decode(proc.communicate()[0]).rstrip("\n") |
79 |
+ mystatus = proc.wait() |
80 |
+ if mystatus == os.EX_OK: |
81 |
+ return clang_ver_prefix + getclangversion(myoutput) |
82 |
+ |
83 |
+ try: |
84 |
+ proc = subprocess.Popen([ubinpath + "/" + clang_ver_command[0]] + clang_ver_command[1:], |
85 |
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
86 |
+ except OSError: |
87 |
+ myoutput = None |
88 |
+ mystatus = 1 |
89 |
+ else: |
90 |
+ myoutput = _unicode_decode(proc.communicate()[0]).rstrip("\n") |
91 |
+ mystatus = proc.wait() |
92 |
+ if mystatus == os.EX_OK: |
93 |
+ return clang_ver_prefix + getclangversion(myoutput) |
94 |
+ |
95 |
portage.writemsg(gcc_not_found_error, noiselevel=-1) |
96 |
return "[unavailable]" |