summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndoni Morales Alastruey <ylatuya@gmail.com>2013-04-12 21:11:50 +0200
committerAndoni Morales Alastruey <ylatuya@gmail.com>2013-04-16 17:42:47 +0200
commit67eb9e16f04a99c9a5c9ecc03799b5f7071c41a7 (patch)
tree6ee2c18ee95f130ff46c76f22ecbb827a70c7f5a
parenta7af02a1f31e442e4c2f67e489de25b6b72e9be5 (diff)
fwlib: fix extration of object files with duplicated names
-rw-r--r--cerbero/ide/xcode/fwlib.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/cerbero/ide/xcode/fwlib.py b/cerbero/ide/xcode/fwlib.py
index f98d0d3..bbb09cf 100644
--- a/cerbero/ide/xcode/fwlib.py
+++ b/cerbero/ide/xcode/fwlib.py
@@ -20,6 +20,7 @@
import os
import tempfile
import shutil
+from collections import defaultdict
from cerbero.config import Architecture
from cerbero.ide.pkgconfig import PkgConfig
@@ -107,6 +108,32 @@ class StaticFrameworkLibrary(FrameworkLibrary):
tmplib = os.path.join (lib_tmpdir, newname)
shell.call('ar -x %s' % tmplib, lib_tmpdir)
+
+ # object files with the same name in an archive are overwritten
+ # when they are extracted. osx's ar does not support the N count
+ # modifier so after extracting all the files we remove them from
+ # the archive to extract those with duplicated names.
+ # eg:
+ # ar t libavcodec.a -> mlpdsp.o mlpdsp.o (2 objects with the same name)
+ # ar d libavcodec.a mlpdsp.o (we remove the first one)
+ # ar t libavcodec.a -> mlpdsp.o (we only the second one now)
+ files = shell.check_call('ar -t %s' % tmplib, lib_tmpdir).split('\n')
+ # FIXME: We should use collections.Count but it's only available in
+ # python 2.7+
+ dups = defaultdict(int)
+ for f in files:
+ dups[f] += 1
+ for f in dups:
+ if dups[f] <= 1:
+ continue
+ for x in range(dups[f]):
+ path = os.path.join(lib_tmpdir, f)
+ new_path = os.path.join(lib_tmpdir, 'dup%d_' % x + f)
+ # The duplicated overwrote the first one, so extract it again
+ shell.call('ar -x %s %s' % (tmplib, f), lib_tmpdir)
+ shutil.move (path, new_path)
+ shell.call('ar -d %s %s' % (tmplib, f), lib_tmpdir)
+
return lib_tmpdir
def _create_framework_library(self, libraries):