Index: isolate/isolate.py |
=================================================================== |
--- isolate/isolate.py (revision 0) |
+++ isolate/isolate.py (revision 0) |
@@ -0,0 +1,123 @@ |
+#!/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. |
+ |
+"""Recreates a tree of files and run an executable in it. |
+ |
+The executable is usually a test. |
+ |
+On linux, starts an xvfb X session to run the executable in. |
+""" |
+ |
+import json |
+import logging |
+import optparse |
+import os |
+import re |
+import subprocess |
+import sys |
+ |
+import tree_creator |
+import xvfb |
+ |
+ |
+class ParserError(Exception): |
+ pass |
+ |
+ |
+def recreate_tree(options): |
+ """Reads a manifest and recreates a tree.""" |
+ os_map = {'cygwin': 'win32', 'linux2': 'linux', 'darwin': 'mac'} |
+ platform = os_map.get(sys.platform, sys.platform) |
+ infiles = ['.'] |
+ if options.manifest: |
+ data = json.load(open(options.manifest, 'r')) |
+ options.outdir = options.outdir or data['outdir'] |
+ options.indir = options.indir or data['indir'] |
+ infiles = data['infiles'] |
+ infiles += data.get('os', {}).get(platform, []) |
+ if not options.outdir or not options.indir: |
+ raise ParserError('Need at least -o and -i or -m') |
+ |
+ outdir = { |
+ 'win32': 'build', |
+ 'linux': 'out', |
+ 'mac': 'xcodebuild', |
+ } |
+ variables = { |
+ 'OUTDIR': outdir[platform] + '/Debug/', |
+ } |
+ infiles = [i % variables for i in infiles] |
+ |
+ action = tree_creator.HARDLINK |
+ if options.dry_run: |
+ action = tree_creator.DRY_RUN |
+ |
+ def blacklist(item): |
+ return ( |
+ re.match(r'.*\.svn$', item) != None or |
+ re.match(r'.*\.pyc$', item) != None) |
+ |
+ tree_creator.recreate_tree( |
+ options.outdir, options.indir, infiles, action, blacklist) |
+ |
+ |
+def run_executable(options, args): |
+ env = os.environ.copy() |
+ # Many tests assume a English interface... |
+ env['LANGUAGE'] = 'en' |
+ # Used by base/base_paths_linux.cc |
+ env['CR_SOURCE_ROOT'] = os.path.abspath(options.outdir).encode() |
+ unique_name = 'not_so_unique' |
+ try: |
+ if not options.no_x: |
+ # TODO(maruel): To not hardcode out/Debug. |
+ env['DISPLAY'] = xvfb.start_virtualx( |
+ unique_name, |
+ os.path.join(options.outdir, 'out', 'Debug')) |
+ os.chdir(options.outdir) |
+ logging.info('Running %s' % ' '.join(args)) |
+ return subprocess.call(args, env=env) |
+ finally: |
+ if not options.no_x: |
+ xvfb.stop_virtualx(unique_name) |
+ |
+ |
+def main(): |
+ parser = optparse.OptionParser( |
+ usage='%prog [options] [test command line...]', |
+ description=sys.modules[__name__].__doc__) |
+ parser.allow_interspersed_args = False |
+ parser.add_option('-v', '--verbose', action='count') |
+ parser.add_option('--dry-run', action='store_true') |
+ parser.add_option( |
+ '-m', '--manifest', |
+ help='json file containing the arguments.') |
+ if sys.platform == 'linux2': |
+ parser.add_option('--no_x', action='store_true') |
+ parser.add_option('-i', '--indir') |
+ parser.add_option('-o', '--outdir') |
+ options, args = parser.parse_args() |
+ if options.verbose == 2: |
+ level = logging.DEBUG |
+ elif options.verbose == 1: |
+ level = logging.INFO |
+ else: |
+ level = logging.ERROR |
+ logging.basicConfig(level=level) |
+ |
+ if sys.platform != 'linux2': |
+ options.no_x = True |
+ |
+ try: |
+ recreate_tree(options) |
+ if not args: |
+ return 0 |
+ return run_executable(options, args) |
+ except ParserError, e: |
+ parser.error(*e.args) |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main()) |
Property changes on: isolate/isolate.py |
___________________________________________________________________ |
Added: svn:executable |
+ * |
Added: svn:eol-style |
+ LF |