Esempio n. 1
0
def CreateTmpGitRepo(project, project_url):
    """Create a temporary git repo locally.

  Args:
    project: git project name to clone.
    project_url: git project url to clone.

  Returns:
    project_dir: local project directory.
  """

    work_dir = GetWorkDir(project)

    if not cros_build_lib.IsInsideChroot():
        work_dir = os.path.join(constants.SOURCE_ROOT,
                                constants.DEFAULT_CHROOT_DIR, work_dir)

    # Delete the work_dir built by previous runs.
    osutils.RmDir(work_dir, ignore_missing=True, sudo=True)

    # Safely create work_dir
    osutils.SafeMakedirs(work_dir)

    project_dir = os.path.join(work_dir, project)
    ref = os.path.join(constants.SOURCE_ROOT, project)

    logging.info('Cloning %s %s to %s', project_url, ref, project_dir)
    repository.CloneWorkingRepo(dest=project_dir,
                                url=project_url,
                                reference=ref)
    return project_dir
def GetProjectRepoDir(project, project_url, clean_old_dir=False):
    """Clone the project repo locally and return the repo directory.

  Args:
    project: git project name to clone.
    project_url: git project url to clone.
    clean_old_dir: Boolean to indicate whether to clean old work_dir. Default
      to False.

  Returns:
    project_dir: local project directory.
  """
    work_dir = GetProjectWorkDir(project)

    if clean_old_dir:
        # Delete the work_dir built by previous runs.
        osutils.RmDir(work_dir, ignore_missing=True, sudo=True)

    osutils.SafeMakedirs(work_dir)

    project_dir = os.path.join(work_dir, project)
    if not os.path.exists(project_dir):
        ref = os.path.join(constants.SOURCE_ROOT, project)
        logging.info('Cloning %s %s to %s', project_url, ref, project_dir)
        repository.CloneWorkingRepo(dest=project_dir,
                                    url=project_url,
                                    reference=ref)

    return project_dir