<commit_before>#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

""" Run the Skia GM executable. """

from utils import shell_utils
from build_step import BuildStep
import errno
import os
import shutil
import sys


class RunGM(BuildStep):
  def _PreGM(self,):
    print 'Removing %s' % self._gm_actual_dir
    try:
      shutil.rmtree(self._gm_actual_dir)
    except:
      pass
    print 'Creating %s' % self._gm_actual_dir
    try:
      os.makedirs(self._gm_actual_dir)
    except OSError as e:
      if e.errno == errno.EEXIST:
        pass
      else:
        raise e

  def _RunModulo(self, cmd):
    """ Run GM in multiple concurrent processes using the --modulo flag. """
    subprocesses = []
    retcodes = []
    for idx in range(self._num_cores):
      subprocesses.append(shell_utils.BashAsync(cmd + ['--modulo', str(idx),
                                                       str(self._num_cores)]))
    for proc in subprocesses:
      retcode = 0
      try:
        shell_utils.LogProcessToCompletion(proc)
      except:
        retcode = 1
      retcodes.append(retcode)
    for retcode in retcodes:
      if retcode != 0:
        raise Exception('Command failed with code %d.' % retcode)

  def _Run(self):
    self._PreGM()
    cmd = [self._PathToBinary('gm'),
           '-w', self._gm_actual_dir,
           ] + self._gm_args
    self._RunModulo(cmd)

<commit_msg>Fix bots not properly failing on GM<commit_after>#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

""" Run the Skia GM executable. """

from utils import shell_utils
from build_step import BuildStep
import errno
import os
import shutil
import sys


class RunGM(BuildStep):
  def _PreGM(self,):
    print 'Removing %s' % self._gm_actual_dir
    try:
      shutil.rmtree(self._gm_actual_dir)
    except:
      pass
    print 'Creating %s' % self._gm_actual_dir
    try:
      os.makedirs(self._gm_actual_dir)
    except OSError as e:
      if e.errno == errno.EEXIST:
        pass
      else:
        raise e

  def _RunModulo(self, cmd):
    """ Run GM in multiple concurrent processes using the --modulo flag. """
    subprocesses = []
    retcodes = []
    for idx in range(self._num_cores):
      subprocesses.append(shell_utils.BashAsync(cmd + ['--modulo', str(idx),
                                                       str(self._num_cores)]))
    for proc in subprocesses:
      retcode = 0
      try:
        retcode = shell_utils.LogProcessToCompletion(proc)[0]
      except:
        retcode = 1
      retcodes.append(retcode)
    for retcode in retcodes:
      if retcode != 0:
        raise Exception('Command failed with code %d.' % retcode)

  def _Run(self):
    self._PreGM()
    cmd = [self._PathToBinary('gm'),
           '-w', self._gm_actual_dir,
           ] + self._gm_args
    self._RunModulo(cmd)


{'fraction_non_alphanumeric': 0.09828089523191696, 'fraction_numerical': 0.004865390853065196, 'mean_word_length': 2.392739273927393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4606818', 'n_tokens_mistral': 1005, 'n_tokens_neox': 951, 'n_words': 283}