[pypy-svn] r59121 - in pypy/branch/cbuild-refactor/pypy/translator/platform: . test
fijal at codespeak.net
fijal at codespeak.net
Thu Oct 16 00:04:30 CEST 2008
Author: fijal
Date: Thu Oct 16 00:04:30 2008
New Revision: 59121
Modified:
pypy/branch/cbuild-refactor/pypy/translator/platform/maemo.py
pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_posix.py
Log:
Some support for makefiles on maemo. Note that makefile is supposed to be run
from outside scratchbox. I'm completely unsure whether this approach make any
sense, experimenting.
Modified: pypy/branch/cbuild-refactor/pypy/translator/platform/maemo.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/translator/platform/maemo.py (original)
+++ pypy/branch/cbuild-refactor/pypy/translator/platform/maemo.py Thu Oct 16 00:04:30 2008
@@ -1,7 +1,8 @@
import py
-from pypy.translator.platform.linux import Linux, _run_subprocess
+from pypy.translator.platform.linux import Linux, _run_subprocess, GnuMakefile
from pypy.translator.platform import ExecutionResult, log
from pypy.tool.udir import udir
+from pypy.tool import autopath
def check_scratchbox():
if not py.path.local('/scratchbox/login').check():
@@ -74,3 +75,55 @@
def library_dirs_for_libffi(self):
# on the other hand, library lands in usual place...
return []
+
+
+ def gen_makefile(self, cfiles, eci, exe_name=None, path=None):
+ cfiles = [py.path.local(f) for f in cfiles]
+ cfiles += [py.path.local(f) for f in eci.separate_module_files]
+
+ if path is None:
+ path = cfiles[0].dirpath()
+
+ pypypath = py.path.local(autopath.pypydir)
+
+ if exe_name is None:
+ exe_name = cfiles[0].new(ext='')
+
+ m = GnuMakefile(path)
+ m.exe_name = exe_name
+ m.eci = eci
+
+ rel_cfiles = [str(cfile) for cfile in cfiles]
+ rel_ofiles = [rel_cfile[:-2]+'.o' for rel_cfile in rel_cfiles]
+ m.cfiles = rel_cfiles
+
+ rel_includedirs = [str(incldir) for incldir in
+ self._preprocess_dirs(eci.include_dirs)]
+
+ m.comment('automatically generated makefile')
+ definitions = [
+ ('TARGET', str(exe_name)),
+ ('DEFAULT_TARGET', '$(TARGET)'),
+ ('SOURCES', rel_cfiles),
+ ('OBJECTS', rel_ofiles),
+ ('LIBS', self._libs(eci.libraries)),
+ ('LIBDIRS', self._libdirs(eci.library_dirs)),
+ ('INCLUDEDIRS', self._includedirs(rel_includedirs)),
+ ('CFLAGS', self.cflags + list(eci.compile_extra)),
+ ('LDFLAGS', self.link_flags + list(eci.link_extra)),
+ ('CC', '/scratchbox/login ' + self.cc)
+ ]
+ for args in definitions:
+ m.definition(*args)
+
+ rules = [
+ ('all', '$(DEFAULT_TARGET)', []),
+ ('$(TARGET)', '$(OBJECTS)', '$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS)'),
+ ('%.o', '%.c', '$(CC) $(CFLAGS) -o $@ -c $< $(INCLUDEDIRS)'),
+ ]
+
+ for rule in rules:
+ m.rule(*rule)
+
+ return m
+
Modified: pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_posix.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_posix.py (original)
+++ pypy/branch/cbuild-refactor/pypy/translator/platform/test/test_posix.py Thu Oct 16 00:04:30 2008
@@ -9,24 +9,36 @@
assert res.out == '42 24\n'
res = host.execute('echo', ['42', '24'])
assert res.out == '42 24\n'
+
+class TestMakefile(object):
+ platform = host
+ strict_on_stderr = True
-def test_simple_makefile():
- tmpdir = udir.join('simple_makefile').ensure(dir=1)
- cfile = tmpdir.join('test_simple_enough.c')
- cfile.write('''
- #include <stdio.h>
- int main()
- {
- printf("42\\n");
- return 0;
- }
- ''')
- mk = host.gen_makefile([cfile], ExternalCompilationInfo(),
- path=tmpdir)
- mk.write()
- host.execute_makefile(mk)
- res = host.execute(tmpdir.join('test_simple_enough'))
- assert res.out == '42\n'
- assert res.err == ''
- assert res.returncode == 0
+ def test_simple_makefile(self):
+ tmpdir = udir.join('simple_makefile' + self.__class__.__name__).ensure(dir=1)
+ cfile = tmpdir.join('test_simple_enough.c')
+ cfile.write('''
+ #include <stdio.h>
+ int main()
+ {
+ printf("42\\n");
+ return 0;
+ }
+ ''')
+ mk = self.platform.gen_makefile([cfile], ExternalCompilationInfo(),
+ path=tmpdir)
+ mk.write()
+ self.platform.execute_makefile(mk)
+ res = self.platform.execute(tmpdir.join('test_simple_enough'))
+ assert res.out == '42\n'
+ if self.strict_on_stderr:
+ assert res.err == ''
+ assert res.returncode == 0
+class TestMaemo(TestMakefile):
+ strict_on_stderr = False
+
+ def setup_class(cls):
+ from pypy.translator.platform.maemo import check_scratchbox, Maemo
+ check_scratchbox()
+ cls.platform = Maemo()
More information about the Pypy-commit
mailing list