Пример #1
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
Пример #2
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
Пример #3
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
Пример #4
0
        except Exception, e:
            print >> sys.stderr, 'error: Launching', args, ':', e
            raise e
        (stdout, stderr) = proc.communicate()
        if proc.returncode and not options.verbose:
            print_command(sys.stderr, args)
        sys.stderr.write(stdout)
        sys.stderr.flush()
        if proc.returncode:
            exit(proc.returncode)
    if not options.depend:
        return
    ensureParentDir(options.depend)
    mk = Makefile()
    deps = [
        dep for dep in deps if os.path.isfile(dep) and dep != options.target
    ]
    no_dynamic_lib = [dep for dep in deps if not isDynamicLib(dep)]
    mk.create_rule([options.target]).add_dependencies(no_dynamic_lib)
    if len(deps) != len(no_dynamic_lib):
        mk.create_rule(['%s_order_only' % options.target
                        ]).add_dependencies(dep for dep in deps
                                            if isDynamicLib(dep))

    with open(options.depend, 'w') as depfile:
        mk.dump(depfile, removal_guard=True)


if __name__ == '__main__':
    main()
Пример #5
0
        if options.verbose:
            print_command(sys.stderr, args)
        try:
            proc = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        except Exception, e:
            print >>sys.stderr, 'error: Launching', args, ':', e
            raise e
        (stdout, stderr) = proc.communicate()
        if proc.returncode and not options.verbose:
            print_command(sys.stderr, args)
        sys.stderr.write(stdout)
        sys.stderr.flush()
        if proc.returncode:
            exit(proc.returncode)
    if not options.depend:
        return
    ensureParentDir(options.depend)
    mk = Makefile()
    deps = [dep for dep in deps if os.path.isfile(dep) and dep != options.target
            and os.path.abspath(dep) != os.path.abspath(options.depend)]
    no_dynamic_lib = [dep for dep in deps if not isDynamicLib(dep)]
    mk.create_rule([options.target]).add_dependencies(no_dynamic_lib)
    if len(deps) != len(no_dynamic_lib):
        mk.create_rule(['%s_order_only' % options.target]).add_dependencies(dep for dep in deps if isDynamicLib(dep))

    with open(options.depend, 'w') as depfile:
        mk.dump(depfile, removal_guard=True)

if __name__ == '__main__':
    main()