Exemple #1
0
 def test_relativize(self):
     '''Test relativize()'''
     os_path_exists = os.path.exists
     def exists(path):
         return True
     os.path.exists = exists
     self.assertEqual(relativize(os.path.abspath(os.curdir)), os.curdir)
     self.assertEqual(relativize(os.path.abspath(os.pardir)), os.pardir)
     self.assertEqual(relativize(os.path.join(os.curdir, 'a')), 'a')
     self.assertEqual(relativize(os.path.join(os.path.abspath(os.curdir), 'a')), 'a')
     # relativize is expected to return the absolute path if it is shorter
     self.assertEqual(relativize(os.sep), os.sep)
     os.path.exists = os.path.exists
 def test_relativize(self):
     '''Test relativize()'''
     os_path_exists = os.path.exists
     def exists(path):
         return True
     os.path.exists = exists
     self.assertEqual(relativize(os.path.abspath(os.curdir)), os.curdir)
     self.assertEqual(relativize(os.path.abspath(os.pardir)), os.pardir)
     self.assertEqual(relativize(os.path.join(os.curdir, 'a')), 'a')
     self.assertEqual(relativize(os.path.join(os.path.abspath(os.curdir), 'a')), 'a')
     # relativize is expected to return the absolute path if it is shorter
     self.assertEqual(relativize(os.sep), os.sep)
     os.path.exists = os.path.exists
Exemple #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 = []

        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 test_makelist(self):
        '''Test grouping object files in lists'''
        # ExpandArgsMore does the same as ExpandArgs
        with ExpandArgsMore(['foo', '-bar'] + self.arg_files + [self.tmpfile('liby', Lib('y'))]) as args:
            self.assertRelEqual(args, ['foo', '-bar'] + self.files + self.liby_files + self.libx_files) 

            # But also has an extra method replacing object files with a list
            args.makelist()
            # self.files has objects at #1, #2, #4
            self.assertRelEqual(args[:3], ['foo', '-bar'] + self.files[:1])
            self.assertRelEqual(args[4:], [self.files[3]] + self.files[5:] + [self.tmpfile('liby', Lib('z'))])

            # Check the list file content
            objs = [f for f in self.files + self.liby_files + self.libx_files if f.endswith(config.OBJ_SUFFIX)]
            if config.EXPAND_LIBS_LIST_STYLE == "linkerscript":
                self.assertNotEqual(args[3][0], '@')
                filename = args[3]
                content = ['INPUT("%s")' % relativize(f) for f in objs]
                with open(filename, 'r') as f:
                    self.assertEqual([l.strip() for l in f.readlines() if len(l.strip())], content)
            elif config.EXPAND_LIBS_LIST_STYLE == "list":
                self.assertEqual(args[3][0], '@')
                filename = args[3][1:]
                content = objs
                with open(filename, 'r') as f:
                    self.assertRelEqual([l.strip() for l in f.readlines() if len(l.strip())], content)

            tmp = args.tmp
        # Check that all temporary files are properly removed
        self.assertEqual(True, all([not os.path.exists(f) for f in tmp]))
Exemple #5
0
    def test_makelist(self):
        '''Test grouping object files in lists'''
        # ExpandArgsMore does the same as ExpandArgs
        with ExpandArgsMore(['foo', '-bar'] + self.arg_files + [self.tmpfile('liby', Lib('y'))]) as args:
            self.assertRelEqual(args, ['foo', '-bar'] + self.files + self.liby_files + self.libx_files) 

            # But also has an extra method replacing object files with a list
            args.makelist()
            # self.files has objects at #1, #2, #4
            self.assertRelEqual(args[:3], ['foo', '-bar'] + self.files[:1])
            self.assertRelEqual(args[4:], [self.files[3]] + self.files[5:] + [self.tmpfile('liby', Lib('z'))])

            # Check the list file content
            objs = [f for f in self.files + self.liby_files + self.libx_files if f.endswith(config.OBJ_SUFFIX)]
            if config.EXPAND_LIBS_LIST_STYLE == "linkerscript":
                self.assertNotEqual(args[3][0], '@')
                filename = args[3]
                content = ['INPUT("{0}")'.format(relativize(f)) for f in objs]
                with open(filename, 'r') as f:
                    self.assertEqual([l.strip() for l in f.readlines() if len(l.strip())], content)
            elif config.EXPAND_LIBS_LIST_STYLE == "list":
                self.assertEqual(args[3][0], '@')
                filename = args[3][1:]
                content = objs
                with open(filename, 'r') as f:
                    self.assertRelEqual([l.strip() for l in f.readlines() if len(l.strip())], content)

            tmp = args.tmp
        # Check that all temporary files are properly removed
        self.assertEqual(True, all([not os.path.exists(f) for f in tmp]))
 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
Exemple #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))
             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 os.path.splitext(f)[1] == conf.OBJ_SUFFIX
                     ]
                 newlist += objs
             else:
                 newlist += [arg]
         else:
             newlist += [arg]
     return newlist
 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
 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
 def assertRelEqual(self, args1, args2):
     self.assertEqual(args1, [relativize(a) for a in args2])
 def assertRelEqual(self, args1, args2):
     self.assertEqual(args1, [relativize(a) for a in args2])
 def _expand_desc(self, arg):
     objs = super(ExpandLibsDeps, self)._expand_desc(arg)
     if os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
         objs += [relativize(arg + conf.LIBS_DESC_SUFFIX)]
     return objs
Exemple #13
0
 def _expand_desc(self, arg):
     objs = super(ExpandLibsDeps, self)._expand_desc(arg)
     if os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
         objs += [relativize(arg + conf.LIBS_DESC_SUFFIX)]
     return objs