async def create_universal_file(self, output, inputlist, dirs): tmp_inputs = [] # relocate all files with the prefix of the merged file. # which must be done before merging them. for f in inputlist: # keep the filename in the suffix to preserve the filename extension tmp = tempfile.NamedTemporaryFile(suffix=os.path.basename(f)) tmp_inputs.append(tmp) shutil.copy(f, tmp.name) prefix_to_replace = [d for d in dirs if d in f][0] relocator = OSXRelocator(self.output_root, prefix_to_replace, False, logfile=self.logfile) # since we are using a temporary file, we must force the library id # name to real one and not based on the filename relocator.relocate_file(tmp.name) relocator.change_id(tmp.name, id=f.replace(prefix_to_replace, self.output_root)) cmd = [self.LIPO_CMD, '-create'] + [f.name for f in tmp_inputs ] + ['-output', output] shell.new_call(cmd) for tmp in tmp_inputs: tmp.close()
def relocate_osx_libraries(self): ''' Make OSX libraries relocatable ''' relocator = OSXRelocator(self.config.prefix, self.config.prefix, True) for f in self.files_list(): if f.split('/')[0] in ['lib', 'bin', 'libexec']: relocator.relocate_file(os.path.join(self.config.prefix, f))
def _relocate_binaries(self): prefix = self.config.prefix if prefix[-1] == '/': prefix = prefix[:-1] for path in ['bin', 'lib', 'libexec']: relocator = OSXRelocator( os.path.join(self.appdir, 'Contents', 'Home', path), self.config.prefix, '@executable_path/../', True) relocator.relocate()
def _relocate_binaries(self, tmp_dir): if not self.package.relocate_osx_binaries: return prefix = self.config.prefix if prefix[-1] == '/': prefix = prefix[:-1] for path in ['bin', 'lib', 'libexec']: relocator = OSXRelocator(os.path.join(tmp_dir, path), self.config.prefix, '@executable_path/../', True) relocator.relocate()
def relocate_osx_libraries(self): ''' Make OSX libraries relocatable ''' relocator = OSXRelocator(self.config.prefix, self.config.prefix, True) def get_real_path(fp): return os.path.realpath(os.path.join(self.config.prefix, fp)) def file_is_relocatable(fp): return fp.split('/')[0] in ['lib', 'bin', 'libexec'] and \ os.path.splitext(fp)[1] not in ['.a', '.pc', '.la'] # Only relocate files are that are potentially relocatable and # remove duplicates by symbolic links so we relocate libs only # once. for f in set([get_real_path(x) for x in self.files_list() \ if file_is_relocatable(x)]): relocator.relocate_file(f)
def create_universal_file(self, output, inputlist, dirs): tmp_inputs = [] # relocate all files with the prefix of the merged file. # which must be done before merging them. for f in inputlist: # keep the filename in the suffix to preserve the filename extension tmp = tempfile.NamedTemporaryFile(suffix=os.path.basename(f)) tmp_inputs.append(tmp) shutil.copy(f, tmp.name) prefix_to_replace = [d for d in dirs if d in f][0] relocator = OSXRelocator (self.output_root, prefix_to_replace, self.output_root, False) # since we are using a temporary file, we must force the library id # name to real one and not based on the filename relocator.relocate_file(tmp.name, id=f.replace(prefix_to_replace, self.output_root)) cmd = '%s -create %s -output %s' % (self.LIPO_CMD, ' '.join([f.name for f in tmp_inputs]), output) self._call(cmd)
def __init__(self, store, force=False, dry_run=False): self.store = store self.cookbook = store.cookbook self.config = self.cookbook.get_config() self.force = force shell.DRY_RUN = dry_run if not self.config.binaries: raise FatalError(_('Configuration without binaries path')) self.binaries = os.path.join(self.config.binaries, self.config.get_md5()) if not self.config.binary_repo: raise FatalError(_('Configuration without binary repo')) self.binary_repo = os.path.join(self.config.binary_repo, self.config.get_md5()) m.message('Using config MD5: %s' % self.config.get_md5()) if not os.path.exists(self.binaries): os.makedirs(self.binaries) if self.config.target_platform == Platform.DARWIN: self.relocator = OSXRelocator(self.config.prefix, self.config.prefix, True)
def _create_tarball(self, filename, files, package_prefix, relocatable): tar = tarfile.open(filename, "w:bz2") for f in files: filepath = os.path.join(self.prefix, f) arcname = os.path.join(package_prefix, f) if relocatable and not os.path.islink(filepath): if os.path.splitext(f)[1] in [ '.la', '.pc' ] or ('bin' in os.path.splitext(f)[0] and is_text_file(filepath)): with open(filepath, 'r') as fo: content = fo.read() content = replace_prefix(self.config.prefix, content, "CERBERO_PREFIX") rewritten = tempfile.NamedTemporaryFile() rewritten.write(content) rewritten.flush() rewritten.seek(0) tinfo = tar.gettarinfo(arcname=arcname, fileobj=fo) tinfo.size = len(content) tinfo.name = os.path.join(package_prefix, f) tar.addfile(tinfo, rewritten) rewritten.close() elif os.path.splitext(f)[1] in [ '.dylib' ] and self.config.target_platform == Platform.DARWIN: tempdir = tempfile.mkdtemp() os.makedirs(os.path.join(tempdir, os.path.dirname(f))) rewritten = os.path.join(tempdir, f) shutil.copy(filepath, rewritten) relocator = OSXRelocator(self.config.prefix, tempdir, True) relocator.change_id(rewritten) tar.add(rewritten, arcname) shutil.rmtree(tempdir) else: tar.add(filepath, arcname) else: tar.add(filepath, arcname) tar.close()
def _relocate_binaries(self, tmp_dir): if not self.package.relocate_osx_binaries: return relocator = OSXRelocator(tmp_dir, self.config.prefix, True) for path in ['bin', 'lib', 'libexec']: relocator.relocate_dir(path)