Esempio n. 1
0
  def _collect_metrics(self, func, command_name, *args, **kwargs):
    self.add('command', command_name)
    try:
      start = time.time()
      func(*args, **kwargs)
      exception = None
    # pylint: disable=bare-except
    except:
      exception = sys.exc_info()
    finally:
      self.add('execution_time', time.time() - start)

    # Print the exception before the metrics notice, so that the notice is
    # clearly visible even if gclient fails.
    if exception and not isinstance(exception[1], SystemExit):
      traceback.print_exception(*exception)

    exit_code = metrics_utils.return_code_from_exception(exception)
    self.add('exit_code', exit_code)

    # Print the metrics notice only if the user has not explicitly opted in
    # or out.
    if self.config.opted_in is None:
      metrics_utils.print_notice(self.config.countdown)

    # Add metrics regarding environment information.
    self.add('timestamp', metrics_utils.seconds_to_weeks(time.time()))
    self.add('python_version', metrics_utils.get_python_version())
    self.add('host_os', gclient_utils.GetMacWinOrLinux())
    self.add('host_arch', detect_host_arch.HostArch())
    self.add('depot_tools_age', metrics_utils.get_repo_timestamp(DEPOT_TOOLS))

    self._upload_metrics_data()
    sys.exit(exit_code)
def FindClangFormatToolInChromiumTree():
  """Return a path to the clang-format executable, or die trying."""
  tool_path = os.path.join(_FindChromiumSourceRoot(), 'third_party',
                           'clang_format', 'bin',
                           gclient_utils.GetMacWinOrLinux(),
                           'clang-format' + gclient_utils.GetExeSuffix())
  if not os.path.exists(tool_path):
    # TODO(nick): After March 2014, eliminate the following advisory.
    error_text = '''\n  GIT CL FORMAT - WINTER WEATHER ADVISORY

    clang-format binaries now come with every Chrome checkout!

    Unfortunately, your depot_tools scripts tried to find clang-format binaries
    in your Chrome checkout, but failed. This is expected if you haven't synced
    since the binaries were added.

    'git cl format' will probably not work until you sync your Chrome tree.
    Sorry about that.

    Contact [email protected] if you have any additional questions.\n\n'''

    error_text += 'File does not exist: %s' % tool_path

    raise NotFoundError(error_text)
  return tool_path
Esempio n. 3
0
def FindClangFormatToolInChromiumTree():
    """Return a path to the clang-format executable, or die trying."""
    tool_path = os.path.join(_FindChromiumSourceRoot(), 'third_party',
                             'clang_format', 'bin',
                             gclient_utils.GetMacWinOrLinux(),
                             'clang-format' + gclient_utils.GetExeSuffix())
    if not os.path.exists(tool_path):
        raise NotFoundError('File does not exist: %s' % tool_path)
    return tool_path
Esempio n. 4
0
    def _collect_metrics(self, func, command_name, *args, **kwargs):
        # If we're already collecting metrics, just execute the function.
        # e.g. git-cl split invokes git-cl upload several times to upload each
        # splitted CL.
        if self.collecting_metrics:
            # Don't collect metrics for this function.
            # e.g. Don't record the arguments git-cl split passes to git-cl upload.
            with self.pause_metrics_collection():
                return func(*args, **kwargs)

        self._collecting_metrics = True
        self.add('metrics_version', metrics_utils.CURRENT_VERSION)
        self.add('command', command_name)
        try:
            start = time.time()
            result = func(*args, **kwargs)
            exception = None
        # pylint: disable=bare-except
        except:
            exception = sys.exc_info()
        finally:
            self.add('execution_time', time.time() - start)

        exit_code = metrics_utils.return_code_from_exception(exception)
        self.add('exit_code', exit_code)

        # Add metrics regarding environment information.
        self.add('timestamp', int(time.time()))
        self.add('python_version', metrics_utils.get_python_version())
        self.add('host_os', gclient_utils.GetMacWinOrLinux())
        self.add('host_arch', detect_host_arch.HostArch())

        depot_tools_age = metrics_utils.get_repo_timestamp(DEPOT_TOOLS)
        if depot_tools_age is not None:
            self.add('depot_tools_age', int(depot_tools_age))

        git_version = metrics_utils.get_git_version()
        if git_version:
            self.add('git_version', git_version)

        self._upload_metrics_data()
        if exception:
            gclient_utils.reraise(exception[0], exception[1], exception[2])
        return result
Esempio n. 5
0
def RunGN(sourceroot):
    # The binaries in platform-specific subdirectories in src/tools/gn/bin.
    gnpath = os.path.join(sourceroot, 'tools', 'gn', 'bin',
                          gclient_utils.GetMacWinOrLinux(),
                          'gn' + gclient_utils.GetExeSuffix())
    return subprocess.call([gnpath] + sys.argv[1:])