示例#1
0
 def _setup_compile(self, sources, macros, include_dirs, extra, depends):
   """Process arguments and decide which source files to compile."""
   if macros is None:
     macros = self.macros
   elif typecheck.is_list(macros):
     macros = macros + (self.macros or [])
   else:
     raise TypeError("'macros' (if supplied) must be a list of tuples")
   if include_dirs is None:
     include_dirs = self._include_dirs
   elif typecheck.is_sequence(include_dirs):
     include_dirs = list(include_dirs) + (self._include_dirs or [])
   else:
     raise TypeError("'include_dirs' (if supplied) must be a list of strings")
   if extra is None:
     extra = []
   # List of expected output files
   objects = self.get_object_filenames(sources)
   assert len(objects) == len(sources)
   pp_options = self._gen_preprocess_options(macros, include_dirs)
   build = {}
   for i in range(len(sources)):
     src = sources[i]
     obj = objects[i]
     ext = path_utils.splitext(src)[1]
     path_utils.mkpath(path_utils.dirname(obj), 0777)
     build[obj] = (src, ext)
   return macros, objects, extra, pp_options, build
示例#2
0
 def get_object_filenames(self, src_filenames):
   obj_filenames = []
   for src_filename in src_filenames:
     base, ext = path_utils.splitext(src_filename)
     base = path_utils.splitdrive(base)[1]
     base = base[path_utils.isabs(base):]
     if ext not in self.get_source_extensions():
       raise Exception("unknown file type '%s' of '%s'" % (ext, src_filename))
     obj_filenames.append(
       path_utils.join(self.get_output_dir(),
                            base + self.get_object_extension()))
   return obj_filenames
示例#3
0
 def identify_language(self, sources):
   """Identify the language of a given file, or list of files. Uses
   language_map, and :func:`CCompiler.get_language_precedence_order` to do the
   job.
   """
   if not typecheck.is_list(sources):
     sources = [sources]
   lang = None
   index = len(self.language_order)
   for source in sources:
     base, ext = path_utils.splitext(source)
     extlang = self.language_map.get(ext)
     try:
       extindex = self.language_order.index(extlang)
       if extindex < index:
         lang = extlang
         index = extindex
     except ValueError:
       pass
   return lang