tools/coverity/coverity.py
def run_coverity(options, args):
  """Runs all the selected tests for the given build type and target."""
  # Create the lock file to prevent another instance of this script from
  # running.
  lock_filename = os.path.join(options.source_dir, LOCK_FILE)
  try:
    lock_file = os.open(lock_filename,
                        os.O_CREAT | os.O_EXCL | os.O_TRUNC | os.O_RDWR)
  except OSError, err:
    print('Failed to open lock file:\n  ' + str(err))
    return 1

  # Write the pid of this script (the python.exe process) to the lock file.
  os.write(lock_file, str(os.getpid()))

  options.target = options.target.title()

  start_time = time.time()

  print('Change directory to ' + options.source_dir)
  os.chdir(options.source_dir)

  # The coverity-password filename may have been a relative path.
  # If so, assume it's relative to the source directory, which means
  # the time to read the password is after we do the chdir().
  coverity_password = _ReadPassword(options.coverity_password_file)

  cmd = 'gclient sync'
  gclient_exit = _RunCommand(cmd, options.dry_run, shell=True)
  if gclient_exit != 0:
    print('gclient aborted with status %s' % gclient_exit)
    _ReleaseLock(lock_file, lock_filename)
    return 1

  print('Elapsed time: %ds' % (time.time() - start_time))

  # Do a clean build.  Remove the build output directory first.
  if sys.platform.startswith('linux'):
    rm_path = os.path.join(options.source_dir,'src','out',options.target)
  elif sys.platform == 'win32':
    rm_path = os.path.join(options.source_dir,options.solution_dir,
                           options.target)
  elif sys.platform == 'darwin':
    rm_path = os.path.join(options.source_dir,'src','xcodebuild')
  else:
    print('Platform "%s" unrecognized, aborting' % sys.platform)
    _ReleaseLock(lock_file, lock_filename)
    return 1

  if options.dry_run:
    print('shutil.rmtree(%s)' % repr(rm_path))
  else:
    shutil.rmtree(rm_path,True)

  if options.preserve_intermediate_dir:
    print('Preserving intermediate directory.')
  else:
    if options.dry_run:
      print('shutil.rmtree(%s)' % repr(options.coverity_intermediate_dir))
      print('os.mkdir(%s)' % repr(options.coverity_intermediate_dir))
    else:
      shutil.rmtree(options.coverity_intermediate_dir,True)
      os.mkdir(options.coverity_intermediate_dir)

  print('Elapsed time: %ds' % (time.time() - start_time))

  use_shell_during_make = False
  if sys.platform.startswith('linux'):
    use_shell_during_make = True
    os.chdir('src')
    _RunCommand('pwd', options.dry_run, shell=True)
    cmd = '%s/cov-build --dir %s make BUILDTYPE=%s chrome' % (
      options.coverity_bin_dir, options.coverity_intermediate_dir,
      options.target)
  elif sys.platform == 'win32':
    cmd = ('%s\\cov-build.exe --dir %s devenv.com %s\\%s /build %s '
           '/project chrome.vcproj') % (
      options.coverity_bin_dir, options.coverity_intermediate_dir,
      options.source_dir, options.solution_file, options.target)
  elif sys.platform == 'darwin':
    use_shell_during_make = True
    os.chdir('src/chrome')
    _RunCommand('pwd', options.dry_run, shell=True)
    cmd = ('%s/cov-build --dir %s xcodebuild -project chrome.xcodeproj '
           '-configuration %s -target chrome') % (
      options.coverity_bin_dir, options.coverity_intermediate_dir,
      options.target)


  _RunCommand(cmd, options.dry_run, shell=use_shell_during_make)
  print('Elapsed time: %ds' % (time.time() - start_time))

  cov_analyze_exe = os.path.join(options.coverity_bin_dir,'cov-analyze')
  cmd = '%s --dir %s %s' % (cov_analyze_exe,
                            options.coverity_intermediate_dir,
                            options.coverity_analyze_options)
  _RunCommand(cmd, options.dry_run, shell=use_shell_during_make)
  print('Elapsed time: %ds' % (time.time() - start_time))

  cov_commit_exe = os.path.join(options.coverity_bin_dir,'cov-commit-defects')

  # On Linux we have started using a Target with a space in it, so we want
  # to quote it. On the other hand, Windows quoting doesn't work quite the
  # same way. To be conservative, I'd like to avoid quoting an argument
  # that doesn't need quoting and which we haven't historically been quoting
  # on that platform. So, only quote the target if we have to.
  coverity_target = options.coverity_target
  if sys.platform != 'win32':
    coverity_target = '"%s"' % coverity_target

  cmd = ('%s --dir %s --remote %s --port %s '
         '--product %s '
         '--target %s '
         '--user %s '
         '--password %s') % (cov_commit_exe,
                             options.coverity_intermediate_dir,
                             options.coverity_dbhost,
                             options.coverity_port,
                             options.coverity_product,
                             coverity_target,
                             options.coverity_user,
                             coverity_password)
  # Avoid echoing the Commit command because it has a password in it
  _RunCommand(cmd, options.dry_run, shell=use_shell_during_make, echo_cmd=False)

  print('Total time: %ds' % (time.time() - start_time))

  _ReleaseLock(lock_file, lock_filename)

  return 0
Runs all the selected tests for the given build type and target.
Runs all the selected tests for the given build type and target.
Runs all the selected tests for the given build type and target .
def run_coverity(options, args):
  lock_filename = os.path.join(options.source_dir, LOCK_FILE)
  try:
    lock_file = os.open(lock_filename,
                        os.O_CREAT | os.O_EXCL | os.O_TRUNC | os.O_RDWR)
  except OSError, err:
    print('Failed to open lock file:\n  ' + str(err))
    return 1
  os.write(lock_file, str(os.getpid()))
  options.target = options.target.title()
  start_time = time.time()
  print('Change directory to ' + options.source_dir)
  os.chdir(options.source_dir)
  coverity_password = _ReadPassword(options.coverity_password_file)
  cmd = 'gclient sync'
  gclient_exit = _RunCommand(cmd, options.dry_run, shell=True)
  if gclient_exit != 0:
    print('gclient aborted with status %s' % gclient_exit)
    _ReleaseLock(lock_file, lock_filename)
    return 1
  print('Elapsed time: %ds' % (time.time() - start_time))
  if sys.platform.startswith('linux'):
    rm_path = os.path.join(options.source_dir,'src','out',options.target)
  elif sys.platform == 'win32':
    rm_path = os.path.join(options.source_dir,options.solution_dir,
                           options.target)
  elif sys.platform == 'darwin':
    rm_path = os.path.join(options.source_dir,'src','xcodebuild')
  else:
    print('Platform "%s" unrecognized, aborting' % sys.platform)
    _ReleaseLock(lock_file, lock_filename)
    return 1
  if options.dry_run:
    print('shutil.rmtree(%s)' % repr(rm_path))
  else:
    shutil.rmtree(rm_path,True)
  if options.preserve_intermediate_dir:
    print('Preserving intermediate directory.')
  else:
    if options.dry_run:
      print('shutil.rmtree(%s)' % repr(options.coverity_intermediate_dir))
      print('os.mkdir(%s)' % repr(options.coverity_intermediate_dir))
    else:
      shutil.rmtree(options.coverity_intermediate_dir,True)
      os.mkdir(options.coverity_intermediate_dir)
  print('Elapsed time: %ds' % (time.time() - start_time))
  use_shell_during_make = False
  if sys.platform.startswith('linux'):
    use_shell_during_make = True
    os.chdir('src')
    _RunCommand('pwd', options.dry_run, shell=True)
    cmd = '%s/cov-build --dir %s make BUILDTYPE=%s chrome' % (
      options.coverity_bin_dir, options.coverity_intermediate_dir,
      options.target)
  elif sys.platform == 'win32':
    cmd = ('%s\\cov-build.exe --dir %s devenv.com %s\\%s /build %s '
           '/project chrome.vcproj') % (
      options.coverity_bin_dir, options.coverity_intermediate_dir,
      options.source_dir, options.solution_file, options.target)
  elif sys.platform == 'darwin':
    use_shell_during_make = True
    os.chdir('src/chrome')
    _RunCommand('pwd', options.dry_run, shell=True)
    cmd = ('%s/cov-build --dir %s xcodebuild -project chrome.xcodeproj '
           '-configuration %s -target chrome') % (
      options.coverity_bin_dir, options.coverity_intermediate_dir,
      options.target)
  _RunCommand(cmd, options.dry_run, shell=use_shell_during_make)
  print('Elapsed time: %ds' % (time.time() - start_time))
  cov_analyze_exe = os.path.join(options.coverity_bin_dir,'cov-analyze')
  cmd = '%s --dir %s %s' % (cov_analyze_exe,
                            options.coverity_intermediate_dir,
                            options.coverity_analyze_options)
  _RunCommand(cmd, options.dry_run, shell=use_shell_during_make)
  print('Elapsed time: %ds' % (time.time() - start_time))
  cov_commit_exe = os.path.join(options.coverity_bin_dir,'cov-commit-defects')
  coverity_target = options.coverity_target
  if sys.platform != 'win32':
    coverity_target = '"%s"' % coverity_target
  cmd = ('%s --dir %s --remote %s --port %s '
         '--product %s '
         '--target %s '
         '--user %s '
         '--password %s') % (cov_commit_exe,
                             options.coverity_intermediate_dir,
                             options.coverity_dbhost,
                             options.coverity_port,
                             options.coverity_product,
                             coverity_target,
                             options.coverity_user,
                             coverity_password)
  _RunCommand(cmd, options.dry_run, shell=use_shell_during_make, echo_cmd=False)
  print('Total time: %ds' % (time.time() - start_time))
  _ReleaseLock(lock_file, lock_filename)
  return 0
def run_coverity ( options , args ) : lock_filename = os . path . join ( options . source_dir , LOCK_FILE ) try : lock_file = os . open ( lock_filename , os . O_CREAT | os . O_EXCL | os . O_TRUNC | os . O_RDWR ) except OSError , err : print ( 'Failed to open lock file:\n  ' + str ( err ) ) return 1 os . write ( lock_file , str ( os . getpid ( ) ) ) options . target = options . target . title ( ) start_time = time . time ( ) print ( 'Change directory to ' + options . source_dir ) os . chdir ( options . source_dir ) coverity_password = _ReadPassword ( options . coverity_password_file ) cmd = 'gclient sync' gclient_exit = _RunCommand ( cmd , options . dry_run , shell = True ) if gclient_exit != 0 : print ( 'gclient aborted with status %s' % gclient_exit ) _ReleaseLock ( lock_file , lock_filename ) return 1 print ( 'Elapsed time: %ds' % ( time . time ( ) - start_time ) ) if sys . platform . startswith ( 'linux' ) : rm_path = os . path . join ( options . source_dir , 'src' , 'out' , options . target ) elif sys . platform == 'win32' : rm_path = os . path . join ( options . source_dir , options . solution_dir , options . target ) elif sys . platform == 'darwin' : rm_path = os . path . join ( options . source_dir , 'src' , 'xcodebuild' ) else : print ( 'Platform "%s" unrecognized, aborting' % sys . platform ) _ReleaseLock ( lock_file , lock_filename ) return 1 if options . dry_run : print ( 'shutil.rmtree(%s)' % repr ( rm_path ) ) else : shutil . rmtree ( rm_path , True ) if options . preserve_intermediate_dir : print ( 'Preserving intermediate directory.' ) else : if options . dry_run : print ( 'shutil.rmtree(%s)' % repr ( options . coverity_intermediate_dir ) ) print ( 'os.mkdir(%s)' % repr ( options . coverity_intermediate_dir ) ) else : shutil . rmtree ( options . coverity_intermediate_dir , True ) os . mkdir ( options . coverity_intermediate_dir ) print ( 'Elapsed time: %ds' % ( time . time ( ) - start_time ) ) use_shell_during_make = False if sys . platform . startswith ( 'linux' ) : use_shell_during_make = True os . chdir ( 'src' ) _RunCommand ( 'pwd' , options . dry_run , shell = True ) cmd = '%s/cov-build --dir %s make BUILDTYPE=%s chrome' % ( options . coverity_bin_dir , options . coverity_intermediate_dir , options . target ) elif sys . platform == 'win32' : cmd = ( '%s\\cov-build.exe --dir %s devenv.com %s\\%s /build %s ' '/project chrome.vcproj' ) % ( options . coverity_bin_dir , options . coverity_intermediate_dir , options . source_dir , options . solution_file , options . target ) elif sys . platform == 'darwin' : use_shell_during_make = True os . chdir ( 'src/chrome' ) _RunCommand ( 'pwd' , options . dry_run , shell = True ) cmd = ( '%s/cov-build --dir %s xcodebuild -project chrome.xcodeproj ' '-configuration %s -target chrome' ) % ( options . coverity_bin_dir , options . coverity_intermediate_dir , options . target ) _RunCommand ( cmd , options . dry_run , shell = use_shell_during_make ) print ( 'Elapsed time: %ds' % ( time . time ( ) - start_time ) ) cov_analyze_exe = os . path . join ( options . coverity_bin_dir , 'cov-analyze' ) cmd = '%s --dir %s %s' % ( cov_analyze_exe , options . coverity_intermediate_dir , options . coverity_analyze_options ) _RunCommand ( cmd , options . dry_run , shell = use_shell_during_make ) print ( 'Elapsed time: %ds' % ( time . time ( ) - start_time ) ) cov_commit_exe = os . path . join ( options . coverity_bin_dir , 'cov-commit-defects' ) coverity_target = options . coverity_target if sys . platform != 'win32' : coverity_target = '"%s"' % coverity_target cmd = ( '%s --dir %s --remote %s --port %s ' '--product %s ' '--target %s ' '--user %s ' '--password %s' ) % ( cov_commit_exe , options . coverity_intermediate_dir , options . coverity_dbhost , options . coverity_port , options . coverity_product , coverity_target , options . coverity_user , coverity_password ) _RunCommand ( cmd , options . dry_run , shell = use_shell_during_make , echo_cmd = False ) print ( 'Total time: %ds' % ( time . time ( ) - start_time ) ) _ReleaseLock ( lock_file , lock_filename ) return 0
Runs all the selected tests for the given build type and target.
Runs all the selected tests for the given build type and target .
"""Runs all the selected tests for the given build type and target.""" # Create the lock file to prevent another instance of this script from # running. # Write the pid of this script (the python.exe process) to the lock file. # The coverity-password filename may have been a relative path. # If so, assume it's relative to the source directory, which means # the time to read the password is after we do the chdir(). # Do a clean build.  Remove the build output directory first. # On Linux we have started using a Target with a space in it, so we want # to quote it. On the other hand, Windows quoting doesn't work quite the # same way. To be conservative, I'd like to avoid quoting an argument # that doesn't need quoting and which we haven't historically been quoting # on that platform. So, only quote the target if we have to. # Avoid echoing the Commit command because it has a password in it
options
args