Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 1 | # Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | """ |
| 5 | Helper to find the path to the correct third_party directory |
| 6 | """ |
| 7 | |
| 8 | from os import path |
| 9 | import sys |
| 10 | |
| 11 | |
| 12 | # Find the root path of the checkout. |
| 13 | # In the Chromium repository, this is the src/chromium directory. |
| 14 | # In the external repository, standalone build, this is the devtools-frontend directory. |
| 15 | # In the external repository, integrated build, this is the src/chromium directory. |
| 16 | def root_path(): |
| 17 | SCRIPTS_PATH = path.dirname(path.abspath(__file__)) |
| 18 | ABS_DEVTOOLS_PATH = path.dirname(SCRIPTS_PATH) |
| 19 | PARENT_PATH = path.dirname(ABS_DEVTOOLS_PATH) |
| 20 | # TODO(1011259): remove Chromium repository handling |
| 21 | if path.basename(PARENT_PATH) == 'renderer': |
| 22 | # Chromium repository |
| 23 | return path.dirname(path.dirname(path.dirname(PARENT_PATH))) |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 24 | elif path.basename(PARENT_PATH) == 'devtools-frontend': |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 25 | # External repository, integrated build |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 26 | return path.dirname(path.dirname(PARENT_PATH)) |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 27 | else: |
| 28 | # External repository, standalone build |
| 29 | return ABS_DEVTOOLS_PATH |
| 30 | |
| 31 | |
| 32 | # This is the third_party path relative to the root of the checkout. |
| 33 | def third_party_path(): |
| 34 | return path.join(root_path(), 'third_party') |
| 35 | |
| 36 | |
| 37 | # This points to the node binary downloaded as part of the checkout. |
| 38 | def node_path(): |
| 39 | try: |
| 40 | old_sys_path = sys.path[:] |
| 41 | sys.path.append(path.join(third_party_path(), 'node')) |
| 42 | import node |
| 43 | finally: |
| 44 | sys.path = old_sys_path |
| 45 | return node.GetBinaryPath() |
| 46 | |
| 47 | |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 48 | def devtools_root_path(): |
| 49 | return path.dirname((path.dirname(path.abspath(__file__)))) |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | def node_modules_path(): |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 53 | return path.join(devtools_root_path(), 'node_modules') |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 54 | |
| 55 | |
| 56 | def eslint_path(): |
| 57 | return path.join(node_modules_path(), 'eslint', 'bin', 'eslint.js') |
| 58 | |
| 59 | |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 60 | def check_localizable_resources_path(): |
| 61 | return path.join(devtools_root_path(), 'scripts', 'check_localizable_resources.js') |
| 62 | |
| 63 | |
| 64 | def check_localized_strings_path(): |
| 65 | return path.join(devtools_root_path(), 'scripts', 'check_localizability.js') |
| 66 | |
| 67 | |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 68 | def karma_path(): |
| 69 | return path.join(node_modules_path(), 'karma', 'bin', 'karma') |
| 70 | |
| 71 | |
Tim van der Lippe | fd90361 | 2019-11-07 11:29:06 +0000 | [diff] [blame] | 72 | def rollup_path(): |
| 73 | return path.join( |
| 74 | node_modules_path(), |
| 75 | 'rollup', |
| 76 | 'dist', |
| 77 | 'bin', |
| 78 | 'rollup', |
| 79 | ) |
| 80 | |
| 81 | |
Paul Lewis | 66e1206 | 2019-12-02 12:04:54 +0000 | [diff] [blame^] | 82 | def package_lock_json_path(): |
| 83 | return path.join(devtools_root_path(), 'package-lock.json') |
| 84 | |
| 85 | |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 86 | def package_json_path(): |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 87 | return path.join(devtools_root_path(), 'package.json') |
Andrey Kosyakov | fff69a7 | 2019-11-27 01:31:57 +0000 | [diff] [blame] | 88 | |
Paul Lewis | 66e1206 | 2019-12-02 12:04:54 +0000 | [diff] [blame^] | 89 | |
Andrey Kosyakov | fff69a7 | 2019-11-27 01:31:57 +0000 | [diff] [blame] | 90 | def browser_protocol_path(): |
| 91 | return path.join(third_party_path(), 'blink', 'public', 'devtools_protocol', 'browser_protocol.pdl') |