Esempio n. 1
0
def main(argv):
    cros_build_lib.AssertInsideChroot()
    opts = _ParseArguments(argv)

    site_config = config_lib.GetConfig()

    logging.info('Generating board configs. This takes about 2m...')
    for key in sorted(binhost.GetChromePrebuiltConfigs(site_config)):
        binhost.GenConfigsForBoard(key.board,
                                   regen=opts.regen,
                                   error_code_ok=True)

    # Fetch all compat IDs.
    fetcher = binhost.CompatIdFetcher()
    keys = binhost.GetChromePrebuiltConfigs(site_config).keys()
    compat_ids = fetcher.FetchCompatIds(keys)

    # Save the PFQ configs.
    pfq_configs = binhost.PrebuiltMapping.Get(keys, compat_ids)
    filename_internal = binhost.PrebuiltMapping.GetFilename(
        opts.buildroot, 'chrome')
    pfq_configs.Dump(filename_internal)
    git.AddPath(filename_internal)
    git.Commit(os.path.dirname(filename_internal),
               'Update PFQ config dump',
               allow_empty=True)

    filename_external = binhost.PrebuiltMapping.GetFilename(opts.buildroot,
                                                            'chromium',
                                                            internal=False)
    pfq_configs.Dump(filename_external, internal=False)
    git.AddPath(filename_external)
    git.Commit(os.path.dirname(filename_external),
               'Update PFQ config dump',
               allow_empty=True)
Esempio n. 2
0
def PrepManifestForRepo(git_repo, manifest):
    """Use this to store a local manifest in a git repo suitable for repo.

  The repo tool can only fetch manifests from git repositories. So, to use
  a local manifest file as the basis for a checkout, it must be checked into
  a local git repository.

  Common Usage:
    manifest = CreateOrFetchWondrousManifest()
    with osutils.TempDir() as manifest_git_dir:
      PrepManifestForRepo(manifest_git_dir, manifest)
      repo = RepoRepository(manifest_git_dir, repo_dir)
      repo.Sync()

  Args:
    git_repo: Path at which to create the git repository (directory created, if
              needed). If a tempdir, then cleanup is owned by the caller.
    manifest: Path to existing manifest file to copy into the new git
              repository.
  """
    if not git.IsGitRepo(git_repo):
        git.Init(git_repo)

    new_manifest = os.path.join(git_repo, constants.DEFAULT_MANIFEST)

    shutil.copyfile(manifest, new_manifest)
    git.AddPath(new_manifest)
    message = 'Local repository holding: %s' % manifest

    # Commit new manifest. allow_empty in case it's the same as last manifest.
    git.Commit(git_repo, message, allow_empty=True)
Esempio n. 3
0
    def Commit(self, file_paths, commit_msg):
        """Commits files listed in |file_paths|.

    Args:
      file_paths: List of files to commit.
      commit_msg: Message to use in commit.
    """
        assert file_paths and isinstance(file_paths, list)
        # Make paths absolute and ensure they exist.
        for i, file_path in enumerate(file_paths):
            if not os.path.isabs(file_path):
                file_paths[i] = self.FullPath(file_path)
            if not os.path.exists(file_paths[i]):
                raise CommitError('Invalid path: %s' % file_paths[i])

        self._commit_msg = 'Automated Commit: ' + commit_msg
        try:
            for file_path in file_paths:
                git.AddPath(file_path)
            commit_args = ['commit', '-m', self._commit_msg]
            git.RunGit(self._checkout_dir,
                       self._git_committer_args + commit_args,
                       print_cmd=True,
                       stderr=True,
                       capture_output=False)
        except cros_build_lib.RunCommandError as e:
            raise CommitError('Could not create git commit: %r' % e)
    def setUp(self):
        self.manifest_dir = os.path.join(self.tempdir, '.repo', 'manifests')

        # Initialize a repo instance here.
        local_repo = os.path.join(constants.SOURCE_ROOT, '.repo/repo/.git')

        # TODO(evanhernandez): This is a hack. Find a way to simplify this test.
        # We used to use the current checkout's manifests.git, but that caused
        # problems in production environemnts.
        remote_manifests = os.path.join(self.tempdir, 'remote',
                                        'manifests.git')
        osutils.SafeMakedirs(remote_manifests)
        git.Init(remote_manifests)
        default_manifest = os.path.join(remote_manifests, 'default.xml')
        osutils.WriteFile(
            default_manifest,
            '<?xml version="1.0" encoding="UTF-8"?><manifest></manifest>')
        git.AddPath(default_manifest)
        git.Commit(remote_manifests, 'dummy commit', allow_empty=True)
        git.CreateBranch(remote_manifests, 'default')
        git.CreateBranch(remote_manifests, 'release-R23-2913.B')
        git.CreateBranch(remote_manifests, 'release-R23-2913.B-suffix')
        git.CreateBranch(remote_manifests, 'firmware-link-')

        # Create a copy of our existing manifests.git, but rewrite it so it
        # looks like a remote manifests.git.  This is to avoid hitting the
        # network, and speeds things up in general.
        local_manifests = 'file://%s' % remote_manifests
        temp_manifests = os.path.join(self.tempdir, 'manifests.git')
        git.RunGit(self.tempdir, ['clone', '-n', '--bare', local_manifests])
        git.RunGit(temp_manifests, [
            'fetch', '-f', '-u', local_manifests,
            'refs/remotes/origin/*:refs/heads/*'
        ])
        git.RunGit(temp_manifests, ['branch', '-D', 'default'])
        cros_build_lib.run([
            'repo',
            'init',
            '-u',
            temp_manifests,
            '--repo-branch',
            'default',
            '--repo-url',
            'file://%s' % local_repo,
        ],
                           cwd=self.tempdir)

        self.active_manifest = os.path.realpath(
            os.path.join(self.tempdir, '.repo', 'manifest.xml'))
Esempio n. 5
0
def UpdateBinhostConfFile(path, key, value):
  """Update binhost config file file with key=value.

  Args:
    path: Filename to update.
    key: Key to update.
    value: New value for key.
  """
  cwd, filename = os.path.split(os.path.abspath(path))
  osutils.SafeMakedirs(cwd)
  if not git.GetCurrentBranch(cwd):
    git.CreatePushBranch(constants.STABLE_EBUILD_BRANCH, cwd, sync=False)
  osutils.WriteFile(path, '', mode='a')
  if UpdateLocalFile(path, value, key):
    desc = '%s: %s %s' % (filename, 'updating' if value else 'clearing', key)
    git.AddPath(path)
    git.Commit(cwd, desc)
Esempio n. 6
0
def MaskNewerPackages(overlay, ebuilds):
    """Mask ebuild versions newer than the ones passed in.

  This creates a new mask file called chromepin which masks ebuilds newer than
  the ones passed in. To undo the masking, just delete that file. The
  mask file is added with git.

  Args:
    overlay: The overlay that will hold the mask file.
    ebuilds: List of ebuilds to set up masks for.
  """
    content = '# Pin chrome by masking more recent versions.\n'
    for ebuild in ebuilds:
        parts = portage_util.SplitEbuildPath(ebuild)
        content += '>%s\n' % os.path.join(parts[0], parts[2])
    mask_file = os.path.join(overlay, MASK_FILE)
    osutils.WriteFile(mask_file, content)
    git.AddPath(mask_file)
Esempio n. 7
0
def RevertStableEBuild(dirname, rev):
    """Revert the stable ebuilds for a package back to a particular revision.

  Also add/remove the files in git.

  Args:
    dirname: Path to the ebuild directory.
    rev: Revision to revert back to.

  Returns:
    The name of the ebuild reverted to.
  """
    package = os.path.basename(dirname.rstrip(os.sep))
    pattern = '%s-*.ebuild' % package

    # Get rid of existing stable ebuilds.
    ebuilds = glob.glob(os.path.join(dirname, pattern))
    for ebuild in ebuilds:
        parts = SplitPVPath(ebuild)
        if parts.version != '9999':
            git.RmPath(ebuild)

    # Bring back the old stable ebuild.
    names = git.GetObjectAtRev(dirname, './', rev).split()
    names = fnmatch.filter(names, pattern)
    names = [
        name for name in names
        if SplitPVPath(os.path.join(dirname, name)).version != '9999'
    ]
    if not names:
        return None
    assert len(names) == 1
    name = names[0]
    git.RevertPath(dirname, name, rev)

    # Update the manifest.
    UpdateManifest(os.path.join(dirname, name))
    manifest_path = os.path.join(dirname, 'Manifest')
    if os.path.exists(manifest_path):
        git.AddPath(manifest_path)
    return os.path.join(dirname, name)
 def testAddPath(self):
     git.AddPath(self.fake_path)
     self.assertCommandContains(['add'])
     self.assertCommandContains([self.fake_file])