Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Side by Side Diff: mojo/tools/mopy/gn.py

Issue 878933003: Move the apptest runner and parts of mopy to the public SDK. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/tools/mopy/file_hash.py ('k') | mojo/tools/mopy/gn_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2015 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 """
6 GN-related configuration functions, e.g., to produce a Config object from a GN
7 args.gn file).
8 """
9
10
11 import ast
12 import os.path
13 import re
14
15 from .config import Config
16
17
18 def BuildDirectoryForConfig(config, src_root):
19 """
20 Returns the build directory for the given configuration.
21 """
22 subdir = ""
23 if config.target_os == Config.OS_ANDROID:
24 subdir += "android_"
25 elif config.target_os == Config.OS_CHROMEOS:
26 subdir += "chromeos_"
27 subdir += "Debug" if config.is_debug else "Release"
28 if config.sanitizer == Config.SANITIZER_ASAN:
29 subdir += "_asan"
30 return os.path.join(src_root, "out", subdir)
31
32
33 def GNArgsForConfig(config):
34 """
35 Return the arguments for gn for the given configuration. This function returns
36 a dictionary with boolean values as boolean.
37 """
38 gn_args = {}
39
40 gn_args["is_debug"] = bool(config.is_debug)
41 gn_args["is_asan"] = config.sanitizer == Config.SANITIZER_ASAN
42
43 if config.is_clang is not None:
44 gn_args["is_clang"] = bool(config.is_clang)
45 else:
46 gn_args["is_clang"] = config.target_os not in (Config.OS_ANDROID,
47 Config.OS_WINDOWS)
48
49 if config.values.get("use_goma"):
50 gn_args["use_goma"] = True
51 gn_args["goma_dir"] = config.values["goma_dir"]
52 else:
53 gn_args["use_goma"] = False
54
55 gn_args["mojo_use_nacl"] = config.values.get("use_nacl", False)
56
57 if config.target_os == Config.OS_ANDROID:
58 gn_args["os"] = "android"
59 elif config.target_os == Config.OS_CHROMEOS:
60 gn_args["os"] = "chromeos"
61 gn_args["use_glib"] = False
62 gn_args["use_system_harfbuzz"] = False
63 elif config.target_os == Config.OS_LINUX:
64 gn_args["is_desktop_linux"] = False
65 gn_args["use_aura"] = False
66 gn_args["use_glib"] = False
67 gn_args["use_system_harfbuzz"] = False
68
69 gn_args["cpu_arch"] = config.target_arch
70
71 return gn_args
72
73
74 def CommandLineForGNArgs(gn_args):
75 """
76 Returns the list of gn arguments to use with the gn command line.
77 """
78 def _ToCommandLine(key, value):
79 if type(value) is bool:
80 return "%s=%s" % (key, "true" if value else "false")
81 return "%s=\"%s\"" % (key, value)
82 return [_ToCommandLine(x, y) for x, y in gn_args.iteritems()]
83
84
85 def ConfigForGNArgs(args):
86 """
87 Return the Config object for the given gn arguments. This function takes a
88 dictionary with boolean values as boolean.
89 """
90 config_args = {}
91 config_args["is_debug"] = args.get("is_debug", False)
92 config_args["sanitizer"] = (
93 Config.SANITIZER_ASAN if args.get("is_asan") else None)
94 config_args["is_clang"] = args.get("is_clang", False)
95 config_args["use_goma"] = args.get("use_goma", False)
96 if config_args["use_goma"]:
97 config_args["goma_dir"] = args.get("goma_dir")
98 config_args["use_nacl"] = args.get("mojo_use_nacl", False)
99 config_args["target_os"] = args.get("os")
100 config_args["target_arch"] = args.get("cpu_arch")
101 return Config(**config_args)
102
103
104 def ParseGNConfig(build_dir):
105 """
106 Parse the gn config file present in |build_dir|. This function returns a
107 dictionary with boolean values as boolean.
108 """
109 TRANSLATIONS = {
110 "true": "True",
111 "false": "False",
112 }
113 gn_file = os.path.join(build_dir, "args.gn")
114 values = {}
115 with open(gn_file, "r") as f:
116 for line in f.readlines():
117 line = re.sub("\s*#.*", "", line)
118 result = re.match("^\s*(\w+)\s*=\s*(.*)\s*$", line)
119 if result:
120 key = result.group(1)
121 value = result.group(2)
122 values[key] = ast.literal_eval(TRANSLATIONS.get(value, value))
123 return values
OLDNEW
« no previous file with comments | « mojo/tools/mopy/file_hash.py ('k') | mojo/tools/mopy/gn_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698