OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import os | 5 import os |
6 | 6 |
7 from .config import Config | 7 from .config import Config |
8 from .gn import BuildDirectoryForConfig | 8 |
9 | 9 |
10 class Paths(object): | 10 class Paths(object): |
11 """Provides commonly used paths""" | 11 """Provides commonly used paths""" |
12 | 12 |
13 def __init__(self, config=None, build_dir=None): | 13 def __init__(self, config): |
14 """Specify either a config or a build_dir to generate paths to binary | 14 """Generate paths to binary artifacts from a Config object.""" |
15 artifacts.""" | |
16 self.src_root = os.path.abspath(os.path.join(__file__, | 15 self.src_root = os.path.abspath(os.path.join(__file__, |
17 os.pardir, os.pardir, os.pardir, os.pardir)) | 16 os.pardir, os.pardir, os.pardir, os.pardir)) |
18 self.mojo_dir = os.path.join(self.src_root, "mojo") | 17 self.mojo_dir = os.path.join(self.src_root, "mojo") |
19 self.adb_path = os.path.join(self.src_root, 'third_party', 'android_tools', | 18 self.adb_path = os.path.join(self.src_root, 'third_party', 'android_tools', |
20 'sdk', 'platform-tools', 'adb') | 19 'sdk', 'platform-tools', 'adb') |
21 | 20 |
22 if config: | 21 self.build_dir = config.build_dir |
23 self.build_dir = BuildDirectoryForConfig(config, self.src_root) | 22 if self.build_dir is None: |
24 elif build_dir is not None: | 23 subdir = "" |
25 self.build_dir = os.path.abspath(build_dir) | 24 if config.target_os == Config.OS_ANDROID: |
26 else: | 25 subdir += "android_" |
27 self.build_dir = None | 26 if config.target_cpu != Config.ARCH_ARM: |
| 27 subdir += config.target_cpu + "_" |
| 28 elif config.target_os == Config.OS_CHROMEOS: |
| 29 subdir += "chromeos_" |
| 30 subdir += "Debug" if config.is_debug else "Release" |
| 31 if config.is_asan: |
| 32 subdir += "_asan" |
| 33 if not(config.is_debug) and config.dcheck_always_on: |
| 34 subdir += "_dcheck" |
| 35 self.build_dir = os.path.join(self.src_root, "out", subdir) |
28 | 36 |
29 if self.build_dir is not None: | 37 self.mojo_runner = os.path.join(self.build_dir, "mojo_runner") |
30 self.mojo_shell_path = os.path.join(self.build_dir, "mojo_runner") | 38 if config.target_os == Config.OS_WINDOWS: |
31 # TODO(vtl): Use the host OS here, since |config| may not be available. | 39 self.mojo_runner += ".exe" |
32 # In any case, if the target is Windows, but the host isn't, using | 40 if config.target_os == Config.OS_ANDROID: |
33 # |os.path| isn't correct.... | 41 self.mojo_runner = os.path.join(self.build_dir, "apks", config.apk_name) |
34 if Config.GetHostOS() == Config.OS_WINDOWS: | |
35 self.mojo_shell_path += ".exe" | |
36 if config and config.target_os == Config.OS_ANDROID: | |
37 self.target_mojo_shell_path = os.path.join(self.build_dir, | |
38 "apks", | |
39 config.apk_name) | |
40 else: | |
41 self.target_mojo_shell_path = self.mojo_shell_path | |
42 else: | |
43 self.mojo_shell_path = None | |
44 self.target_mojo_shell_path = None | |
45 | 42 |
46 def RelPath(self, path): | 43 def RelPath(self, path): |
47 """Returns the given path, relative to the current directory.""" | 44 """Returns the given path, relative to the current directory.""" |
48 return os.path.relpath(path) | 45 return os.path.relpath(path) |
49 | 46 |
50 def SrcRelPath(self, path): | 47 def SrcRelPath(self, path): |
51 """Returns the given path, relative to self.src_root.""" | 48 """Returns the given path, relative to self.src_root.""" |
52 return os.path.relpath(path, self.src_root) | 49 return os.path.relpath(path, self.src_root) |
53 | |
54 def FileFromUrl(self, url): | |
55 """Given an app URL (<scheme>:<appname>), return 'build_dir/appname.mojo'. | |
56 If self.build_dir is None, just return appname.mojo | |
57 """ | |
58 (_, name) = url.split(':') | |
59 if self.build_dir: | |
60 return os.path.join(self.build_dir, name + '.mojo') | |
61 return name + '.mojo' | |
62 | |
63 @staticmethod | |
64 def IsValidAppUrl(url): | |
65 """Returns False if url is malformed, True otherwise.""" | |
66 try: | |
67 return len(url.split(':')) == 2 | |
68 except ValueError: | |
69 return False | |
OLD | NEW |