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 |
Paul Lewis | 449ac18 | 2019-12-03 10:28:11 +0000 | [diff] [blame] | 10 | import platform |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 11 | |
| 12 | |
| 13 | # Find the root path of the checkout. |
| 14 | # In the Chromium repository, this is the src/chromium directory. |
| 15 | # In the external repository, standalone build, this is the devtools-frontend directory. |
| 16 | # In the external repository, integrated build, this is the src/chromium directory. |
| 17 | def root_path(): |
| 18 | SCRIPTS_PATH = path.dirname(path.abspath(__file__)) |
| 19 | ABS_DEVTOOLS_PATH = path.dirname(SCRIPTS_PATH) |
| 20 | PARENT_PATH = path.dirname(ABS_DEVTOOLS_PATH) |
| 21 | # TODO(1011259): remove Chromium repository handling |
| 22 | if path.basename(PARENT_PATH) == 'renderer': |
| 23 | # Chromium repository |
| 24 | return path.dirname(path.dirname(path.dirname(PARENT_PATH))) |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 25 | elif path.basename(PARENT_PATH) == 'devtools-frontend': |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 26 | # External repository, integrated build |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 27 | return path.dirname(path.dirname(PARENT_PATH)) |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 28 | else: |
| 29 | # External repository, standalone build |
| 30 | return ABS_DEVTOOLS_PATH |
| 31 | |
| 32 | |
| 33 | # This is the third_party path relative to the root of the checkout. |
| 34 | def third_party_path(): |
| 35 | return path.join(root_path(), 'third_party') |
| 36 | |
| 37 | |
| 38 | # This points to the node binary downloaded as part of the checkout. |
| 39 | def node_path(): |
| 40 | try: |
| 41 | old_sys_path = sys.path[:] |
| 42 | sys.path.append(path.join(third_party_path(), 'node')) |
| 43 | import node |
| 44 | finally: |
| 45 | sys.path = old_sys_path |
| 46 | return node.GetBinaryPath() |
| 47 | |
| 48 | |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 49 | def devtools_root_path(): |
| 50 | return path.dirname((path.dirname(path.abspath(__file__)))) |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 51 | |
| 52 | |
| 53 | def node_modules_path(): |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 54 | return path.join(devtools_root_path(), 'node_modules') |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 55 | |
| 56 | |
| 57 | def eslint_path(): |
| 58 | return path.join(node_modules_path(), 'eslint', 'bin', 'eslint.js') |
| 59 | |
| 60 | |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 61 | def check_localizable_resources_path(): |
Yang Guo | 6e99c7c | 2019-12-03 10:41:40 +0100 | [diff] [blame] | 62 | return path.join(devtools_root_path(), 'scripts', 'localization', 'check_localizable_resources.js') |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 63 | |
| 64 | |
| 65 | def check_localized_strings_path(): |
Yang Guo | 6e99c7c | 2019-12-03 10:41:40 +0100 | [diff] [blame] | 66 | return path.join(devtools_root_path(), 'scripts', 'localization', 'check_localizability.js') |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 67 | |
| 68 | |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 69 | def karma_path(): |
| 70 | return path.join(node_modules_path(), 'karma', 'bin', 'karma') |
| 71 | |
| 72 | |
Paul Lewis | 449ac18 | 2019-12-03 10:28:11 +0000 | [diff] [blame] | 73 | def boot_perf_test_path(): |
| 74 | return path.join(devtools_root_path(), 'test', 'perf', 'bootperf.js') |
| 75 | |
| 76 | |
| 77 | def hosted_mode_script_path(): |
| 78 | return path.join(devtools_root_path(), 'scripts', 'hosted_mode', 'server.js') |
| 79 | |
| 80 | |
| 81 | def downloaded_chrome_binary_path(): |
| 82 | return path.abspath(path.join( |
| 83 | *{ |
| 84 | 'Linux': (devtools_root_path(), 'third_party', 'chrome', 'chrome-linux', 'chrome'), |
| 85 | 'Darwin': (devtools_root_path(), 'third_party', 'chrome', 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium'), |
| 86 | 'Windows': (devtools_root_path(), 'third_party', 'chrome', 'chrome-win', 'chrome.exe'), |
| 87 | }[platform.system()])) |
| 88 | |
| 89 | |
Paul Lewis | e184c4c | 2019-12-02 12:30:15 +0000 | [diff] [blame] | 90 | def license_checker_path(): |
| 91 | return path.join(node_modules_path(), 'license-checker', 'bin', 'license-checker') |
| 92 | |
| 93 | |
Tim van der Lippe | fd90361 | 2019-11-07 11:29:06 +0000 | [diff] [blame] | 94 | def rollup_path(): |
| 95 | return path.join( |
| 96 | node_modules_path(), |
| 97 | 'rollup', |
| 98 | 'dist', |
| 99 | 'bin', |
| 100 | 'rollup', |
| 101 | ) |
| 102 | |
| 103 | |
Paul Lewis | 66e1206 | 2019-12-02 12:04:54 +0000 | [diff] [blame] | 104 | def package_lock_json_path(): |
| 105 | return path.join(devtools_root_path(), 'package-lock.json') |
| 106 | |
| 107 | |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 108 | def package_json_path(): |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 109 | return path.join(devtools_root_path(), 'package.json') |
Andrey Kosyakov | fff69a7 | 2019-11-27 01:31:57 +0000 | [diff] [blame] | 110 | |
Paul Lewis | 66e1206 | 2019-12-02 12:04:54 +0000 | [diff] [blame] | 111 | |
Andrey Kosyakov | fff69a7 | 2019-11-27 01:31:57 +0000 | [diff] [blame] | 112 | def browser_protocol_path(): |
| 113 | return path.join(third_party_path(), 'blink', 'public', 'devtools_protocol', 'browser_protocol.pdl') |