Ejemplo n.º 1
0
  def update_submodules(cls):
    """Does a git pull and then update the submodules to the latest version
    AND finally ensure the submodule is on master
    @warning if you run this from a module run that does a os.chdir, this
       os.chdir will NOT persist here
    """
    if ExecUtils.RunCmd('git pull')[0]:
      raise Error(TermColor.ColorStr(
        'unable to git pull as part of submodule update', 'RED'))

    if ExecUtils.RunCmd('git submodule init && git submodule update')[0]:
      raise Error(TermColor.ColorStr(
        'git submodule update failed!', 'RED'))
Ejemplo n.º 2
0
 def commit_push(cls, files, msg):
   """Commits to the current branch AND pushes to remote
   Args:
     files (list) - list of files to commit
     msg (string) - the commit message
   """
   ret = ExecUtils.RunCmd('git commit %s -m "%s"' % (' '.join(files), msg))[0]
   if not ret == 0:
     raise Error(TermColor.ColorStr(
       'error committing these files: %s' % ' '.join(files), 'RED'))
   ret = ExecUtils.RunCmd('git pull && git push')[0]
   if not ret == 0:
     raise Error(TermColor.ColorStr(
       'Please manually resolve any conflicts preventing git push of ' + \
       'the commit to remote', 'RED'))
Ejemplo n.º 3
0
 def get_current_branch(cls):
   """Returns the name of the current branch"""
   cmd = 'git rev-parse --abbrev-ref HEAD'
   r = ExecUtils.RunCmd(cmd)
   if r[0]:
     raise Error(TermColor.ColorStr('error executing cmd %s' % cmd, 'RED'))
   return r[1].strip()
Ejemplo n.º 4
0
 def checkout_branch(cls, branch):
   """Checks out the specified branch with the latest code
   Args:
     branch (string) - the branch name
   """
   # fetches the latest code
   ret = ExecUtils.RunCmd('git fetch origin')[0]
   if not ret == 0:
     raise Error(TermColor.ColorStr('error during git fetch origin!', 'RED'))
   #subprocess.check_call(
   #  'git checkout -b %s --track origin/%s 2>/dev/null' % \
   #  (branch, branch),
   #  shell=True)
   ret = ExecUtils.RunCmd('git checkout -B %s --track origin/%s' % (
     branch, branch))[0]
   if not ret == 0:
     raise Error(TermColor.ColorStr(
       'error checking out branch %s' % branch, 'RED'))
Ejemplo n.º 5
0
 def apply_hotfix(cls, branch, commit_hash=""):
   """applies a hotfix to a specific branch
   Args:
     branch (string) - the branch to apply the hotfix
     hash (string) - the commit hash to use
   Raises:
     EmptyHotfixError - raised when the hotfix is empty
     Error - critical error such as conflict stopped with
       hotfix from being applied
   """
   print("moving to branch %s" % TermColor.ColorStr(branch, 'GREEN'))
   # get onto the appropriate branch
   cls.checkout_branch(branch)
   # try to cherry-pick
   print(TermColor.ColorStr("Applying hotfix to branch: %s" % branch,
                            'GREEN'))
   ret = ExecUtils.RunCmd('git cherry-pick %s' % commit_hash)[0]
   if not ret == 0:
     r = ExecUtils.RunCmd('git diff --name-only')
     if r[0]:
       raise Error(TermColor.ColorStr('error doing a git diff', 'RED'))
     files = r[1]
     if not files:
       raise EmptyHotfixError('hotfix is empty. likely already applied')
     # not an error if empty
     raise Error(TermColor.ColorStr(
       ('Hotfix apply failed at step cherry pick on branch %s.\n'
        'You NEED to fix this NOW! Go to %s and fix the issue! '
        'Impacted files: %s') % (
       cls.get_current_branch(), os.getcwd(), files), 'RED'))
   # push cherry-pick to remote
   ret = ExecUtils.RunCmd('git push origin %s' % branch)[0]
   if not ret == 0:
     raise Error(TermColor.ColorStr(
       'Please manually resolve your merge conflicts,' + \
       'then commit, and finally run hotfix selecting the ' + \
       'branches that have not yet received the commit', 'RED'))
   print(TermColor.ColorStr('Applied hotfix to %s' % branch, 'GREEN'))
   print(TermColor.ColorStr('On branch %s' % branch, 'GREEN'))
Ejemplo n.º 6
0
    def Clean(cls):
        """Runs the cleaner.

    Return:
      int: Exit status. 0 means no error.
    """
        gen_makefile = GenMakefile(Flags.ARGS.debug)
        gen_makefile.GenMainMakeFile()

        clean = 'clean'
        if Flags.ARGS.obj:
            clean = 'cleano'
        elif Flags.ARGS.all:
            clean = 'cleanall'

        (status, out) = ExecUtils.RunCmd(
            'make -f %s %s' % (gen_makefile.GetMakeFileName(), clean))

        return status
Ejemplo n.º 7
0
  def _MakeSingeRule(cls, rule, makefile, deps_file):
    """Builds a Single Rule.
    Args:
      rule: string: The rule to build.
      makefile: string: The *main* makefile name.

    Return:
      (int): Returns the result status.
          The status is '1' for success, '0' for 'ignore', '-1' for fail.
    """
    # Get dependencies list for the rule. Run this with the original main file.
    (status, out) = ExecUtils.RunCmd('make -f %s %s' %
                                     (makefile, cls.GetDepsRuleName(rule)))
    if status:
      TermColor.Error('Could not make dependency for rule %s' %
                      Utils.RuleDisplayName(rule))
      return -1

    return super(CCRules, cls)._MakeSingeRule(rule, makefile, deps_file)
Ejemplo n.º 8
0
  def _RunSingeTask(cls, task):
    """Runs a Single Task.

    Args:
      task: string: The task to run.

    Return:
      (EXITCODE, string): Returns a tuple of the result status and the task.
    """
    TermColor.Info('Executing %s' % PipelineUtils.TaskDisplayName(task))
    task_vars = cls.__GetEnvVarsForTask(task)
    TermColor.VInfo(4, 'VARS: \n%s' % task_vars)

    task_cmd = task
    pipe_output = True
    log_file = PipelineUtils.GetLogFileForTask(task)
    if log_file:
       task_cmd += ' > ' + PipelineUtils.GetLogFileForTask(task) + ' 2>&1'
       pipe_output = False

    timeout = cls.__GetTimeOutForTask(task)
    start = time.time()
    (status, out) = ExecUtils.RunCmd(task_cmd, timeout, pipe_output, task_vars)
    time_taken = time.time() - start
    TermColor.Info('Executed  %s. Took %.2fs' % (PipelineUtils.TaskDisplayName(task), time_taken))
    if status:
      TermColor.Failure('Failed Task: %s' % PipelineUtils.TaskDisplayName(task))
      if task_vars.get('PIPELINE_TASK_ABORT_FAIL', None):
        status_code = Runner.EXITCODE['ABORT_FAIL']
      elif task_vars.get('PIPELINE_TASK_ALLOW_FAIL', None):
        status_code = Runner.EXITCODE['ALLOW_FAIL']
      else:
        status_code = Runner.EXITCODE['FAILURE']
    else:
      status_code = Runner.EXITCODE['SUCCESS']

    cls._SendMailForTask(task, status_code, time_taken, log_file, out)

    # Everything done. Mark the task as successful.
    return (status_code, task)
Ejemplo n.º 9
0
  def _MakeSingeRule(cls, rule, makefile, deps_file):
    """Builds a Single Rule.
    Args:
      rule: string: The rule to build.
      makefile: string: The *main* makefile name.

    Return:
      (int): Returns the result status.
          The status is '1' for success, '0' for 'ignore', '-1' for fail.
    """
    # Build the rule.

    if Flags.ARGS.pool_size:
      parallel_processes = Flags.ARGS.pool_size
    else:
      parallel_processes = max(multiprocessing.cpu_count(), 1)
    (status, out) = ExecUtils.RunCmd('make -r -j%d -f %s %s' % (parallel_processes,
                                                                deps_file, rule))
    if status:
      TermColor.Failure('Failed Rule: %s' % Utils.RuleDisplayName(rule))
      return -1

    TermColor.VInfo(1, '%s Output: \n%s' % (Utils.RuleDisplayName(rule), out))
    return 1
Ejemplo n.º 10
0
  def _RunSingeRule(cls, rule, pipe_output):
    """Runs a Single Rule.

    Args:
      rule: string: The rule to run.
      pipe_output: bool: Whether to pipe_output or dump it to STDOUT.

    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.
    """
    TermColor.Info('Running %s' % Utils.RuleDisplayName(rule))
    start = time.time()
    bin_file = FileUtils.GetBinPathForFile(rule)
    (status, out) = ExecUtils.RunCmd('%s %s' % (bin_file, Flags.ARGS.args),
                                     Flags.ARGS.timeout, pipe_output)
    if status:
      TermColor.Failure('Failed Rule: %s' % Utils.RuleDisplayName(rule))
      return (-1, rule)

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