OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # |
2 # Copyright 2014 the V8 project authors. All rights reserved. | 3 # Copyright 2014 the V8 project authors. All rights reserved. |
3 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
5 # met: | 6 # met: |
6 # | 7 # |
7 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following | 11 # copyright notice, this list of conditions and the following |
11 # disclaimer in the documentation and/or other materials provided | 12 # disclaimer in the documentation and/or other materials provided |
12 # with the distribution. | 13 # with the distribution. |
13 # * Neither the name of Google Inc. nor the names of its | 14 # * Neither the name of Google Inc. nor the names of its |
14 # contributors may be used to endorse or promote products derived | 15 # contributors may be used to endorse or promote products derived |
15 # from this software without specific prior written permission. | 16 # from this software without specific prior written permission. |
16 # | 17 # |
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 29 |
29 # Wraps test execution with a coverage analysis. To get the best speed, the | 30 # This utility concatenates several files into one. On Unix-like systems |
30 # native python coverage version >= 3.7.1 should be installed. | 31 # it is equivalent to: |
| 32 # cat file1 file2 file3 ...files... > target |
| 33 # |
| 34 # The reason for writing a seperate utility is that 'cat' is not available |
| 35 # on all supported build platforms, but Python is, and hence this provides |
| 36 # us with an easy and uniform way of doing this on all platforms. |
31 | 37 |
32 import coverage | 38 import optparse |
33 import os | |
34 import unittest | |
35 import sys | |
36 | 39 |
37 | 40 |
38 def Main(argv): | 41 def Concatenate(filenames): |
39 script_path = os.path.dirname(os.path.abspath(__file__)) | 42 """Concatenate files. |
40 cov = coverage.coverage(include=([os.path.join(script_path, '*.py')])) | 43 |
41 cov.start() | 44 Args: |
42 import test_scripts | 45 files: Array of file names. |
43 alltests = map(unittest.TestLoader().loadTestsFromTestCase, [ | 46 The last name is the target; all earlier ones are sources. |
44 test_scripts.ToplevelTest, | 47 |
45 test_scripts.ScriptTest, | 48 Returns: |
46 test_scripts.SystemTest, | 49 True, if the operation was successful. |
47 ]) | 50 """ |
48 unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite(alltests)) | 51 if len(filenames) < 2: |
49 cov.stop() | 52 print "An error occured generating %s:\nNothing to do." % filenames[-1] |
50 print cov.report() | 53 return False |
| 54 |
| 55 try: |
| 56 with open(filenames[-1], "wb") as target: |
| 57 for filename in filenames[:-1]: |
| 58 with open(filename, "rb") as current: |
| 59 target.write(current.read()) |
| 60 return True |
| 61 except IOError as e: |
| 62 print "An error occured when writing %s:\n%s" % (filenames[-1], e) |
| 63 return False |
51 | 64 |
52 | 65 |
53 if __name__ == '__main__': | 66 def main(): |
54 sys.exit(Main(sys.argv)) | 67 parser = optparse.OptionParser() |
| 68 parser.set_usage("""Concatenate several files into one. |
| 69 Equivalent to: cat file1 ... > target.""") |
| 70 (options, args) = parser.parse_args() |
| 71 exit(0 if Concatenate(args) else 1) |
| 72 |
| 73 |
| 74 if __name__ == "__main__": |
| 75 main() |
OLD | NEW |