OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Top-level presubmit script for depot tools. |
| 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
| 8 details on the presubmit API built into gcl. |
| 9 """ |
| 10 |
| 11 |
| 12 def CheckChangeOnUpload(input_api, output_api): |
| 13 return RunTests(input_api, output_api) |
| 14 |
| 15 |
| 16 def CheckChangeOnCommit(input_api, output_api): |
| 17 return RunTests(input_api, output_api) |
| 18 |
| 19 |
| 20 def RunTests(input_api, output_api): |
| 21 """Run all the shells scripts in the directory test. |
| 22 |
| 23 Also verify the GAE python SDK is available, fetches Rietveld if necessary and |
| 24 start a test instance to test against. |
| 25 """ |
| 26 # They are not exposed from InputApi. |
| 27 from os import listdir, pathsep |
| 28 import socket |
| 29 import time |
| 30 |
| 31 # Shortcuts |
| 32 join = input_api.os_path.join |
| 33 error = output_api.PresubmitError |
| 34 |
| 35 # Paths |
| 36 sdk_path = input_api.os_path.abspath(join('..', '..', 'google_appengine')) |
| 37 dev_app = join(sdk_path, 'dev_appserver.py') |
| 38 rietveld = join('test', 'rietveld') |
| 39 django_path = join(rietveld, 'django') |
| 40 |
| 41 # Generate a friendly environment. |
| 42 env = input_api.environ.copy() |
| 43 env['LANGUAGE'] = 'en' |
| 44 if env.get('PYTHONPATH'): |
| 45 env['PYTHONPATH'] = (env['PYTHONPATH'].rstrip(pathsep) + pathsep + |
| 46 django_path) |
| 47 else: |
| 48 env['PYTHONPATH'] = django_path |
| 49 |
| 50 def call(*args, **kwargs): |
| 51 kwargs['env'] = env |
| 52 x = input_api.subprocess.Popen(*args, **kwargs) |
| 53 x.communicate() |
| 54 return x.returncode == 0 |
| 55 |
| 56 def test_port(port): |
| 57 s = socket.socket() |
| 58 try: |
| 59 return s.connect_ex(('127.0.0.1', port)) == 0 |
| 60 finally: |
| 61 s.close() |
| 62 |
| 63 # First, verify the Google AppEngine SDK is available. |
| 64 if not input_api.os_path.isfile(dev_app): |
| 65 return [error('Install google_appengine sdk in %s' % sdk_path)] |
| 66 |
| 67 # Second, checkout rietveld and django if not available. |
| 68 if not input_api.os_path.isdir(rietveld): |
| 69 print('Checking out rietveld...') |
| 70 if not call(['svn', 'co', '-q', |
| 71 'http://rietveld.googlecode.com/svn/trunk@563', |
| 72 rietveld]): |
| 73 return [error('Failed to checkout rietveld')] |
| 74 if not input_api.os_path.isdir(django_path): |
| 75 print('Checking out django...') |
| 76 if not call( |
| 77 ['svn', 'co', '-q', |
| 78 'http://code.djangoproject.com/' |
| 79 'svn/django/branches/releases/1.0.X/django@13637', |
| 80 django_path]): |
| 81 return [error('Failed to checkout django')] |
| 82 |
| 83 |
| 84 # Test to find an available port starting at 8080. |
| 85 port = 8080 |
| 86 while test_port(port) and port < 65000: |
| 87 port += 1 |
| 88 if port == 65000: |
| 89 return [error('Having issues finding an available port')] |
| 90 |
| 91 verbose = False |
| 92 if verbose: |
| 93 stdout = None |
| 94 stderr = None |
| 95 else: |
| 96 stdout = input_api.subprocess.PIPE |
| 97 stderr = input_api.subprocess.PIPE |
| 98 output = [] |
| 99 test_server = input_api.subprocess.Popen( |
| 100 [dev_app, rietveld, '--port=%d' % port, |
| 101 '--datastore_path=' + join(rietveld, 'tmp.db'), '-c'], |
| 102 stdout=stdout, stderr=stderr, env=env) |
| 103 try: |
| 104 # Loop until port 127.0.0.1:port opens or the process dies. |
| 105 while not test_port(port): |
| 106 test_server.poll() |
| 107 if test_server.returncode is not None: |
| 108 output.append(error('Test rietveld instance failed early')) |
| 109 break |
| 110 time.sleep(0.001) |
| 111 |
| 112 test_path = input_api.os_path.abspath('test') |
| 113 for test in listdir(test_path): |
| 114 # push-from-logs and rename fails for now. Remove from this list once they |
| 115 # work. |
| 116 if (test in ('push-from-logs.sh', 'rename.sh', 'test-lib.sh') or |
| 117 not test.endswith('.sh')): |
| 118 continue |
| 119 print('Running %s' % test) |
| 120 if not call([join(test_path, test)], cwd=test_path, stdout=stdout): |
| 121 output.append(error('%s failed' % test)) |
| 122 finally: |
| 123 test_server.kill() |
| 124 return output |
OLD | NEW |