OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The PDFium Authors. All rights reserved. | 2 # Copyright 2015 The PDFium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import optparse | 6 import optparse |
7 import os | 7 import os |
8 import re | 8 import re |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
11 | 11 |
| 12 import common |
| 13 |
12 # Nomenclature: | 14 # Nomenclature: |
13 # x_root - "x" | 15 # x_root - "x" |
14 # x_filename - "x.ext" | 16 # x_filename - "x.ext" |
15 # x_path - "path/to/a/b/c/x.ext" | 17 # x_path - "path/to/a/b/c/x.ext" |
16 # c_dir - "path/to/a/b/c" | 18 # c_dir - "path/to/a/b/c" |
17 | 19 |
18 def generate_and_test(input_filename, source_dir, working_dir, | 20 def generate_and_test(input_filename, source_dir, working_dir, |
19 fixup_path, pdfium_test_path, text_diff_path): | 21 fixup_path, pdfium_test_path, text_diff_path): |
20 input_root, _ = os.path.splitext(input_filename) | 22 input_root, _ = os.path.splitext(input_filename) |
21 input_path = os.path.join(source_dir, input_root + '.in') | 23 input_path = os.path.join(source_dir, input_root + '.in') |
(...skipping 11 matching lines...) Expand all Loading... |
33 except subprocess.CalledProcessError as e: | 35 except subprocess.CalledProcessError as e: |
34 print "FAILURE: " + input_filename + "; " + str(e) | 36 print "FAILURE: " + input_filename + "; " + str(e) |
35 return False | 37 return False |
36 return True | 38 return True |
37 | 39 |
38 def main(): | 40 def main(): |
39 parser = optparse.OptionParser() | 41 parser = optparse.OptionParser() |
40 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), | 42 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), |
41 help='relative path from the base source directory') | 43 help='relative path from the base source directory') |
42 options, args = parser.parse_args() | 44 options, args = parser.parse_args() |
43 | 45 finder = common.DirectoryFinder(options.build_dir) |
44 # Expect |my_dir| to be .../pdfium/testing/tools. | 46 fixup_path = finder.ScriptPath('fixup_pdf_template.py') |
45 my_dir = os.path.dirname(os.path.realpath(__file__)) | 47 text_diff_path = finder.ScriptPath('text_diff.py') |
46 testing_dir = os.path.dirname(my_dir) | 48 source_dir = finder.TestingDir(os.path.join('resources', 'javascript')) |
47 pdfium_dir = os.path.dirname(testing_dir) | 49 pdfium_test_path = finder.ExecutablePath('pdfium_test') |
48 if (os.path.basename(my_dir) != 'tools' or | 50 working_dir = finder.WorkingDir(os.path.join('testing', 'javascript')) |
49 os.path.basename(testing_dir) != 'testing'): | |
50 print 'Confused, can not find pdfium root directory, aborting.' | |
51 return 1 | |
52 | |
53 # Other scripts are found in the same directory as this one. | |
54 fixup_path = os.path.join(my_dir, 'fixup_pdf_template.py') | |
55 text_diff_path = os.path.join(my_dir, 'text_diff.py') | |
56 | |
57 # test files are in .../pdfium/testing/resources/javascript. | |
58 source_dir = os.path.join(testing_dir, 'resources', 'javascript') | |
59 | |
60 # Find path to build directory. This depends on whether this is a | |
61 # standalone build vs. a build as part of a chromium checkout. For | |
62 # standalone, we expect a path like .../pdfium/out/Debug, but for | |
63 # chromium, we expect a path like .../src/out/Debug two levels | |
64 # higher (to skip over the third_party/pdfium path component under | |
65 # which chromium sticks pdfium). | |
66 base_dir = pdfium_dir | |
67 one_up_dir = os.path.dirname(base_dir) | |
68 two_up_dir = os.path.dirname(one_up_dir) | |
69 if (os.path.basename(two_up_dir) == 'src' and | |
70 os.path.basename(one_up_dir) == 'third_party'): | |
71 base_dir = two_up_dir | |
72 build_dir = os.path.join(base_dir, options.build_dir) | |
73 | |
74 # Compiled binaries are found under the build path. | |
75 pdfium_test_path = os.path.join(build_dir, 'pdfium_test') | |
76 if sys.platform.startswith('win'): | |
77 pdfium_test_path = pdfium_test_path + '.exe' | |
78 # TODO(tsepez): Mac may require special handling here. | |
79 | |
80 # Place generated files under the build directory, not source directory. | |
81 gen_dir = os.path.join(build_dir, 'gen', 'pdfium') | |
82 working_dir = os.path.join(gen_dir, 'testing', 'javascript') | |
83 if not os.path.exists(working_dir): | 51 if not os.path.exists(working_dir): |
84 os.makedirs(working_dir) | 52 os.makedirs(working_dir) |
85 | 53 |
86 failures = [] | 54 failures = [] |
87 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') | 55 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') |
88 for input_filename in os.listdir(source_dir): | 56 for input_filename in os.listdir(source_dir): |
89 if input_file_re.match(input_filename): | 57 if input_file_re.match(input_filename): |
90 input_path = os.path.join(source_dir, input_filename) | 58 input_path = os.path.join(source_dir, input_filename) |
91 if os.path.isfile(input_path): | 59 if os.path.isfile(input_path): |
92 if not generate_and_test(input_filename, source_dir, working_dir, | 60 if not generate_and_test(input_filename, source_dir, working_dir, |
93 fixup_path, pdfium_test_path, text_diff_path): | 61 fixup_path, pdfium_test_path, text_diff_path): |
94 failures.append(input_path) | 62 failures.append(input_path) |
95 | 63 |
96 if failures: | 64 if failures: |
97 print '\n\nSummary of Failures:' | 65 print '\n\nSummary of Failures:' |
98 for failure in failures: | 66 for failure in failures: |
99 print failure | 67 print failure |
100 return 1 | 68 return 1 |
101 return 0 | 69 return 0 |
102 | 70 |
103 | 71 |
104 if __name__ == '__main__': | 72 if __name__ == '__main__': |
105 sys.exit(main()) | 73 sys.exit(main()) |
OLD | NEW |