Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
| 3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import re | 6 import re |
| 7 import shutil | 7 import shutil |
| 8 import sys | 8 import sys |
| 9 import tempfile | 9 import tempfile |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 self.mode = mode | 24 self.mode = mode |
| 25 self.arch = arch | 25 self.arch = arch |
| 26 | 26 |
| 27 def IsBatchable(self): | 27 def IsBatchable(self): |
| 28 return False | 28 return False |
| 29 | 29 |
| 30 def GetStubs(self): | 30 def GetStubs(self): |
| 31 source = self.GetSource() | 31 source = self.GetSource() |
| 32 stub_classes = utils.ParseTestOptions(test.ISOLATE_STUB_PATTERN, source, | 32 stub_classes = utils.ParseTestOptions(test.ISOLATE_STUB_PATTERN, source, |
| 33 self.context.workspace) | 33 self.context.workspace) |
| 34 if stub_classes is None: | |
| 35 return (None, None, None) | |
| 34 (interface, _, classes) = stub_classes[0].partition(':') | 36 (interface, _, classes) = stub_classes[0].partition(':') |
| 35 (interface, _, implementation) = interface.partition('+') | 37 (interface, _, implementation) = interface.partition('+') |
| 36 return (interface, classes, implementation) | 38 return (interface, classes, implementation) |
| 37 | 39 |
| 38 def IsFailureOutput(self, output): | |
| 39 return output.exit_code != 0 or not '##DONE##' in output.stdout | |
| 40 | |
| 41 def BeforeRun(self): | 40 def BeforeRun(self): |
| 42 if not self.context.generate: | 41 if not self.context.generate: |
| 43 return | 42 return |
| 44 command = self.context.GetDartC(self.mode, 'dartc') | |
| 45 (interface, classes, _) = self.GetStubs() | 43 (interface, classes, _) = self.GetStubs() |
| 44 if interface is None: | |
| 45 return | |
| 46 d = join(self.GetPath(), 'generated') | 46 d = join(self.GetPath(), 'generated') |
| 47 if not isdir(d): | 47 if not isdir(d): |
| 48 os.mkdir(d) | 48 os.mkdir(d) |
| 49 tmpdir = tempfile.mkdtemp() | 49 tmpdir = tempfile.mkdtemp() |
| 50 src = join(self.GetPath(), interface) | 50 src = join(self.GetPath(), interface) |
| 51 dest = join(self.GetPath(), GeneratedName(interface)) | 51 dest = join(self.GetPath(), GeneratedName(interface)) |
| 52 (_, tmp) = tempfile.mkstemp() | |
| 53 command = self.context.GetDartC(self.mode, 'dartc') | |
| 52 self.RunCommand(command + [ src, | 54 self.RunCommand(command + [ src, |
| 53 # dartc generates output even if it has no | 55 # dartc generates output even if it has no |
| 54 # output to generate. | 56 # output to generate. |
| 55 '-out', tmpdir, | 57 '-out', tmpdir, |
| 56 '-isolate-stub-out', dest, | 58 '-isolate-stub-out', tmp, |
| 57 '-generate-isolate-stubs', classes ]) | 59 '-generate-isolate-stubs', classes ]) |
| 58 shutil.rmtree(tmpdir) | 60 shutil.rmtree(tmpdir) |
| 59 d = open(dest, 'a') | 61 |
| 62 # Copy comments and # commands from the beginning of the source to | |
| 63 # the beginning of the generated file, then copy the remaining | |
| 64 # source to the end. | |
| 65 d = open(dest, 'w') | |
| 60 s = open(src, 'r') | 66 s = open(src, 'r') |
| 67 t = open(tmp, 'r') | |
| 68 while True: | |
| 69 line = s.readline() | |
| 70 if not (re.match('^\s+$', line) or line.startswith('//') or line.startswit h('#')): | |
|
kasperl
2011/10/24 13:47:01
Long line.
Ben Laurie (Google)
2011/10/24 14:21:42
Will be fixed in next commit.
| |
| 71 break | |
| 72 d.write(line) | |
| 73 d.write(t.read()) | |
| 74 os.remove(tmp) | |
| 75 d.write(line) | |
| 61 d.write(s.read()) | 76 d.write(s.read()) |
| 62 | 77 |
| 63 def GetCommand(self): | 78 def GetCommand(self): |
| 64 # Parse the options by reading the .dart source file. | 79 # Parse the options by reading the .dart source file. |
| 65 source = self.GetSource() | 80 source = self.GetSource() |
| 66 vm_options = utils.ParseTestOptions(test.VM_OPTIONS_PATTERN, source, | 81 vm_options = utils.ParseTestOptions(test.VM_OPTIONS_PATTERN, source, |
| 67 self.context.workspace) | 82 self.context.workspace) |
| 68 dart_options = utils.ParseTestOptions(test.DART_OPTIONS_PATTERN, source, | 83 dart_options = utils.ParseTestOptions(test.DART_OPTIONS_PATTERN, source, |
| 69 self.context.workspace) | 84 self.context.workspace) |
| 70 (interface, _, implementation) = self.GetStubs() | 85 (interface, _, implementation) = self.GetStubs() |
| 71 | 86 |
| 72 # Combine everything into a command array and return it. | 87 # Combine everything into a command array and return it. |
| 73 command = self.context.GetDart(self.mode, self.arch) | 88 command = self.context.GetDart(self.mode, self.arch) |
| 74 files = [ join(self.GetPath(), GeneratedName(interface)) ] | 89 if interface is None: |
| 90 f = self.filename | |
| 91 else: | |
| 92 f = GeneratedName(interface) | |
| 93 files = [ join(self.GetPath(), f) ] | |
| 75 if vm_options: command += vm_options | 94 if vm_options: command += vm_options |
| 76 if dart_options: command += dart_options | 95 if dart_options: command += dart_options |
| 77 else: command += files | 96 else: command += files |
| 78 return command | 97 return command |
| 79 | 98 |
| 80 | 99 |
| 81 class DartStubTestConfiguration(test_configuration.StandardTestConfiguration): | 100 class DartStubTestConfiguration(test_configuration.StandardTestConfiguration): |
| 82 def __init__(self, context, root): | 101 def __init__(self, context, root): |
| 83 super(DartStubTestConfiguration, self).__init__(context, root) | 102 super(DartStubTestConfiguration, self).__init__(context, root) |
| 84 | 103 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 103 tests.append(DartStubTestCase(self.context, | 122 tests.append(DartStubTestCase(self.context, |
| 104 test_path, | 123 test_path, |
| 105 join(root, f), | 124 join(root, f), |
| 106 mode, | 125 mode, |
| 107 arch)) | 126 arch)) |
| 108 return tests | 127 return tests |
| 109 | 128 |
| 110 | 129 |
| 111 def GetConfiguration(context, root): | 130 def GetConfiguration(context, root): |
| 112 return DartStubTestConfiguration(context, root) | 131 return DartStubTestConfiguration(context, root) |
| OLD | NEW |