コード例 #1
0
ファイル: buildfile.py プロジェクト: sladeware/bbapp
 def buildpath(self, path, recursive=True):
   """Path will be created if it doesn't exist."""
   if typecheck.is_list(path):
     path = path_utils.join(*path)
   elif not typecheck.is_string(path):
     raise TypeError("path can be only a string or list")
   path = path_utils.join(self.get_build_dir(), path)
   if path_utils.exists(path):
     return path
   return path_utils.touch(path, recursive=recursive)
コード例 #2
0
ファイル: build.py プロジェクト: sladeware/bbapp
 def __init__(self, root_dir, parser, argv):
   Command.__init__(self, root_dir, parser, argv)
   if not self.args:
     self.args = [DEFAULT_TARGET]
   self.rules = []
   addresses = []
   # TODO: the following injection has to be fixed
   if os.path.exists(bb.config.user_settings.get("bbos", "homedir")):
     bbos_src = path_utils.join(bb.config.user_settings.get("bbos", "homedir"),
                                "src", "main")
     bbos_buildfile = buildfile.BuildFile(bbos_src, ".")
     buildfile.Context(bbos_buildfile).parse()
   #
   for target in self.args[0:]:
     try:
       address = buildfile.get_address(root_dir, target)
     except:
       self.error("Problem parsing target %s: %s" %
                  (target, traceback.format_exc()))
     if not address:
       print("Cannot find BUILD file for", target, file=sys.stderr)
       continue
     addresses.append(address)
   for address in addresses:
     try:
       print(buildfile.get_rule(address))
       rule = buildfile.get_rule(address)
     except:
       self.error("Problem parsing BUILD rule %s: %s" %
                  (address, traceback.format_exc()))
     if not rule:
       self.error("Rule %s does not exist" % address)
     self.rules.append(rule)
コード例 #3
0
ファイル: custom_c_compiler.py プロジェクト: sladeware/bbapp
 def link(self, objects, output_filename, *list_args, **dict_args):
   # Adopt output file name to output directory
   if self.get_output_dir() is not None:
     self.set_output_filename(path_utils.join(self.get_output_dir(),
                                                output_filename))
   binary_filename = path_utils.relpath(output_filename, self.output_dir)
   logger.info("Linking executable: %s" % binary_filename)
   self._link(objects, *list_args, **dict_args)
コード例 #4
0
ファイル: app.py プロジェクト: sladeware/bbapp
  def init_home_dir(cls, home_dir):
    """Initializes passed home directory if such wasn't already initialized.

    :returns: Path to home directory.
    """
    if not path_utils.exists(home_dir):
      raise IOError("'%s' doesn't exist" % home_dir)
    settings_dir = path_utils.join(home_dir, SETTINGS_DIR)
    path_utils.mkpath(settings_dir)
    return home_dir
コード例 #5
0
ファイル: custom_c_compiler.py プロジェクト: sladeware/bbapp
 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
コード例 #6
0
ファイル: compiler.py プロジェクト: sladeware/bbapp
  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))
コード例 #7
0
ファイル: buildfile.py プロジェクト: sladeware/bbapp
 def __init__(self, target=None, name=None, execute=None, deps=[]):
   """Each rule has a name that identifies it within existed context. In case
   name wasn't provided, it becomes a target and vice-versa.
   """
   if not target and not name:
     raise Exception("target and/or name have to be provided")
   if name and not typecheck.is_string(name):
     raise TypeError("name has to be a string: %s,%s" % (name, target))
   self._target = target
   if not name:
     if typecheck.is_string(target):
       name = target
     elif typecheck.is_class(target) or typecheck.is_function(target):
       name = target.__name__
     else:
       name = "i%d" % id(target)
   self._name = name
   self._description = None
   self._address = None
   self._address = self.locate()
   self._dependencies = [] # TODO: deprecated
   self._properties = dict()
   self._build_dir = None
   # TODO: test on windows and other systems!
   self.set_build_dir(path_utils.join(
       bb.config.user_settings.get("b3", "builddir"), os.getcwd()[1:]))
   if hasattr(self.__class__, "properties"):
     self.add_properties(self.__class__.properties)
   register_rule(self)
   if execute:
     if not callable(execute):
       raise TypeError()
     self.execute = types.MethodType(execute, self)
   # Defer dependency resolution after parsing the current BUILD file to
   # allow for forward references
   self._post_init(self._finalize_deps, deps)