示例#1
0
def CMDtrace(args):
  """Traces the target using trace_inputs.py.

  It runs the executable without remapping it, and traces all the files it and
  its child processes access. Then the 'read' command can be used to generate an
  updated .isolate file out of it.

  Argument processing stops at the first non-recognized argument and these
  arguments are appended to the command line of the target to run. For example,
  use: isolate.py -r foo.results -- --gtest_filter=Foo.Bar
  """
  parser = OptionParserIsolate(command='trace')
  parser.enable_interspersed_args()
  options, args = parser.parse_args(args)
  complete_state = load_complete_state(options, STATS_ONLY)
  cmd = complete_state.result.command + args
  if not cmd:
    raise ExecutionError('No command to run')
  cmd = trace_inputs.fix_python_path(cmd)
  cwd = os.path.normpath(os.path.join(
      complete_state.root_dir, complete_state.result.relative_cwd))
  logging.info('Running %s, cwd=%s' % (cmd, cwd))
  api = trace_inputs.get_api()
  logfile = complete_state.result_file + '.log'
  api.clean_trace(logfile)
  try:
    with api.get_tracer(logfile) as tracer:
      result, _ = tracer.trace(
          cmd,
          cwd,
          'default',
          True)
  except trace_inputs.TracingFailure, e:
    raise ExecutionError('Tracing failed for: %s\n%s' % (' '.join(cmd), str(e)))
示例#2
0
def CMDrun(args):
  """Runs the test executable in an isolated (temporary) directory.

  All the dependencies are mapped into the temporary directory and the
  directory is cleaned up after the target exits. Warning: if -outdir is
  specified, it is deleted upon exit.

  Argument processing stops at the first non-recognized argument and these
  arguments are appended to the command line of the target to run. For example,
  use: isolate.py -r foo.results -- --gtest_filter=Foo.Bar
  """
  parser = OptionParserIsolate(command='run', require_result=False)
  parser.enable_interspersed_args()
  options, args = parser.parse_args(args)
  complete_state = load_complete_state(options, STATS_ONLY)
  cmd = complete_state.result.command + args
  if not cmd:
    raise ExecutionError('No command to run')
  cmd = trace_inputs.fix_python_path(cmd)
  try:
    if not options.outdir:
      options.outdir = run_test_from_archive.make_temp_dir(
          'isolate', complete_state.root_dir)
    else:
      if not os.path.isdir(options.outdir):
        os.makedirs(options.outdir)
    recreate_tree(
        outdir=options.outdir,
        indir=complete_state.root_dir,
        infiles=complete_state.result.files,
        action=run_test_from_archive.HARDLINK,
        as_sha1=False)
    cwd = os.path.normpath(
        os.path.join(options.outdir, complete_state.result.relative_cwd))
    if not os.path.isdir(cwd):
      # It can happen when no files are mapped from the directory containing the
      # .isolate file. But the directory must exist to be the current working
      # directory.
      os.makedirs(cwd)
    if complete_state.result.read_only:
      run_test_from_archive.make_writable(options.outdir, True)
    logging.info('Running %s, cwd=%s' % (cmd, cwd))
    result = subprocess.call(cmd, cwd=cwd)
  finally:
    if options.outdir:
      run_test_from_archive.rmtree(options.outdir)

  if complete_state.result_file:
    complete_state.save_files()
  return result
示例#3
0
def MODErun(_outdir, state):
    """Always uses a temporary directory."""
    try:
        outdir = tempfile.mkdtemp(prefix="isolate")
        recreate_tree(outdir, state.root_dir, state.result.files.keys(), run_test_from_archive.HARDLINK)
        cwd = os.path.join(outdir, state.result.relative_cwd)
        if not os.path.isdir(cwd):
            os.makedirs(cwd)
        if state.result.read_only:
            run_test_from_archive.make_writable(outdir, True)
        if not state.result.command:
            print "No command to run"
            return 1
        cmd = trace_inputs.fix_python_path(state.result.command)
        logging.info("Running %s, cwd=%s" % (cmd, cwd))
        return subprocess.call(cmd, cwd=cwd)
    finally:
        run_test_from_archive.rmtree(outdir)
示例#4
0
def MODErun(_outdir, state):
    """Always uses a temporary directory."""
    try:
        outdir = tempfile.mkdtemp(prefix='isolate')
        recreate_tree(outdir, state.root_dir, state.result.files.keys(),
                      run_test_from_archive.HARDLINK)
        cwd = os.path.join(outdir, state.result.relative_cwd)
        if not os.path.isdir(cwd):
            os.makedirs(cwd)
        if state.result.read_only:
            run_test_from_archive.make_writable(outdir, True)
        if not state.result.command:
            print 'No command to run'
            return 1
        cmd = trace_inputs.fix_python_path(state.result.command)
        logging.info('Running %s, cwd=%s' % (cmd, cwd))
        return subprocess.call(cmd, cwd=cwd)
    finally:
        run_test_from_archive.rmtree(outdir)
示例#5
0
def MODErun(_outdir, indir, data):
  """Always uses a temporary directory."""
  try:
    outdir = tempfile.mkdtemp(prefix='isolate')
    recreate_tree(
        outdir, indir, data['files'].keys(), run_test_from_archive.HARDLINK)
    cwd = os.path.join(outdir, data['relative_cwd'])
    if not os.path.isdir(cwd):
      os.makedirs(cwd)
    if data['read_only']:
      run_test_from_archive.make_writable(outdir, True)
    if not data['command']:
      print 'No command to run'
      return 1
    cmd = trace_inputs.fix_python_path(data['command'])
    logging.info('Running %s, cwd=%s' % (cmd, cwd))
    return subprocess.call(cmd, cwd=cwd)
  finally:
    run_test_from_archive.rmtree(outdir)
示例#6
0
def CMDrun(args):
  """Runs the test executable in an isolated (temporary) directory.

  All the dependencies are mapped into the temporary directory and the
  directory is cleaned up after the target exits. Warning: if -outdir is
  specified, it is deleted upon exit.
  """
  parser = OptionParserIsolate(command='run', require_result=False)
  options, _ = parser.parse_args(args)
  complete_state = load_complete_state(options, STATS_ONLY)
  try:
    if not options.outdir:
      options.outdir = tempfile.mkdtemp(prefix='isolate')
    else:
      if not os.path.isdir(options.outdir):
        os.makedirs(options.outdir)
    recreate_tree(
        options.outdir,
        complete_state.root_dir,
        complete_state.result.files.keys(),
        run_test_from_archive.HARDLINK)
    cwd = os.path.join(options.outdir, complete_state.result.relative_cwd)
    if not os.path.isdir(cwd):
      os.makedirs(cwd)
    if complete_state.result.read_only:
      run_test_from_archive.make_writable(options.outdir, True)
    if not complete_state.result.command:
      raise ExecutionError('No command to run')
    cmd = trace_inputs.fix_python_path(complete_state.result.command)
    logging.info('Running %s, cwd=%s' % (cmd, cwd))
    result = subprocess.call(cmd, cwd=cwd)
  finally:
    if options.outdir:
      run_test_from_archive.rmtree(options.outdir)

  if complete_state.result_file:
    complete_state.save_files()
  return result