blob: 14d721c7dbb018225cc48e9fc9e4afb2fbc9c94a [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
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.
16def 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)))
24 elif path.basename(PARENT_PATH) == 'third_party':
25 # External repository, integrated build
26 return path.dirname(PARENT_PATH)
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.
33def 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.
38def 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
48DEVTOOLS_ROOT_PATH = path.join(path.dirname(__file__), '..')
49
50
51def node_modules_path():
52 SCRIPTS_PATH = path.dirname(path.abspath(__file__))
53 ABS_DEVTOOLS_PATH = path.dirname(SCRIPTS_PATH)
54 PARENT_PATH = path.dirname(ABS_DEVTOOLS_PATH)
55 # TODO(1011259): remove Chromium repository handling
56 if path.basename(PARENT_PATH) == 'renderer':
57 # While in Chromium repo, node modules are hosted in //third_party/devtools-node-modules.
58 return path.join(root_path(), 'third_party', 'devtools-node-modules', 'third_party', 'node_modules')
59 else:
60 # In the external repo, node modules are hosted in root.
61 return path.join(root_path(), 'node_modules')
62
63
64def eslint_path():
65 return path.join(node_modules_path(), 'eslint', 'bin', 'eslint.js')
66
67
68def karma_path():
69 return path.join(node_modules_path(), 'karma', 'bin', 'karma')
70
71
72def package_json_path():
73 return path.join(DEVTOOLS_ROOT_PATH, 'package.json')