Tobias Pape avatar Tobias Pape committed 48ee7b6 Merge

Merged in krono/pypy/osx-eci-frameworks-makefile (pull request #195)

OSX: Ensure frameworks end up in Makefile when specified in External compilation info

Comments (0)

Files changed (2)

rpython/translator/platform/darwin.py

             response_file = relto.bestrelpath(response_file)
         return ["-Wl,-exported_symbols_list,%s" % (response_file,)]
 
+    def gen_makefile(self, cfiles, eci, exe_name=None, path=None,
+                     shared=False):
+        # ensure frameworks are passed in the Makefile
+        fs = self._frameworks(eci.frameworks)
+        if len(fs) > 0:
+            # concat (-framework, FrameworkName) pairs
+            self.extra_libs += tuple(map(" ".join, zip(fs[::2], fs[1::2])))
+        mk = super(Darwin, self).gen_makefile(cfiles, eci, exe_name, path,
+                                              shared)
+        return mk
+
+
 class Darwin_i386(Darwin):
     name = "darwin_i386"
     link_flags = ('-arch', 'i386', '-mmacosx-version-min=10.4')

rpython/translator/platform/test/test_darwin.py

         host_factory = Darwin_i386
     else:
         host_factory = Darwin_x86_64
+elif platform.machine() == 'x86_64':
+    host_factory = Darwin_x86_64
 else:
     host_factory = Darwin_PowerPC
 
+def is_x86():
+    return platform.machine() == 'i386' or platform.machine() == 'x86_64'
+
 class TestDarwin(BasicTest):
     platform = host_factory()
 
         res = self.platform.execute(executable)
         self.check_res(res)
 
+    def test_frameworks_with_makefile(self):
+        from StringIO import StringIO
+        tmpdir = udir.join('fw_mk' + self.__class__.__name__).ensure(dir=1)
+        objcfile = tmpdir.join('test_simple.m')
+        objcfile.write(r'''
+        #import <Foundation/Foundation.h>
+        int main (int argc, const char * argv[]) {
+            NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+            NSArray *args = [[NSProcessInfo processInfo] arguments];
+            NSCountedSet *cset = [[NSCountedSet alloc] initWithArray:args];
+
+            printf("%d\n", 23);
+
+            [cset release];
+            [pool release];
+            return 0;
+        }
+        ''')
+        eci = ExternalCompilationInfo(frameworks=('Cocoa',))
+        mk = self.platform.gen_makefile([objcfile], eci, path=tmpdir)
+        # The framework should end up in the Makefile
+        out = StringIO()
+        mk.write(out)
+        assert "-framework Cocoa" in out.getvalue()
+        # check that it actually works
+        mk.write()
+        self.platform.execute_makefile(mk)
+        res = self.platform.execute(tmpdir.join('test_simple'))
+        self.check_res(res, expected="23\n")
+
+
     def test_64_32_results(self):
-        if platform.machine() != 'i386':
+        if not is_x86():
             py.test.skip("i386 only")
         plat32 = Darwin_i386()
         plat64 = Darwin_x86_64()
             self.check_res(res, '1\n')
 
     def test_longsize(self):
-        if platform.machine() != 'i386':
+        if not is_x86():
             py.test.skip("i386 only")
         cfile = udir.join('test_int_size.c')
         cfile.write(r'''
         executable = self.platform.compile([cfile], eci)
         res = self.platform.execute(executable)
         self.check_res(res, str(sys.maxint) + '\n')
-        
+
     def test_32bit_makefile(self):
-        if platform.machine() != 'i386':
+        if not is_x86():
             py.test.skip("i386 only")
         plat32 = Darwin_i386()
         plat64 = Darwin_x86_64()
             plat64.execute_makefile(mk)
             res = plat64.execute(tmpdir.join('test_int_size'))
             self.check_res(res, '1\n')
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.