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_location): |
| 24 # |build_location| is typically "out/Debug" or "out/Release". |
| 25 # Expect |my_dir| to be .../pdfium/testing/tools. |
| 26 self.my_dir = os.path.dirname(os.path.realpath(__file__)) |
| 27 self.testing_dir = os.path.dirname(self.my_dir) |
| 28 if (os.path.basename(self.my_dir) != 'tools' or |
| 29 os.path.basename(self.testing_dir) != 'testing'): |
| 30 raise Exception('Confused, can not find pdfium root directory, aborting.') |
| 31 self.pdfium_dir = os.path.dirname(self.testing_dir) |
| 32 # Find path to build directory. This depends on whether this is a |
| 33 # standalone build vs. a build as part of a chromium checkout. For |
| 34 # standalone, we expect a path like .../pdfium/out/Debug, but for |
| 35 # chromium, we expect a path like .../src/out/Debug two levels |
| 36 # higher (to skip over the third_party/pdfium path component under |
| 37 # which chromium sticks pdfium). |
| 38 self.base_dir = self.pdfium_dir |
| 39 one_up_dir = os.path.dirname(self.base_dir) |
| 40 two_up_dir = os.path.dirname(one_up_dir) |
| 41 if (os.path.basename(two_up_dir) == 'src' and |
| 42 os.path.basename(one_up_dir) == 'third_party'): |
| 43 self.base_dir = two_up_dir |
| 44 self.build_dir = os.path.join(self.base_dir, build_location) |
| 45 self.os_name = os_name() |
| 46 |
| 47 def ExecutablePath(self, name): |
| 48 '''Finds compiled binaries under the build path.''' |
| 49 result = os.path.join(self.build_dir, name) |
| 50 if self.os_name == 'win': |
| 51 result = result + '.exe' |
| 52 return result |
| 53 |
| 54 def ScriptPath(self, name): |
| 55 '''Finds other scripts in the same directory as this one.''' |
| 56 return os.path.join(self.my_dir, name) |
| 57 |
| 58 def WorkingDir(self, other_components=''): |
| 59 '''Places generated files under the build directory, not source dir.''' |
| 60 result = os.path.join(self.build_dir, 'gen', 'pdfium') |
| 61 if other_components: |
| 62 result = os.path.join(result, other_components) |
| 63 return result |
| 64 |
| 65 def TestingDir(self, other_components=''): |
| 66 '''Finds test files somewhere under the testing directory.''' |
| 67 result = self.testing_dir |
| 68 if other_components: |
| 69 result = os.path.join(result, other_components) |
| 70 return result |
OLD | NEW |