OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 import os | |
7 import sys | |
8 | |
9 def os_name(): | |
10 if sys.platform.startswith('linux'): | |
11 return 'linux' | |
12 if sys.platform.startswith('win'): | |
13 return 'win' | |
14 if sys.platform.startswith('darwin'): | |
15 return 'mac' | |
16 raise Exception('Confused, can not determine OS, aborting.') | |
17 | |
18 | |
19 class DirectoryFinder: | |
20 '''A class for finding directories and paths under either a standalone | |
21 checkout or a chromium checkout of PDFium.''' | |
22 | |
23 def __init__(self, build_type): | |
Lei Zhang
2015/04/03 19:50:27
You may want to add a comment to explain what buil
Tom Sepez
2015/04/03 20:19:50
Done.
| |
24 # Expect |my_dir| to be .../pdfium/testing/tools. | |
25 self.my_dir = os.path.dirname(os.path.realpath(__file__)) | |
26 self.testing_dir = os.path.dirname(self.my_dir) | |
27 if (os.path.basename(self.my_dir) != 'tools' or | |
28 os.path.basename(self.testing_dir) != 'testing'): | |
29 raise Exception('Confused, can not find pdfium root directory, aborting.') | |
30 self.pdfium_dir = os.path.dirname(self.testing_dir) | |
31 # Find path to build directory. This depends on whether this is a | |
32 # standalone build vs. a build as part of a chromium checkout. For | |
33 # standalone, we expect a path like .../pdfium/out/Debug, but for | |
34 # chromium, we expect a path like .../src/out/Debug two levels | |
35 # higher (to skip over the third_party/pdfium path component under | |
36 # which chromium sticks pdfium). | |
37 self.base_dir = self.pdfium_dir | |
38 one_up_dir = os.path.dirname(self.base_dir) | |
39 two_up_dir = os.path.dirname(one_up_dir) | |
40 if (os.path.basename(two_up_dir) == 'src' and | |
41 os.path.basename(one_up_dir) == 'third_party'): | |
42 self.base_dir = two_up_dir | |
43 self.build_dir = os.path.join(self.base_dir, build_type) | |
44 self.os_name = os_name() | |
45 | |
46 def ExecutablePath(self, name): | |
47 '''Finds compiled binaries under the build path.''' | |
48 result = os.path.join(self.build_dir, name) | |
49 if self.os_name == 'win': | |
50 result = result + '.exe' | |
51 return result | |
52 | |
53 def ScriptPath(self, name): | |
54 '''Finds other scripts in the same directory as this one.''' | |
55 return os.path.join(self.my_dir, name) | |
56 | |
57 def WorkingDir(self, other_components=''): | |
58 '''Places generated files under the build directory, not source dir.''' | |
59 result = os.path.join(self.build_dir, 'gen', 'pdfium') | |
60 if other_components: | |
61 result = os.path.join(result, other_components) | |
62 return result | |
63 | |
64 def TestingDir(self, other_components=''): | |
65 '''Finds test files somewhere under the testing directory.''' | |
66 result = self.testing_dir | |
67 if other_components: | |
68 result = os.path.join(result, other_components) | |
69 return result | |
OLD | NEW |