Пример #1
0
    def _ComputeRules(cls, targets, ignore_list=[]):
        """Computes the rules to be run given the input targets.
    Args:
      targets: list: List of input targets.
    Return:
      list: List of actual rules to be run.
    """
        rules = []
        for target in targets:
            ignore = Utils.IgnoreRule(target, ignore_list)
            if ignore:
                TermColor.Warning(
                    'Ignored target %s as anything with [%s] is ignored.' %
                    (target, ignore))
                continue

            if os.path.isdir(target):
                target = os.getcwd() if target == '.' else target
                rule = os.path.join(target, 'RULES')
                if os.path.isfile(rule):
                    rules += [Utils.RuleNormalizedName(rule)]
                else:
                    TermColor.Warning('No RULES file in directory: %s' %
                                      target)
            elif os.path.isfile(target):
                rules += [
                    Utils.RuleNormalizedName(os.path.splitext(target)[0])
                ]
            elif os.path.basename(target) == '...':
                dir = os.path.dirname(target)
                if not dir: dir = os.getcwd()
                dir = os.path.dirname(
                    Utils.RuleNormalizedName(os.path.join(dir, 'RULES')))
                rules += Utils.GetRulesFilesFromSubdirs(dir, ignore_list)
            else:
                rules += [Utils.RuleNormalizedName(target)]

        temp_list = []
        seen = set()
        for rule in rules:
            if rule in seen: continue
            temp_list += [rule]
            seen |= set([rule])

        rules = []
        for rule in temp_list:
            if ((os.path.basename(rule) != 'RULES') and
                (os.path.join(os.path.dirname(rule), 'RULES') in seen)):
                continue
            rules += [rule]

        return rules
Пример #2
0
  def _WorkHorse(cls, rule, makefile):
    """Workhorse for building a single rule.
    Args:
      rule: string: The rule to build.
      makefile: string: The *main* makefile name.

    Return:
      (int, string): Returns a tuple of the result status and the rule.
          The status is '1' for success, '0' for 'ignore', '-1' for fail.
    """
    start = time.time()
    ignore = Utils.IgnoreRule(rule, Flags.ARGS.ignore_rules)
    if ignore:
      TermColor.Warning('Ignored targets in %s as anything with [%s] is ignored' %
                        (Utils.RuleDisplayName(rule), ignore))
      return (0, rule)

    TermColor.Info('Building %s' % Utils.RuleDisplayName(rule))

    deps_file = cls.GetDepsFileName(makefile, rule, '.main.')
    try:
      shutil.copy(makefile, deps_file)
      cls._PrepareDepsFile(rule, deps_file)
    except (OSError, IOError) as e:
      TermColor.Error('Could not create makefile for rule %s' %
                      Utils.RuleDisplayName(rule))
      return (-1, rule)

    # Make the rule.
    status = cls._MakeSingeRule(rule, makefile, deps_file)
    if status != 1:
      TermColor.Failure('Failed Rule: %s' % Utils.RuleDisplayName(rule))
      return (status, rule)

    TermColor.Info('Built %s. Took %.2fs' %
                   (Utils.RuleDisplayName(rule), (time.time() - start)))
    # Everything done. Mark the rule as successful.
    return (1, rule)