def CopyFileToGS(self,
                     filename,
                     gs_base,
                     gs_subdir,
                     mimetype=None,
                     gs_acl=None):
        # normalize the subdir to remove duplicated slashes. This break newer
        # versions of gsutil. Also remove leading and ending slashes for the subdir,
        # gsutil adds them back autimatically and this can cause a double slash to
        # be added.
        if gs_subdir:
            gs_subdir = gs_subdir.replace('//', '/')
            gs_subdir = gs_subdir.strip('/')

        # Construct metadata from our revision information, as available.
        gs_metadata = {
            GS_COMMIT_POSITION_NUMBER_KEY: self._chromium_revision,
        }

        # Add the commit position, if available
        try:
            gs_metadata[
                GS_COMMIT_POSITION_KEY] = chromium_utils.BuildCommitPosition(
                    *chromium_utils.GetCommitPosition(self.options))
        except chromium_utils.NoIdentifiedRevision:
            pass

        # Add the git commit hash, if available
        try:
            gs_metadata[GS_GIT_COMMIT_KEY] = chromium_utils.GetGitCommit(
                self.options)
        except chromium_utils.NoIdentifiedRevision:
            pass

        status = slave_utils.GSUtilCopyFile(filename,
                                            gs_base,
                                            gs_subdir,
                                            mimetype,
                                            gs_acl,
                                            metadata=gs_metadata)
        if status != 0:
            dest = gs_base + '/' + gs_subdir
            raise GSUtilError('GSUtilCopyFile error %d. "%s" -> "%s"' %
                              (status, filename, dest))
def GetGitCommit(options, primary_project):
    """Returns: (str/None) the git commit hash for a given project.

  Attempts to identify the git commit hash for a given project. If
  'primary_project' is None, or if there is no git commit hash for the specified
  primary project, the checkout-wide commit hash will be used.

  If none of the candidate configurations are present, 'None' will be returned.
  """
    projects = []
    if primary_project:
        projects += [primary_project]
    projects += [None]

    for project in projects:
        try:
            return chromium_utils.GetGitCommit(options, project=project)
        except chromium_utils.NoIdentifiedRevision:
            pass
    return None
    def __init__(self, options, build_revision):
        """Sets a number of file and directory paths for convenient use."""

        self.options = options
        self._src_dir = os.path.abspath(options.src_dir)
        self._chrome_dir = os.path.join(self._src_dir, 'chrome')

        build_dir = build_directory.GetBuildOutputDirectory()
        self._build_dir = os.path.join(build_dir, options.target)
        if chromium_utils.IsWindows():
            self._tool_dir = os.path.join(self._chrome_dir, 'tools', 'build',
                                          'win')
        elif chromium_utils.IsLinux():
            # On Linux, we might have built for chromeos.  Archive the same.
            if (options.factory_properties.get('chromeos', None)
                    or slave_utils.GypFlagIsOn(options, 'chromeos')):
                self._tool_dir = os.path.join(self._chrome_dir, 'tools',
                                              'build', 'chromeos')
            # Or, we might have built for Android.
            elif options.factory_properties.get('target_os') == 'android':
                self._tool_dir = os.path.join(self._chrome_dir, 'tools',
                                              'build', 'android')
            else:
                self._tool_dir = os.path.join(self._chrome_dir, 'tools',
                                              'build', 'linux')
        elif chromium_utils.IsMac():
            self._tool_dir = os.path.join(self._chrome_dir, 'tools', 'build',
                                          'mac')
        else:
            raise NotImplementedError(
                'Platform "%s" is not currently supported.' % sys.platform)
        self._staging_dir = (options.staging_dir
                             or slave_utils.GetStagingDir(self._src_dir))
        if not os.path.exists(self._staging_dir):
            os.makedirs(self._staging_dir)

        self._symbol_dir_base = options.dirs['symbol_dir_base']
        self._www_dir_base = options.dirs['www_dir_base']

        if options.build_name:
            self._build_name = options.build_name
        else:
            self._build_name = slave_utils.SlaveBuildName(self._src_dir)

        self._symbol_dir_base = os.path.join(self._symbol_dir_base,
                                             self._build_name)
        self._www_dir_base = os.path.join(self._www_dir_base, self._build_name)

        self._version_file = os.path.join(self._chrome_dir, 'VERSION')

        self._chromium_revision = chromium_utils.GetBuildSortKey(options)[1]

        self._v8_revision = chromium_utils.GetBuildSortKey(options,
                                                           project='v8')[1]
        self._v8_revision_git = chromium_utils.GetGitCommit(options,
                                                            project='v8')

        self.last_change_file = os.path.join(self._staging_dir, 'LAST_CHANGE')
        # The REVISIONS file will record the revisions information of the main
        # components Chromium/WebKit/V8.
        self.revisions_path = os.path.join(self._staging_dir, 'REVISIONS')
        self._build_revision = build_revision
        self._build_path_component = str(self._build_revision)

        # Will be initialized in GetLastBuildRevision.
        self.last_chromium_revision = None
        self.last_v8_revision = None

        self._files_file = os.path.join(self._tool_dir,
                                        archive_utils.FILES_FILENAME)
        self._test_files = self.BuildOldFilesList(TEST_FILE_NAME)

        self._dual_upload = options.factory_properties.get(
            'dual_upload', False)
        self._archive_files = None