Esempio n. 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
Esempio n. 2
0
 def _link(self, objects, output_dir=None, libraries=None, library_dirs=None,
             debug=False, extra_preargs=None, extra_postargs=None,
             target_lang=None):
   """Linking."""
   objects, output_dir, libraries, library_dirs = \
       self._setup_link(objects, output_dir, libraries, library_dirs)
   lib_options = self._gen_lib_options(library_dirs, libraries)
   # Finalize linker options
   ld_options = self._gen_ld_options(debug, extra_preargs)
   if extra_postargs:
     ld_options.extend(extra_postargs)
   ld_options += (objects + lib_options + ['-o', self.get_output_filename()])
   path_utils.mkpath(path_utils.dirname(self.get_output_filename()))
   try:
     linker = self.get_executable()
     # skip over environment variable settings if /usr/bin/env is used to set
     # up the linker's environment. This is needed on OSX. Note: this
     # assumes that the normal and C++ compiler have the same environment
     # settings.
     i = 0
     if path_utils.basename(linker[0]) == "env":
       i = 1
       while "=" in linker[i]:
         i = i + 1
     # TODO: resolve this
     #linker[i] = self.get_executable('compiler_cxx')[i]
     spawn.spawn([linker] + ld_options, debug=self.get_verbosity_level(),
                 dry_run=self.is_dry_run_mode_enabled())
   except Exception, e:
     raise Exception, e
Esempio n. 3
0
 def identify_home_dir(cls):
   for record in inspect.stack():
     (frame, filename, lineno, code_ctx, _, index) = record
     path = path_utils.dirname(path_utils.abspath(filename))
     home_dir = cls.find_home_dir(path)
     if home_dir:
       return home_dir
   return cls.find_home_dir(path_utils.realpath(os.curdir)) or os.getcwd()
Esempio n. 4
0
 def read_params(self, params):
   if not isinstance(params, self.Parameters):
     params = self.Parameters(params)
   if not "basedir" in params.context:
     caller_frame = inspect.getouterframes(inspect.currentframe(), 2)
     params.context["basedir"] = path_utils.dirname(inspect.getsourcefile(
         caller_frame[1][0])) or "."
   self.__processing_params = params
   if self.__param_handlers:
     for param, handler_name in self.__param_handlers.items():
       if not param in params:
         continue
       value = params[param]
       handler = getattr(self, handler_name)
       handler(value)
   self.__processing_params = None
Esempio n. 5
0
  def add_file(self, path):
    """Adds file to the list of files. The path will be normalized by using
    :func:`os.path.abspath`.

    :param path: A string that represents file path.

    :returns: A normalized string path.

    :raises: TypeError
    """
    if typecheck.is_string(path):
      if not path_utils.exists(path):
        caller_frame = inspect.getouterframes(inspect.currentframe(), 2)
        filename = inspect.getsourcefile(caller_frame[2][0])
        possible_dir = path_utils.dirname(filename)
        alternative_path = path_utils.join(possible_dir, path)
        if path_utils.exists(alternative_path):
          return self.add_file(alternative_path)
      path = path_utils.abspath(path)
      if not path_utils.exists(path):
        raise Exception("Path doesn't exist: %s" % path)
      if not path in self._files:
        self._files.append(path)
      return path
    elif typecheck.is_callable(path):
      result = path()
      if not result:
        return
      elif typecheck.is_list(result):
        self.add_files(result)
      else:
        self.add_file(result)
    elif not path:
      return None
    else:
      raise TypeError("Unknown path type '%s' of '%s'" % (type(path), path))