[pypy-svn] r75269 - in pypy/trunk/pypy/translator: platform tool tool/test
afa at codespeak.net
afa at codespeak.net
Fri Jun 11 15:22:38 CEST 2010
Author: afa
Date: Fri Jun 11 15:22:37 2010
New Revision: 75269
Modified:
pypy/trunk/pypy/translator/platform/__init__.py
pypy/trunk/pypy/translator/platform/darwin.py
pypy/trunk/pypy/translator/platform/posix.py
pypy/trunk/pypy/translator/platform/windows.py
pypy/trunk/pypy/translator/tool/cbuild.py
pypy/trunk/pypy/translator/tool/test/test_cbuild.py
Log:
Move the generation of the "-exported_symbols_list" to the platform package,
and merge it with the Windows "/EXPORT:xxx" feature
on Windows, this gives shorter command lines,
and also fix the generation of the Makefile.
Modified: pypy/trunk/pypy/translator/platform/__init__.py
==============================================================================
--- pypy/trunk/pypy/translator/platform/__init__.py (original)
+++ pypy/trunk/pypy/translator/platform/__init__.py Fri Jun 11 15:22:37 2010
@@ -5,6 +5,7 @@
import sys, py, os
+from pypy.tool.udir import udir
from pypy.tool.ansi_print import ansi_log
log = py.log.Producer("platform")
py.log.setconsumer("platform", ansi_log)
@@ -123,6 +124,18 @@
for line in stderr.splitlines():
log.WARNING(line)
+ def _make_response_file(self, prefix):
+ """Creates a temporary file with the specified prefix,
+ and returns its name"""
+ # Build unique filename
+ num = 0
+ while 1:
+ response_file = udir.join('%s%i' % (prefix, num))
+ num += 1
+ if not response_file.check():
+ break
+ return response_file
+
def _preprocess_include_dirs(self, include_dirs):
return include_dirs
@@ -144,9 +157,15 @@
library_dirs = self._libdirs(library_dirs)
libraries = self._libs(eci.libraries)
link_files = self._linkfiles(eci.link_files)
- return (library_dirs + self.link_flags +
+ export_flags = self._exportsymbols_link_flags(eci)
+ return (library_dirs + self.link_flags + export_flags +
link_files + list(eci.link_extra) + libraries)
+ def _exportsymbols_link_flags(self, eci):
+ if eci.export_symbols:
+ raise ValueError("This platform does not support export symbols")
+ return []
+
def _finish_linking(self, ofiles, eci, outputfilename, standalone):
if outputfilename is None:
outputfilename = ofiles[0].purebasename
Modified: pypy/trunk/pypy/translator/platform/darwin.py
==============================================================================
--- pypy/trunk/pypy/translator/platform/darwin.py (original)
+++ pypy/trunk/pypy/translator/platform/darwin.py Fri Jun 11 15:22:37 2010
@@ -56,6 +56,17 @@
include_dirs = self._includedirs(eci.include_dirs)
return (args + frameworks + include_dirs)
+ def _exportsymbols_link_flags(self, eci):
+ if not eci.export_symbols:
+ return []
+
+ response_file = self._make_response_file("dynamic-symbols-")
+ f = response_file.open("w")
+ for sym in eci.export_symbols:
+ f.write("_%s\n" % (sym,))
+ f.close()
+ return ["-Wl,-exported_symbols_list,%s" % (response_file,)]
+
class Darwin_i386(Darwin):
name = "darwin_i386"
link_flags = ['-arch', 'i386', '-mmacosx-version-min=10.4']
Modified: pypy/trunk/pypy/translator/platform/posix.py
==============================================================================
--- pypy/trunk/pypy/translator/platform/posix.py (original)
+++ pypy/trunk/pypy/translator/platform/posix.py Fri Jun 11 15:22:37 2010
@@ -37,9 +37,21 @@
return oname
def _link_args_from_eci(self, eci, standalone):
- eci = eci.convert_exportsymbols_to_file()
return Platform._link_args_from_eci(self, eci, standalone)
+ def _exportsymbols_link_flags(self, eci):
+ if not eci.export_symbols:
+ return []
+
+ response_file = self._make_response_file("dynamic-symbols-")
+ f = response_file.open("w")
+ f.write("{\n")
+ for sym in eci.export_symbols:
+ f.write("%s;\n" % (sym,))
+ f.write("};")
+ f.close()
+ return ["-Wl,--export-dynamic,--version-script=%s" % (response_file,)]
+
def _link(self, cc, ofiles, link_args, standalone, exe_name):
args = [str(ofile) for ofile in ofiles] + link_args
args += ['-o', str(exe_name)]
@@ -61,7 +73,6 @@
def gen_makefile(self, cfiles, eci, exe_name=None, path=None,
shared=False):
- eci = eci.convert_exportsymbols_to_file()
cfiles = [py.path.local(f) for f in cfiles]
cfiles += [py.path.local(f) for f in eci.separate_module_files]
@@ -77,6 +88,8 @@
if shared:
linkflags = self._args_for_shared(linkflags)
+ linkflags += self._exportsymbols_link_flags(eci)
+
if shared:
libname = exe_name.new(ext='').basename
target_name = 'lib' + exe_name.new(ext=self.so_ext).basename
Modified: pypy/trunk/pypy/translator/platform/windows.py
==============================================================================
--- pypy/trunk/pypy/translator/platform/windows.py (original)
+++ pypy/trunk/pypy/translator/platform/windows.py Fri Jun 11 15:22:37 2010
@@ -139,8 +139,18 @@
def _link_args_from_eci(self, eci, standalone):
# Windows needs to resolve all symbols even for DLLs
- args = super(MsvcPlatform, self)._link_args_from_eci(eci, standalone=True)
- return args + ['/EXPORT:%s' % symbol for symbol in eci.export_symbols]
+ return super(MsvcPlatform, self)._link_args_from_eci(eci, standalone=True)
+
+ def _exportsymbols_link_flags(self, eci):
+ if not eci.export_symbols:
+ return []
+
+ response_file = self._make_response_file("exported_symbols_")
+ f = response_file.open("w")
+ for sym in eci.export_symbols:
+ f.write("/EXPORT:%s\n" % (sym,))
+ f.close()
+ return ["@%s" % (response_file,)]
def _compile_c_file(self, cc, cfile, compile_args):
oname = cfile.new(ext='obj')
@@ -179,7 +189,7 @@
# Microsoft compilers write compilation errors to stdout
stderr = stdout + stderr
errorfile = outname.new(ext='errors')
- errorfile.write(stderr)
+ errorfile.write(stderr, mode='wb')
stderrlines = stderr.splitlines()
for line in stderrlines:
log.ERROR(line)
@@ -207,6 +217,7 @@
if shared:
linkflags = self._args_for_shared(linkflags) + [
'/EXPORT:$(PYPY_MAIN_FUNCTION)']
+ linkflags += self._exportsymbols_link_flags(eci)
if shared:
so_name = exe_name.new(ext=self.so_ext)
@@ -243,6 +254,7 @@
('LDFLAGSEXTRA', list(eci.link_extra)),
('CC', self.cc),
('CC_LINK', self.link),
+ ('LINKFILES', eci.link_files),
('MASM', self.masm),
]
@@ -262,7 +274,7 @@
'$(CC_LINK) /nologo $(LDFLAGS) $(LDFLAGSEXTRA) $(OBJECTS) /out:$@ $(LIBDIRS) $(LIBS)')
else:
m.rule('$(TARGET)', '$(OBJECTS)',
- ['$(CC_LINK) /nologo $(LDFLAGS) $(LDFLAGSEXTRA) $(OBJECTS) /out:$@ $(LIBDIRS) $(LIBS) /MANIFESTFILE:$*.manifest',
+ ['$(CC_LINK) /nologo $(LDFLAGS) $(LDFLAGSEXTRA) $(OBJECTS) $(LINKFILES) /out:$@ $(LIBDIRS) $(LIBS) /MANIFESTFILE:$*.manifest',
'mt.exe -nologo -manifest $*.manifest -outputresource:$@;1',
])
Modified: pypy/trunk/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/trunk/pypy/translator/tool/cbuild.py (original)
+++ pypy/trunk/pypy/translator/tool/cbuild.py Fri Jun 11 15:22:37 2010
@@ -260,34 +260,6 @@
d['separate_module_files'] += tuple(files)
return ExternalCompilationInfo(**d)
- def convert_exportsymbols_to_file(self):
- if not self.export_symbols:
- return self
- num = 0
- while 1:
- file_name = udir.join('dynamic-symbols-%i' % num)
- num += 1
- if not file_name.check():
- break
-
- # XXX this logic should be moved to translator/platform/*.py
- d = self._copy_attributes()
- f = file_name.open("w")
- if host.name.startswith('darwin'):
- for sym in self.export_symbols:
- f.write("_%s\n" % (sym,))
- d['link_extra'] += ("-Wl,-exported_symbols_list,"+str(file_name), )
- else:
- f.write("{\n")
- for sym in self.export_symbols:
- f.write("%s;\n" % (sym,))
- f.write("};")
- d['link_extra'] += ("-Wl,--export-dynamic,--version-script=" + str(file_name), )
- f.close()
- d['export_symbols'] = ()
- return ExternalCompilationInfo(**d)
-
-
def get_module_files(self):
d = self._copy_attributes()
files = d['separate_module_files']
Modified: pypy/trunk/pypy/translator/tool/test/test_cbuild.py
==============================================================================
--- pypy/trunk/pypy/translator/tool/test/test_cbuild.py (original)
+++ pypy/trunk/pypy/translator/tool/test/test_cbuild.py Fri Jun 11 15:22:37 2010
@@ -71,17 +71,6 @@
e = ExternalCompilationInfo()
assert e.convert_sources_to_files() is e
- def test_convert_sources_to_c_files(self):
- eci = ExternalCompilationInfo(
- export_symbols=("foo", )
- )
- neweci = eci.convert_exportsymbols_to_file()
- le = neweci.link_extra[-1]
- assert "foo;" in file(le.rsplit("=", 1)[1]).read()
- e = ExternalCompilationInfo()
- assert e.convert_exportsymbols_to_file() is e
-
-
def test_make_shared_lib(self):
eci = ExternalCompilationInfo(
separate_module_sources = ['''
More information about the Pypy-commit
mailing list