| 1 | |
| 2 | from rpython.translator.platform import host, CompilationError |
| 3 | from rpython.translator.tool.cbuild import ExternalCompilationInfo |
| 4 | from rpython.tool.udir import udir |
| 5 | from StringIO import StringIO |
| 6 | import sys, os |
| 7 | |
| 8 | def test_echo(): |
| 9 | res = host.execute('echo', '42 24') |
| 10 | assert res.out == '42 24\n' |
| 11 | |
| 12 | res = host.execute('echo', ['42', '24']) |
| 13 | assert res.out == '42 24\n' |
| 14 | |
| 15 | class TestMakefile(object): |
| 16 | platform = host |
| 17 | strict_on_stderr = True |
| 18 | |
| 19 | def test_simple_makefile(self): |
| 20 | tmpdir = udir.join('simple_makefile' + self.__class__.__name__).ensure(dir=1) |
| 21 | cfile = tmpdir.join('test_simple_enough.c') |
| 22 | cfile.write(''' |
| 23 | #include <stdio.h> |
| 24 | int main() |
| 25 | { |
| 26 | printf("42\\n"); |
| 27 | return 0; |
| 28 | } |
| 29 | ''') |
| 30 | mk = self.platform.gen_makefile([cfile], ExternalCompilationInfo(), |
| 31 | path=tmpdir) |
| 32 | mk.write() |
| 33 | self.platform.execute_makefile(mk) |
| 34 | res = self.platform.execute(tmpdir.join('test_simple_enough')) |
| 35 | assert res.out == '42\n' |
| 36 | if self.strict_on_stderr: |
| 37 | assert res.err == '' |
| 38 | assert res.returncode == 0 |
| 39 | if sys.platform.startswith('linux'): |
| 40 | assert '-lrt' in tmpdir.join("Makefile").read() |
| 41 | |
| 42 | def test_link_files(self): |
| 43 | tmpdir = udir.join('link_files' + self.__class__.__name__).ensure(dir=1) |
| 44 | eci = ExternalCompilationInfo(link_files=['/foo/bar.a']) |
| 45 | mk = self.platform.gen_makefile(['blip.c'], eci, path=tmpdir) |
| 46 | mk.write() |
| 47 | assert 'LINKFILES = /foo/bar.a' in tmpdir.join('Makefile').read() |
| 48 | |
| 49 | def test_preprocess_localbase(self): |
| 50 | tmpdir = udir.join('test_preprocess_localbase').ensure(dir=1) |
| 51 | eci = ExternalCompilationInfo() |
| 52 | os.environ['PYPY_LOCALBASE'] = '/foo/baz' |
| 53 | try: |
| 54 | mk = self.platform.gen_makefile(['blip.c'], eci, path=tmpdir) |
| 55 | mk.write() |
| 56 | finally: |
| 57 | del os.environ['PYPY_LOCALBASE'] |
| 58 | Makefile = tmpdir.join('Makefile').read() |
| 59 | include_prefix = '-I' |
| 60 | lib_prefix = '-L' |
| 61 | if self.platform.name == 'msvc': |
| 62 | include_prefix = '/I' |
| 63 | lib_prefix = '/LIBPATH:' |
| 64 | assert 'INCLUDEDIRS = %s/foo/baz/include' % include_prefix in Makefile |
| 65 | assert 'LIBDIRS = %s/foo/baz/lib' % lib_prefix in Makefile |
| 66 |