public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] consider clang when looking up compiler version
@ 2016-02-18 20:04 Fabian Groffen
  2016-02-18 20:04 ` [gentoo-portage-dev] [PATCH] getgccversion: check for clang if gcc is not found Fabian Groffen
  0 siblings, 1 reply; 3+ messages in thread
From: Fabian Groffen @ 2016-02-18 20:04 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Fabian Groffen

This is a patch from prefix branch to make the compiler detection
consider clang.

Fabian Groffen (1):
  getgccversion: check for clang if gcc is not found

 pym/_emerge/actions.py | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

-- 
2.7.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [gentoo-portage-dev] [PATCH] getgccversion: check for clang if gcc is not found
  2016-02-18 20:04 [gentoo-portage-dev] [PATCH] consider clang when looking up compiler version Fabian Groffen
@ 2016-02-18 20:04 ` Fabian Groffen
  2016-02-22 13:08   ` Alexander Berntsen
  0 siblings, 1 reply; 3+ messages in thread
From: Fabian Groffen @ 2016-02-18 20:04 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Fabian Groffen

In Gentoo Prefix on Mac OS X systems, LLVM/clang is used as the
toolchain, so no gcc/gcc-config around.  Probe for clang after we failed
to locate gcc, so we can show clang version instead.
---
 pym/_emerge/actions.py | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
index 59626ad..1d324aa 100644
--- a/pym/_emerge/actions.py
+++ b/pym/_emerge/actions.py
@@ -39,6 +39,7 @@ from portage import os
 from portage import shutil
 from portage import eapi_is_supported, _encodings, _unicode_decode
 from portage.cache.cache_errors import CacheError
+from portage.const import EPREFIX
 from portage.const import GLOBAL_CONFIG_PATH, VCS_DIRS, _DEPCLEAN_LIB_CHECK_DEFAULT
 from portage.const import SUPPORTED_BINPKG_FORMATS, TIMESTAMP_FORMAT
 from portage.dbapi.dep_expand import dep_expand
@@ -2406,12 +2407,23 @@ def getgccversion(chost=None):
 	gcc_ver_command = ['gcc', '-dumpversion']
 	gcc_ver_prefix = 'gcc-'
 
+	clang_ver_command = ['clang', '--version']
+	clang_ver_prefix = 'clang-'
+
+	ubinpath = os.path.join('/', portage.const.EPREFIX, 'usr', 'bin')
+
 	gcc_not_found_error = red(
 	"!!! No gcc found. You probably need to 'source /etc/profile'\n" +
 	"!!! to update the environment of this terminal and possibly\n" +
 	"!!! other terminals also.\n"
 	)
 
+	def getclangversion(output):
+		version = re.search('clang version ([0-9.]+) ', output)
+		if version:
+			return version.group(1)
+		return "unknown"
+
 	if chost:
 		try:
 			proc = subprocess.Popen(["gcc-config", "-c"],
@@ -2439,7 +2451,7 @@ def getgccversion(chost=None):
 			return gcc_ver_prefix + myoutput
 
 	try:
-		proc = subprocess.Popen(gcc_ver_command,
+		proc = subprocess.Popen([ubinpath + "/" + gcc_ver_command[0]] + gcc_ver_command[1:],
 			stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 	except OSError:
 		myoutput = None
@@ -2450,6 +2462,31 @@ def getgccversion(chost=None):
 	if mystatus == os.EX_OK:
 		return gcc_ver_prefix + myoutput
 
+	try:
+		proc = subprocess.Popen(
+			[ubinpath + "/" + chost + "-" + clang_ver_command[0]] + clang_ver_command[1:],
+			stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+	except OSError:
+		myoutput = None
+		mystatus = 1
+	else:
+		myoutput = _unicode_decode(proc.communicate()[0]).rstrip("\n")
+		mystatus = proc.wait()
+	if mystatus == os.EX_OK:
+		return clang_ver_prefix + getclangversion(myoutput)
+
+	try:
+		proc = subprocess.Popen([ubinpath + "/" + clang_ver_command[0]] + clang_ver_command[1:],
+			stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+	except OSError:
+		myoutput = None
+		mystatus = 1
+	else:
+		myoutput = _unicode_decode(proc.communicate()[0]).rstrip("\n")
+		mystatus = proc.wait()
+	if mystatus == os.EX_OK:
+		return clang_ver_prefix + getclangversion(myoutput)
+
 	portage.writemsg(gcc_not_found_error, noiselevel=-1)
 	return "[unavailable]"
 
-- 
2.7.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] getgccversion: check for clang if gcc is not found
  2016-02-18 20:04 ` [gentoo-portage-dev] [PATCH] getgccversion: check for clang if gcc is not found Fabian Groffen
@ 2016-02-22 13:08   ` Alexander Berntsen
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Berntsen @ 2016-02-22 13:08 UTC (permalink / raw
  To: gentoo-portage-dev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Shouldn't this also do a sort of "clang not found either!" type of
output?
- -- 
Alexander
bernalex@gentoo.org
https://secure.plaimi.net/~alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCgAGBQJWywhHAAoJENQqWdRUGk8BYOcP/3K/gBn5kizIDhLMynHVoCgX
V/wkVZ1ZPVNXyCpjePew/KYDggS/rMrcECKvoYtHBNVsfhJjoca/Swu0VQXWevW0
U/brYSY55pbvgs74HURltJHvm1i1D6mZIpi6kl3CKbARB8ytZk6sTdI1CmZSGx+k
YFZgVqPOkI1o97h0Pewtksmwa0bomGv1nObIMzeC4dNn4invCROU1dS6RFlGWVAI
sbKQDusLWn70rN9jkmmrC+hqIfVxzAC1j9I2qCX6jqisFrLWZ9+pLFl39Ng+Ipul
8tmJBea9ayaq4kc+CADjJypFDEEyrXlSDL81QjJUgwsfnWvIOu7UKVvcVQhU5rHa
rHTKqJHTL3UoJX+DrQdzRHiKL8dkuOU8VpRdXwHshu1nwWiIp4qRF35vKTBuBE8R
8dSLYUYIVXgLG/90mkoUy9gOTd6/S33ZJwUIMipDpdJ7oLPsVugL9W8vmSTBUlGV
z8h8s4MtEjareKEUi0TOzH0gXLpPgdep5dGHXF3GjwR3r+7gl+KMbGpeSYBH436Z
H8cmcdeuMY+HVa6xl0TH1c/INyEOdjQFzVkvWV+lsszJq83WHEzqYled2eAnAUsH
/cGKiifQbiP+tzgo1DFT6HBZsDpf8UbBaldLX42bws+rJf3/bhdgFtiC/r4JXKSo
geq/fQgq8fyydYHfU080
=n5J4
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-02-22 13:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-18 20:04 [gentoo-portage-dev] [PATCH] consider clang when looking up compiler version Fabian Groffen
2016-02-18 20:04 ` [gentoo-portage-dev] [PATCH] getgccversion: check for clang if gcc is not found Fabian Groffen
2016-02-22 13:08   ` Alexander Berntsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox