def assemble(self): logger.info("Building PKG (CArchive) %s", os.path.basename(self.name)) trash = [] mytoc = [] srctoc = [] seenInms = {} seenFnms = {} seenFnms_typ = {} toc = add_suffix_to_extensions(self.toc) # 'inm' - relative filename inside a CArchive # 'fnm' - absolute filename as it is on the file system. for inm, fnm, typ in toc: # Ensure filename 'fnm' is not None or empty string. Otherwise # it will fail in case of 'typ' being type OPTION. if fnm and not os.path.isfile(fnm) and is_path_to_egg(fnm): # file is contained within python egg, it is added with the egg continue if typ in ('BINARY', 'EXTENSION', 'DEPENDENCY'): if self.exclude_binaries and typ != 'DEPENDENCY': self.dependencies.append((inm, fnm, typ)) else: if typ == 'BINARY': # Avoid importing the same binary extension twice. This might # happen if they come from different sources (eg. once from # binary dependence, and once from direct import). if inm in seenInms: logger.warning( 'Two binaries added with the same internal name.' ) logger.warning(pprint.pformat((inm, fnm, typ))) logger.warning('was placed previously at') logger.warning( pprint.pformat((inm, seenInms[inm], seenFnms_typ[seenInms[inm]]))) logger.warning('Skipping %s.' % fnm) continue # Warn if the same binary extension was included # with multiple internal names if fnm in seenFnms: logger.warning( 'One binary added with two internal names.') logger.warning(pprint.pformat((inm, fnm, typ))) logger.warning('was placed previously at') logger.warning( pprint.pformat( (seenFnms[fnm], fnm, seenFnms_typ[fnm]))) seenInms[inm] = fnm seenFnms[fnm] = inm seenFnms_typ[fnm] = typ fnm = checkCache(fnm, strip=self.strip_binaries, upx=(self.upx_binaries and (is_win or is_cygwin)), dist_nm=inm) mytoc.append((inm, fnm, self.cdict.get(typ, 0), self.xformdict.get(typ, 'b'))) elif typ == 'OPTION': mytoc.append((inm, '', 0, 'o')) elif typ in ('PYSOURCE', 'PYMODULE'): # collect sourcefiles and module in a toc of it's own # which will not be sorted. srctoc.append((inm, fnm, self.cdict[typ], self.xformdict[typ])) else: mytoc.append((inm, fnm, self.cdict.get(typ, 0), self.xformdict.get(typ, 'b'))) # Bootloader has to know the name of Python library. Pass python libname to CArchive. pylib_name = os.path.basename(bindepend.get_python_library_path()) # Sort content alphabetically by type and name to support # reproducible builds. mytoc.sort(key=itemgetter(3, 0)) # Do *not* sort modules and scripts, as their order is important. # TODO: Think about having all modules first and then all scripts. archive = CArchiveWriter(self.name, srctoc + mytoc, pylib_name=pylib_name) for item in trash: os.remove(item) logger.info("Building PKG (CArchive) %s completed successfully.", os.path.basename(self.name))
def assemble(self): logger.info("Building PKG (CArchive) %s", os.path.basename(self.name)) trash = [] mytoc = [] seenInms = {} seenFnms = {} seenFnms_typ = {} toc = add_suffix_to_extensions(self.toc) # 'inm' - relative filename inside a CArchive # 'fnm' - absolute filename as it is on the file system. for inm, fnm, typ in toc: # Ensure filename 'fnm' is not None or empty string. Otherwise # it will fail in case of 'typ' being type OPTION. if fnm and not os.path.isfile(fnm) and is_path_to_egg(fnm): # file is contained within python egg, it is added with the egg continue if typ in ('BINARY', 'EXTENSION', 'DEPENDENCY'): if self.exclude_binaries and typ != 'DEPENDENCY': self.dependencies.append((inm, fnm, typ)) else: if typ == 'BINARY': # Avoid importing the same binary extension twice. This might # happen if they come from different sources (eg. once from # binary dependence, and once from direct import). if inm in seenInms: logger.warn('Two binaries added with the same internal name.') logger.warn(pprint.pformat((inm, fnm, typ))) logger.warn('was placed previously at') logger.warn(pprint.pformat((inm, seenInms[inm], seenFnms_typ[seenInms[inm]]))) logger.warn('Skipping %s.' % fnm) continue # Warn if the same binary extension was included # with multiple internal names if fnm in seenFnms: logger.warn('One binary added with two internal names.') logger.warn(pprint.pformat((inm, fnm, typ))) logger.warn('was placed previously at') logger.warn(pprint.pformat((seenFnms[fnm], fnm, seenFnms_typ[fnm]))) seenInms[inm] = fnm seenFnms[fnm] = inm seenFnms_typ[fnm] = typ fnm = checkCache(fnm, strip=self.strip_binaries, upx=(self.upx_binaries and (is_win or is_cygwin)), dist_nm=inm) mytoc.append((inm, fnm, self.cdict.get(typ, 0), self.xformdict.get(typ, 'b'))) elif typ == 'OPTION': mytoc.append((inm, '', 0, 'o')) else: mytoc.append((inm, fnm, self.cdict.get(typ, 0), self.xformdict.get(typ, 'b'))) # Bootloader has to know the name of Python library. Pass python libname to CArchive. pylib_name = os.path.basename(bindepend.get_python_library_path()) archive = CArchiveWriter(pylib_name=pylib_name) archive.build(self.name, mytoc) for item in trash: os.remove(item)