Commit c170827f authored by Armin Rigo's avatar Armin Rigo
Browse files

Tweak 'sys.version' to actually contain the compiler used to compile

the final C sources, instead of whatever gcc was present when we
produced the C sources.  Useful e.g. with pypy-stm where we use a
different compiler at the end (clang or gcc-seg-gs).
parent 79617073c0fe
......@@ -66,7 +66,7 @@ class Module(MixedModule):
'api_version' : 'version.get_api_version(space)',
'version_info' : 'version.get_version_info(space)',
'version' : 'version.get_version(space)',
#'version' : set in startup()
'pypy_version_info' : 'version.get_pypy_version_info(space)',
'subversion' : 'version.get_subversion_info(space)',
'_mercurial' : 'version.get_repo_info(space)',
......@@ -108,6 +108,9 @@ class Module(MixedModule):
assert self.filesystemencoding is None
else:
from pypy.module.sys import version
space.setitem(self.w_dict, space.wrap("version"),
space.wrap(version.get_version(space)))
if _WIN:
from pypy.module.sys import vm
w_handle = vm.get_dllhandle(space)
......
......@@ -2,13 +2,13 @@ class AppTestVersion:
def test_compiler(self):
import sys
assert ("MSC v." in sys.version or
"GCC " in sys.version)
"GCC " in sys.version or
"(untranslated)" in sys.version)
def test_get_version(space, monkeypatch):
def test_get_version():
from pypy.module.sys import version
monkeypatch.setattr(version, 'PYPY_VERSION', (2,5,0, "final", 1))
res = space.unwrap(version.get_version(space))
res = version._make_version_template(PYPY_VERSION=(2,5,0, "final", 1))
assert "[PyPy 2.5.0" in res
monkeypatch.setattr(version, 'PYPY_VERSION', (2,6,3, "alpha", 5))
res = space.unwrap(version.get_version(space))
res = version._make_version_template(PYPY_VERSION=(2,6,3, "alpha", 5))
assert "[PyPy 2.6.3-alpha5" in res
assert res.endswith(' with %s]')
......@@ -2,7 +2,7 @@
Version numbers exposed by PyPy through the 'sys' module.
"""
import os
from rpython.translator.platform import platform
from rpython.rlib import compilerinfo
from pypy.interpreter import gateway
#XXX # the release serial 42 is not in range(16)
......@@ -12,15 +12,6 @@ CPYTHON_API_VERSION = 1013 #XXX # sync with include/modsupport.h
PYPY_VERSION = (2, 7, 0, "alpha", 0) #XXX # sync patchlevel.h
if platform.name == 'msvc':
COMPILER_INFO = 'MSC v.%d 32 bit' % (platform.version * 10 + 600)
elif platform.cc is not None and \
os.path.basename(platform.cc).startswith(('gcc', 'clang')):
from rpython.rtyper.tool import rffi_platform
COMPILER_INFO = 'GCC ' + rffi_platform.getdefinedstring('__VERSION__', '')
else:
COMPILER_INFO = ""
import pypy
pypydir = os.path.dirname(os.path.abspath(pypy.__file__))
......@@ -57,19 +48,24 @@ def get_version_info(space):
w_version_info = app.wget(space, "version_info")
return space.call_function(w_version_info, space.wrap(CPYTHON_VERSION))
def get_version(space):
def _make_version_template(PYPY_VERSION=PYPY_VERSION):
ver = "%d.%d.%d" % (PYPY_VERSION[0], PYPY_VERSION[1], PYPY_VERSION[2])
if PYPY_VERSION[3] != "final":
ver = ver + "-%s%d" %(PYPY_VERSION[3], PYPY_VERSION[4])
return space.wrap("%d.%d.%d (%s, %s, %s)\n[PyPy %s%s]" % (
template = "%d.%d.%d (%s, %s, %s)\n[PyPy %s with %%s]" % (
CPYTHON_VERSION[0],
CPYTHON_VERSION[1],
CPYTHON_VERSION[2],
get_repo_version_info(root=pypyroot)[1],
date,
time,
ver,
compiler_version()))
ver)
assert template.count('%') == 1 # only for the "%s" near the end
return template
_VERSION_TEMPLATE = _make_version_template()
def get_version(space):
return space.wrap(_VERSION_TEMPLATE % compilerinfo.get_compiler_info())
def get_winver(space):
return space.wrap("%d.%d" % (
......@@ -111,8 +107,3 @@ def tuple2hex(ver):
ver[2] << 8 |
d[ver[3]] << 4 |
subver)
def compiler_version():
if not COMPILER_INFO:
return ""
return " with %s" % (COMPILER_INFO,)
from rpython.rlib.objectmodel import we_are_translated
from rpython.rtyper.lltypesystem import rffi
from rpython.translator.platform import platform
def get_compiler_info():
"""Returns a string like 'MSC v.# 32 bit' or 'GCC #.#.#'.
Before translation, returns '(untranslated)'.
Must be called at run-time, not before translation, otherwise
you're freezing the string '(untranslated)' into the executable!
"""
if we_are_translated():
return rffi.charp2str(COMPILER_INFO)
return "(untranslated)"
# ____________________________________________________________
if platform.name == 'msvc':
# XXX hard-code the MSC version, I don't feel like computing it dynamically
_C_COMPILER_INFO = '"MSC v.%d 32 bit"' % (platform.version * 10 + 600)
else:
_C_COMPILER_INFO = '("GCC " __VERSION__)'
COMPILER_INFO = rffi.CConstant(_C_COMPILER_INFO, rffi.CCHARP)
from rpython.rlib.compilerinfo import get_compiler_info
from rpython.translator.c.test.test_genc import compile
def test_untranslated():
assert get_compiler_info() == "untranslated"
def fn(index):
cc = get_compiler_info()
if index < len(cc):
return ord(cc[index])
return 0
def test_compiled():
fn2 = compile(fn, [int])
lst = []
index = 0
while True:
c = fn2(index)
if c == 0:
break
lst.append(chr(c))
index += 1
s = ''.join(lst)
print s
assert s.startswith('MSC ') or s.startswith('GCC ')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment