blob: bfa7d17354f2f9d8cf0944f978bc2efa3c6bb25d [file] [log] [blame]
Yang Guod8176982019-10-04 20:30:35 +00001# 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"""
5Helper to find the path to the correct third_party directory
6"""
7
8from os import path
9import sys
Paul Lewis449ac182019-12-03 10:28:11 +000010import platform
Yang Guod8176982019-10-04 20:30:35 +000011
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.
17def 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)))
Alex Rudenko413451a2021-07-22 15:36:37 +000025 elif path.basename(PARENT_PATH) == 'devtools-frontend' or path.basename(
26 PARENT_PATH) == 'devtools-frontend-internal':
Yang Guod8176982019-10-04 20:30:35 +000027 # External repository, integrated build
Yang Guo4fd355c2019-09-19 10:59:03 +020028 return path.dirname(path.dirname(PARENT_PATH))
Yang Guod8176982019-10-04 20:30:35 +000029 else:
30 # External repository, standalone build
31 return ABS_DEVTOOLS_PATH
32
33
34# This is the third_party path relative to the root of the checkout.
35def third_party_path():
36 return path.join(root_path(), 'third_party')
37
38
39# This points to the node binary downloaded as part of the checkout.
40def node_path():
41 try:
42 old_sys_path = sys.path[:]
43 sys.path.append(path.join(third_party_path(), 'node'))
44 import node
45 finally:
46 sys.path = old_sys_path
47 return node.GetBinaryPath()
48
49
Yang Guo75beda92019-10-28 08:29:25 +010050def devtools_root_path():
51 return path.dirname((path.dirname(path.abspath(__file__))))
Yang Guod8176982019-10-04 20:30:35 +000052
53
54def node_modules_path():
Yang Guo75beda92019-10-28 08:29:25 +010055 return path.join(devtools_root_path(), 'node_modules')
Yang Guod8176982019-10-04 20:30:35 +000056
57
58def eslint_path():
59 return path.join(node_modules_path(), 'eslint', 'bin', 'eslint.js')
60
61
Tim van der Lippe869374b2020-04-20 11:12:31 +010062def mocha_path():
63 return path.join(node_modules_path(), 'mocha', 'bin', 'mocha')
64
65
Yang Guod8176982019-10-04 20:30:35 +000066def karma_path():
67 return path.join(node_modules_path(), 'karma', 'bin', 'karma')
68
69
Paul Lewisb8b38012020-01-22 17:18:47 +000070def typescript_compiler_path():
71 return path.join(node_modules_path(), 'typescript', 'bin', 'tsc')
72
73
Paul Lewis449ac182019-12-03 10:28:11 +000074def hosted_mode_script_path():
75 return path.join(devtools_root_path(), 'scripts', 'hosted_mode', 'server.js')
76
77
Takuto Ikuta95a359d2022-01-24 10:38:29 +090078def esbuild_path():
79 return path.join(devtools_root_path(), 'third_party', 'esbuild', 'esbuild')
80
81
Paul Lewis449ac182019-12-03 10:28:11 +000082def downloaded_chrome_binary_path():
83 return path.abspath(path.join(
84 *{
85 'Linux': (devtools_root_path(), 'third_party', 'chrome', 'chrome-linux', 'chrome'),
86 'Darwin': (devtools_root_path(), 'third_party', 'chrome', 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium'),
87 'Windows': (devtools_root_path(), 'third_party', 'chrome', 'chrome-win', 'chrome.exe'),
88 }[platform.system()]))
89
90
Paul Lewise184c4c2019-12-02 12:30:15 +000091def license_checker_path():
92 return path.join(node_modules_path(), 'license-checker', 'bin', 'license-checker')
93
94
Tim van der Lippefd903612019-11-07 11:29:06 +000095def rollup_path():
96 return path.join(
97 node_modules_path(),
98 'rollup',
99 'dist',
100 'bin',
101 'rollup',
102 )
103
104
Paul Lewis66e12062019-12-02 12:04:54 +0000105def package_lock_json_path():
106 return path.join(devtools_root_path(), 'package-lock.json')
107
108
Yang Guod8176982019-10-04 20:30:35 +0000109def package_json_path():
Yang Guo75beda92019-10-28 08:29:25 +0100110 return path.join(devtools_root_path(), 'package.json')
Andrey Kosyakovfff69a72019-11-27 01:31:57 +0000111
Paul Lewis66e12062019-12-02 12:04:54 +0000112
Andrey Kosyakovfff69a72019-11-27 01:31:57 +0000113def browser_protocol_path():
114 return path.join(third_party_path(), 'blink', 'public', 'devtools_protocol', 'browser_protocol.pdl')