OLD | NEW |
| (Empty) |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 import os | |
6 | |
7 from .config import Config | |
8 from .gn import BuildDirectoryForConfig | |
9 | |
10 class Paths(object): | |
11 """Provides commonly used paths""" | |
12 | |
13 def __init__(self, config=None, build_dir=None): | |
14 """Specify either a config or a build_dir to generate paths to binary | |
15 artifacts.""" | |
16 self.src_root = os.path.abspath(os.path.join(__file__, | |
17 os.pardir, os.pardir, os.pardir, os.pardir)) | |
18 self.mojo_dir = os.path.join(self.src_root, "mojo") | |
19 | |
20 if config: | |
21 self.build_dir = BuildDirectoryForConfig(config, self.src_root) | |
22 elif build_dir is not None: | |
23 self.build_dir = os.path.abspath(build_dir) | |
24 else: | |
25 self.build_dir = None | |
26 | |
27 if self.build_dir is not None: | |
28 self.mojo_launcher_path = os.path.join(self.build_dir, "mojo_launcher") | |
29 self.mojo_shell_path = os.path.join(self.build_dir, "mojo_shell") | |
30 # TODO(vtl): Use the host OS here, since |config| may not be available. | |
31 # In any case, if the target is Windows, but the host isn't, using | |
32 # |os.path| isn't correct.... | |
33 if Config.GetHostOS() == Config.OS_WINDOWS: | |
34 self.mojo_launcher_path += ".exe" | |
35 self.mojo_shell_path += ".exe" | |
36 else: | |
37 self.mojo_launcher_path = None | |
38 self.mojo_shell_path = None | |
39 | |
40 def RelPath(self, path): | |
41 """Returns the given path, relative to the current directory.""" | |
42 return os.path.relpath(path) | |
43 | |
44 def SrcRelPath(self, path): | |
45 """Returns the given path, relative to self.src_root.""" | |
46 return os.path.relpath(path, self.src_root) | |
47 | |
48 def FileFromUrl(self, url): | |
49 """Given an app URL (<scheme>:<appname>), return 'build_dir/appname.mojo'. | |
50 If self.build_dir is None, just return appname.mojo | |
51 """ | |
52 (_, name) = url.split(':') | |
53 if self.build_dir: | |
54 return os.path.join(self.build_dir, name + '.mojo') | |
55 return name + '.mojo' | |
56 | |
57 @staticmethod | |
58 def IsValidAppUrl(url): | |
59 """Returns False if url is malformed, True otherwise.""" | |
60 try: | |
61 return len(url.split(':')) == 2 | |
62 except ValueError: | |
63 return False | |
OLD | NEW |