def reorder(self, order_list):
     '''Given a list of file names without OBJ_SUFFIX, rearrange self
     so that the object file names it contains are ordered according to
     that list.
     '''
     objs = [o for o in self if isObject(o)]
     if not objs: return
     idx = self.index(objs[0])
     # Keep everything before the first object, then the ordered objects,
     # then any other objects, then any non-objects after the first object
     objnames = dict([(os.path.splitext(os.path.basename(o))[0], o) for o in objs])
     self[0:] = self[0:idx] + [objnames[o] for o in order_list if o in objnames] + \
                [o for o in objs if os.path.splitext(os.path.basename(o))[0] not in order_list] + \
                [x for x in self[idx:] if not isObject(x)]
Example #2
0
 def reorder(self, order_list):
     '''Given a list of file names without OBJ_SUFFIX, rearrange self
     so that the object file names it contains are ordered according to
     that list.
     '''
     objs = [o for o in self if isObject(o)]
     if not objs: return
     idx = self.index(objs[0])
     # Keep everything before the first object, then the ordered objects,
     # then any other objects, then any non-objects after the first object
     objnames = dict([(os.path.splitext(os.path.basename(o))[0], o)
                      for o in objs])
     self[0:] = self[0:idx] + [objnames[o] for o in order_list if o in objnames] + \
                [o for o in objs if os.path.splitext(os.path.basename(o))[0] not in order_list] + \
                [x for x in self[idx:] if not isObject(x)]
 def _getOrderedSections(self, ordered_symbols):
     '''Given an ordered list of symbols, returns the corresponding list
     of sections following the order.'''
     if not conf.EXPAND_LIBS_ORDER_STYLE in [
             'linkerscript', 'section-ordering-file'
     ]:
         raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' %
                         conf.EXPAND_LIBS_ORDER_STYLE)
     finder = SectionFinder([
         arg for arg in self
         if isObject(arg) or os.path.splitext(arg)[1] == conf.LIB_SUFFIX
     ])
     folded = self._getFoldedSections()
     sections = set()
     ordered_sections = []
     for symbol in ordered_symbols:
         symbol_sections = finder.getSections(symbol)
         all_symbol_sections = []
         for section in symbol_sections:
             if section in folded:
                 if isinstance(folded[section], str):
                     section = folded[section]
                 all_symbol_sections.append(section)
                 all_symbol_sections.extend(folded[section])
             else:
                 all_symbol_sections.append(section)
         for section in all_symbol_sections:
             if not section in sections:
                 ordered_sections.append(section)
                 sections.add(section)
     return ordered_sections
 def _getOrderedSections(self, ordered_symbols):
     '''Given an ordered list of symbols, returns the corresponding list
     of sections following the order.'''
     if conf.EXPAND_LIBS_ORDER_STYLE not in ['linkerscript',
                                             'section-ordering-file']:
         raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
                         .format(conf.EXPAND_LIBS_ORDER_STYLE))
     finder = SectionFinder([arg for arg in self 
                             if isObject(arg) or 
                             os.path.splitext(arg)[1] == conf.LIB_SUFFIX])
     folded = self._getFoldedSections()
     sections = set()
     ordered_sections = []
     for symbol in ordered_symbols:
         symbol_sections = finder.getSections(symbol)
         all_symbol_sections = []
         for section in symbol_sections:
             if section in folded:
                 if isinstance(folded[section], str):
                     section = folded[section]
                 all_symbol_sections.append(section)
                 all_symbol_sections.extend(folded[section])
             else:
                 all_symbol_sections.append(section)
         for section in all_symbol_sections:
             if not section in sections:
                 ordered_sections.append(section)
                 sections.add(section)
     return ordered_sections
 def makelist(self):
     '''Replaces object file names with a temporary list file, using a
     list format depending on the EXPAND_LIBS_LIST_STYLE variable
     '''
     objs = [o for o in self if isObject(o)]
     if not len(objs): return
     fd, tmp = tempfile.mkstemp(suffix=".list", dir=os.curdir)
     if conf.EXPAND_LIBS_LIST_STYLE == "linkerscript":
         content = ['INPUT("%s")\n' % obj for obj in objs]
         ref = tmp
     elif conf.EXPAND_LIBS_LIST_STYLE == "filelist":
         content = ["%s\n" % obj for obj in objs]
         ref = "-Wl,-filelist," + tmp
     elif conf.EXPAND_LIBS_LIST_STYLE == "list":
         content = ["%s\n" % obj for obj in objs]
         ref = "@" + tmp
     else:
         os.close(fd)
         os.remove(tmp)
         return
     self.tmp.append(tmp)
     f = os.fdopen(fd, "w")
     f.writelines(content)
     f.close()
     idx = self.index(objs[0])
     newlist = self[0:idx] + [ref] + [
         item for item in self[idx:] if item not in objs
     ]
     self[0:] = newlist
Example #6
0
 def _extract(self, args):
     '''When a static library name is found, either extract its contents
     in a temporary directory or use the information found in the
     corresponding lib descriptor.
     '''
     ar_extract = conf.AR_EXTRACT.split()
     newlist = []
     for arg in args:
         if os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
             if os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
                 newlist += self._extract(self._expand_desc(arg))
             elif os.path.exists(arg) and len(ar_extract):
                 tmp = tempfile.mkdtemp(dir=os.curdir)
                 self.tmp.append(tmp)
                 subprocess.call(ar_extract + [os.path.abspath(arg)],
                                 cwd=tmp)
                 objs = []
                 for root, dirs, files in os.walk(tmp):
                     objs += [
                         relativize(os.path.join(root, f)) for f in files
                         if isObject(f)
                     ]
                 newlist += objs
             else:
                 newlist += [arg]
         else:
             newlist += [arg]
     return newlist
Example #7
0
 def _extract(self, args):
     '''When a static library name is found, either extract its contents
     in a temporary directory or use the information found in the
     corresponding lib descriptor.
     '''
     ar_extract = conf.AR_EXTRACT.split()
     newlist = []
     for arg in args:
         if os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
             if os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
                 newlist += self._extract(self._expand_desc(arg))
                 continue
             elif os.path.exists(arg) and (len(ar_extract) or conf.AR == 'lib'):
                 tmp = tempfile.mkdtemp(dir=os.curdir)
                 self.tmp.append(tmp)
                 if conf.AR == 'lib':
                     out = subprocess.check_output([conf.AR, '-NOLOGO', '-LIST', arg])
                     files = out.splitlines()
                     # If lib -list returns a list full of dlls, it's an
                     # import lib.
                     if all(isDynamicLib(f) for f in files):
                         newlist += [arg]
                         continue
                     for f in files:
                         subprocess.call([conf.AR, '-NOLOGO', '-EXTRACT:%s' % f, os.path.abspath(arg)], cwd=tmp)
                 else:
                     subprocess.call(ar_extract + [os.path.abspath(arg)], cwd=tmp)
                 objs = []
                 for root, dirs, files in os.walk(tmp):
                     objs += [relativize(os.path.join(root, f)) for f in files if isObject(f)]
                 newlist += sorted(objs)
                 continue
         newlist += [arg]
     return newlist
Example #8
0
 def makelist(self):
     '''Replaces object file names with a temporary list file, using a
     list format depending on the EXPAND_LIBS_LIST_STYLE variable
     '''
     objs = [o for o in self if isObject(o)]
     if not len(objs): return
     fd, tmp = tempfile.mkstemp(suffix=".list",dir=os.curdir)
     if conf.EXPAND_LIBS_LIST_STYLE == "linkerscript":
         content = ['INPUT("%s")\n' % obj for obj in objs]
         ref = tmp
     elif conf.EXPAND_LIBS_LIST_STYLE == "filelist":
         content = ["%s\n" % obj for obj in objs]
         ref = "-Wl,-filelist," + tmp
     elif conf.EXPAND_LIBS_LIST_STYLE == "list":
         content = ["%s\n" % obj for obj in objs]
         ref = "@" + tmp
     else:
         os.close(fd)
         os.remove(tmp)
         return
     self.tmp.append(tmp)
     f = os.fdopen(fd, "w")
     f.writelines(content)
     f.close()
     idx = self.index(objs[0])
     newlist = self[0:idx] + [ref] + [item for item in self[idx:] if item not in objs]
     self[0:] = newlist
Example #9
0
def generate(args):
    desc = LibDescriptor()
    for arg in args:
        if isObject(arg):
            desc['OBJS'].append(os.path.abspath(arg))
        elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX and \
             (os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX)):
            desc['LIBS'].append(os.path.abspath(arg))
    return desc
Example #10
0
def generate(args):
    desc = LibDescriptor()
    for arg in args:
        if isObject(arg):
            desc['OBJS'].append(os.path.abspath(arg))
        elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX and \
             (os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX)):
            desc['LIBS'].append(os.path.abspath(arg))
    return desc
Example #11
0
    def _extract(self, args):
        '''When a static library name is found, either extract its contents
        in a temporary directory or use the information found in the
        corresponding lib descriptor.
        '''
        ar_extract = conf.AR_EXTRACT.split()
        newlist = []

        def lookup(base, f):
            for root, dirs, files in os.walk(base):
                if f in files:
                    return os.path.join(root, f)

        for arg in args:
            if os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
                if os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
                    newlist += self._extract(self._expand_desc(arg))
                    continue
                elif os.path.exists(arg) and (len(ar_extract) or conf.AR == 'lib'):
                    tmp = tempfile.mkdtemp(dir=os.curdir)
                    self.tmp.append(tmp)
                    if conf.AR == 'lib':
                        out = subprocess.check_output([conf.AR, '-NOLOGO', '-LIST', arg])
                        files = out.splitlines()
                        # If lib -list returns a list full of dlls, it's an
                        # import lib.
                        if all(isDynamicLib(f) for f in files):
                            newlist += [arg]
                            continue
                        for f in files:
                            subprocess.call([conf.AR, '-NOLOGO', '-EXTRACT:%s' % f, os.path.abspath(arg)], cwd=tmp)
                    else:
                        subprocess.call(ar_extract + [os.path.abspath(arg)], cwd=tmp)
                    objs = []
                    basedir = os.path.dirname(arg)
                    for root, dirs, files in os.walk(tmp):
                        for f in files:
                            if isObject(f):
                                # If the file extracted from the library also
                                # exists in the directory containing the
                                # library, or one of its subdirectories, use
                                # that instead.
                                maybe_obj = lookup(os.path.join(basedir, os.path.relpath(root, tmp)), f)
                                if maybe_obj:
                                    objs.append(relativize(maybe_obj))
                                else:
                                    objs.append(relativize(os.path.join(root, f)))
                    newlist += sorted(objs)
                    continue
            newlist += [arg]
        return newlist
def generate(args):
    desc = LibDescriptor()
    for arg in args:
        if isObject(arg):
            if os.path.exists(arg):
                desc['OBJS'].append(os.path.abspath(arg))
            else:
                raise Exception("File not found: %s" % arg)
        elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
            if os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
                desc['LIBS'].append(os.path.abspath(arg))
            else:
                raise Exception("File not found: %s" % arg)
    return desc
Example #13
0
 def __init__(self, objs):
     '''Creates an instance, given a list of object files.'''
     if not conf.EXPAND_LIBS_ORDER_STYLE in ['linkerscript', 'section-ordering-file']:
         raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
     self.mapping = {}
     for obj in objs:
         if not isObject(obj) and os.path.splitext(obj)[1] != conf.LIB_SUFFIX:
             raise Exception('%s is not an object nor a static library' % obj)
         for symbol, section in SectionFinder._getSymbols(obj):
             sym = SectionFinder._normalize(symbol)
             if sym in self.mapping:
                 if not section in self.mapping[sym]:
                     self.mapping[sym].append(section)
             else:
                 self.mapping[sym] = [section]
def generate(args):
    desc = LibDescriptor()
    for arg in args:
        if isObject(arg):
            if os.path.exists(arg):
                desc['OBJS'].append(os.path.abspath(arg))
            else:
                raise Exception("File not found: %s" % arg)
        elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
            if os.path.exists(arg) or os.path.exists(arg +
                                                     conf.LIBS_DESC_SUFFIX):
                desc['LIBS'].append(os.path.abspath(arg))
            else:
                raise Exception("File not found: %s" % arg)
    return desc
Example #15
0
 def __init__(self, objs):
     '''Creates an instance, given a list of object files.'''
     if not conf.EXPAND_LIBS_ORDER_STYLE in ['linkerscript', 'section-ordering-file']:
         raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
     self.mapping = {}
     for obj in objs:
         if not isObject(obj) and os.path.splitext(obj)[1] != conf.LIB_SUFFIX:
             raise Exception('%s is not an object nor a static library' % obj)
         for symbol, section in SectionFinder._getSymbols(obj):
             sym = SectionFinder._normalize(symbol)
             if sym in self.mapping:
                 if not section in self.mapping[sym]:
                     self.mapping[sym].append(section)
             else:
                 self.mapping[sym] = [section]
Example #16
0
 def _extract(self, args):
     '''When a static library name is found, either extract its contents
     in a temporary directory or use the information found in the
     corresponding lib descriptor.
     '''
     ar_extract = conf.AR_EXTRACT.split()
     newlist = []
     for arg in args:
         if os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
             if os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
                 newlist += self._extract(self._expand_desc(arg))
                 continue
             elif os.path.exists(arg) and (len(ar_extract)
                                           or conf.AR == 'lib'):
                 tmp = tempfile.mkdtemp(dir=os.curdir)
                 self.tmp.append(tmp)
                 if conf.AR == 'lib':
                     out = subprocess.check_output(
                         [conf.AR, '-NOLOGO', '-LIST', arg])
                     files = out.splitlines()
                     # If lib -list returns a list full of dlls, it's an
                     # import lib.
                     if all(isDynamicLib(f) for f in files):
                         newlist += [arg]
                         continue
                     for f in files:
                         subprocess.call([
                             conf.AR, '-NOLOGO',
                             '-EXTRACT:%s' % f,
                             os.path.abspath(arg)
                         ],
                                         cwd=tmp)
                 else:
                     subprocess.call(ar_extract + [os.path.abspath(arg)],
                                     cwd=tmp)
                 objs = []
                 for root, dirs, files in os.walk(tmp):
                     objs += [
                         relativize(os.path.join(root, f)) for f in files
                         if isObject(f)
                     ]
                 newlist += sorted(objs)
                 continue
         newlist += [arg]
     return newlist
Example #17
0
def generate(args):
    desc = LibDescriptor()
    for arg in args:
        if isObject(arg):
            if os.path.exists(arg):
                desc['OBJS'].append(os.path.abspath(arg))
            else:
                raise Exception("File not found: %s" % arg)
        elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
            # We want to skip static libraries with the name foo-rs-prelink
            # as they are individually linked for every final library, and
            # thus should not be included in the descriptor file
            if '-rs-prelink' in os.path.basename(arg):
                continue
            if os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
                desc['LIBS'].append(os.path.abspath(arg))
            else:
                raise Exception("File not found: %s" % arg)
    return desc
Example #18
0
def generate(args):
    desc = LibDescriptor()
    for arg in args:
        if isObject(arg):
            if os.path.exists(arg):
                desc['OBJS'].append(os.path.abspath(arg))
            else:
                raise Exception("File not found: %s" % arg)
        elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
            # We want to skip static libraries with the name foo-rs-prelink
            # as they are individually linked for every final library, and
            # thus should not be included in the descriptor file
            if '-rs-prelink' in os.path.basename(arg):
                continue
            if os.path.exists(arg) or os.path.exists(arg +
                                                     conf.LIBS_DESC_SUFFIX):
                desc['LIBS'].append(os.path.abspath(arg))
            else:
                raise Exception("File not found: %s" % arg)
    return desc
 def _extract(self, args):
     '''When a static library name is found, either extract its contents
     in a temporary directory or use the information found in the
     corresponding lib descriptor.
     '''
     ar_extract = conf.AR_EXTRACT.split()
     newlist = []
     for arg in args:
         if os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
             if os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
                 newlist += self._extract(self._expand_desc(arg))
             elif os.path.exists(arg) and len(ar_extract):
                 tmp = tempfile.mkdtemp(dir=os.curdir)
                 self.tmp.append(tmp)
                 subprocess.call(ar_extract + [os.path.abspath(arg)], cwd=tmp)
                 objs = []
                 for root, dirs, files in os.walk(tmp):
                     objs += [relativize(os.path.join(root, f)) for f in files if isObject(f)]
                 newlist += objs
             else:
                 newlist += [arg]
         else:
             newlist += [arg]
     return newlist