OLD | NEW |
---|---|
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 """ | 5 """ |
6 GN-related configuration functions, e.g., to produce a Config object from a GN | 6 GN-related configuration functions, e.g., to produce a Config object from a GN |
7 args.gn file). | 7 args.gn file). |
8 """ | 8 """ |
9 | 9 |
10 | 10 |
11 import ast | 11 import ast |
12 import os.path | 12 import os.path |
13 import re | 13 import re |
14 | 14 |
15 from .config import Config | 15 from .config import Config |
16 | 16 |
17 | 17 |
18 def BuildDirectoryForConfig(config, src_root): | 18 def BuildDirectoryForConfig(config, src_root): |
19 """ | 19 """ |
20 Returns the build directory for the given configuration. | 20 Returns the build directory for the given configuration. |
21 """ | 21 """ |
22 subdir = "" | 22 subdir = "" |
23 if config.target_os == Config.OS_ANDROID: | 23 if config.target_os == Config.OS_ANDROID: |
24 subdir += "android_" | 24 subdir += "android_" |
25 if config.target_cpu != Config.ARCH_ARM: | 25 if config.target_cpu != Config.ARCH_ARM: |
26 subdir += config.target_cpu + "_" | 26 subdir += config.target_cpu + "_" |
27 elif config.target_os == Config.OS_FNL: | |
28 subdir += "fnl_" | |
27 elif config.target_os == Config.OS_IOS: | 29 elif config.target_os == Config.OS_IOS: |
28 subdir += "ios_" | 30 subdir += "ios_" |
29 if config.is_simulator: | 31 if config.is_simulator: |
30 subdir += "sim_" | 32 subdir += "sim_" |
31 if config.is_official_build: | 33 if config.is_official_build: |
32 subdir += "Official" | 34 subdir += "Official" |
33 elif config.is_debug: | 35 elif config.is_debug: |
34 subdir += "Debug" | 36 subdir += "Debug" |
35 else: | 37 else: |
36 subdir += "Release" | 38 subdir += "Release" |
37 if config.sanitizer == Config.SANITIZER_ASAN: | 39 if config.sanitizer == Config.SANITIZER_ASAN: |
38 subdir += "_asan" | 40 subdir += "_asan" |
39 if not(config.is_debug) and config.dcheck_always_on: | 41 if not(config.is_debug) and config.dcheck_always_on: |
40 subdir += "_dcheck" | 42 subdir += "_dcheck" |
41 return os.path.join(src_root, "out", subdir) | 43 return os.path.join(src_root, "out", subdir) |
42 | 44 |
43 | |
viettrungluu
2015/09/16 22:19:46
nit: Please undelete this line.
cdotstout
2015/09/16 22:27:09
Done.
| |
44 def GNArgsForConfig(config): | 45 def GNArgsForConfig(config): |
45 """ | 46 """ |
46 Return the arguments for gn for the given configuration. This function returns | 47 Return the arguments for gn for the given configuration. This function returns |
47 a dictionary with boolean values as boolean. | 48 a dictionary with boolean values as boolean. |
48 """ | 49 """ |
49 gn_args = {} | 50 gn_args = {} |
50 | 51 |
51 gn_args["is_debug"] = bool(config.is_debug) | 52 gn_args["is_debug"] = bool(config.is_debug) |
52 gn_args["is_official_build"] = bool(config.is_official_build) | 53 gn_args["is_official_build"] = bool(config.is_official_build) |
53 gn_args["is_asan"] = config.sanitizer == Config.SANITIZER_ASAN | 54 gn_args["is_asan"] = config.sanitizer == Config.SANITIZER_ASAN |
54 | 55 |
55 if config.is_clang is not None: | 56 if config.is_clang is not None: |
56 gn_args["is_clang"] = bool(config.is_clang) | 57 gn_args["is_clang"] = bool(config.is_clang) |
57 else: | 58 else: |
58 gn_args["is_clang"] = config.target_os not in (Config.OS_ANDROID, | 59 gn_args["is_clang"] = config.target_os not in (Config.OS_ANDROID, |
60 Config.OS_FNL, | |
59 Config.OS_WINDOWS) | 61 Config.OS_WINDOWS) |
60 | 62 |
61 if config.values.get("use_goma"): | 63 if config.values.get("use_goma"): |
62 gn_args["use_goma"] = True | 64 gn_args["use_goma"] = True |
63 gn_args["goma_dir"] = config.values["goma_dir"] | 65 gn_args["goma_dir"] = config.values["goma_dir"] |
64 else: | 66 else: |
65 gn_args["use_goma"] = False | 67 gn_args["use_goma"] = False |
66 | 68 |
67 gn_args["dcheck_always_on"] = config.dcheck_always_on | 69 gn_args["dcheck_always_on"] = config.dcheck_always_on |
68 | 70 |
69 if config.target_os == Config.OS_ANDROID: | 71 if config.target_os == Config.OS_ANDROID: |
70 gn_args["target_os"] = "android" | 72 gn_args["target_os"] = "android" |
73 elif config.target_os == Config.OS_FNL: | |
74 gn_args["target_os"] = "fnl" | |
75 gn_args["use_aura"] = False | |
76 gn_args["use_glib"] = False | |
77 gn_args["use_ozone"] = True | |
78 gn_args["use_system_harfbuzz"] = False | |
79 gn_args["target_sysroot"] = config.values.get("target_sysroot", "") | |
80 gn_args["toolchain_prefix"] = config.values.get("toolchain_prefix", "") | |
71 elif config.target_os == Config.OS_IOS: | 81 elif config.target_os == Config.OS_IOS: |
72 gn_args["target_os"] = "ios" | 82 gn_args["target_os"] = "ios" |
73 gn_args["ios_deployment_target"] = "7.0" | 83 gn_args["ios_deployment_target"] = "7.0" |
74 gn_args["clang_use_chrome_plugins"] = False | 84 gn_args["clang_use_chrome_plugins"] = False |
75 if config.is_simulator: | 85 if config.is_simulator: |
76 gn_args["use_libjpeg_turbo"] = False | 86 gn_args["use_libjpeg_turbo"] = False |
77 gn_args["use_ios_simulator"] = config.is_simulator | 87 gn_args["use_ios_simulator"] = config.is_simulator |
78 elif config.target_os == Config.OS_LINUX: | 88 elif config.target_os == Config.OS_LINUX: |
79 gn_args["use_aura"] = False | 89 gn_args["use_aura"] = False |
80 gn_args["use_glib"] = False | 90 gn_args["use_glib"] = False |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 if config_args["use_goma"]: | 135 if config_args["use_goma"]: |
126 config_args["goma_dir"] = args.get("goma_dir") | 136 config_args["goma_dir"] = args.get("goma_dir") |
127 config_args["use_nacl"] = args.get("mojo_use_nacl", False) | 137 config_args["use_nacl"] = args.get("mojo_use_nacl", False) |
128 config_args["mojo_use_go"] = args.get("mojo_use_go", False) | 138 config_args["mojo_use_go"] = args.get("mojo_use_go", False) |
129 if config_args["mojo_use_go"]: | 139 if config_args["mojo_use_go"]: |
130 config_args["go_build_tool"] = args.get("go_build_tool") | 140 config_args["go_build_tool"] = args.get("go_build_tool") |
131 config_args["target_os"] = args.get("target_os") | 141 config_args["target_os"] = args.get("target_os") |
132 config_args["target_cpu"] = args.get("target_cpu") | 142 config_args["target_cpu"] = args.get("target_cpu") |
133 config_args["dcheck_always_on"] = args.get("dcheck_always_on") | 143 config_args["dcheck_always_on"] = args.get("dcheck_always_on") |
134 config_args["is_simulator"] = args.get("use_ios_simulator", False) | 144 config_args["is_simulator"] = args.get("use_ios_simulator", False) |
145 if "target_sysroot" in args: | |
146 config_args["target_sysroot"] = args.get("target_sysroot") | |
147 if "toolchain_prefix" in args: | |
148 config_args["toolchain_prefix"] = args.get("toolchain_prefix") | |
135 return Config(**config_args) | 149 return Config(**config_args) |
136 | 150 |
137 | 151 |
138 def ParseGNConfig(build_dir): | 152 def ParseGNConfig(build_dir): |
139 """ | 153 """ |
140 Parse the gn config file present in |build_dir|. This function returns a | 154 Parse the gn config file present in |build_dir|. This function returns a |
141 dictionary with boolean values as boolean. | 155 dictionary with boolean values as boolean. |
142 """ | 156 """ |
143 TRANSLATIONS = { | 157 TRANSLATIONS = { |
144 "true": "True", | 158 "true": "True", |
145 "false": "False", | 159 "false": "False", |
146 } | 160 } |
147 gn_file = os.path.join(build_dir, "args.gn") | 161 gn_file = os.path.join(build_dir, "args.gn") |
148 values = {} | 162 values = {} |
149 with open(gn_file, "r") as f: | 163 with open(gn_file, "r") as f: |
150 for line in f.readlines(): | 164 for line in f.readlines(): |
151 line = re.sub("\s*#.*", "", line) | 165 line = re.sub("\s*#.*", "", line) |
152 result = re.match("^\s*(\w+)\s*=\s*(.*)\s*$", line) | 166 result = re.match("^\s*(\w+)\s*=\s*(.*)\s*$", line) |
153 if result: | 167 if result: |
154 key = result.group(1) | 168 key = result.group(1) |
155 value = result.group(2) | 169 value = result.group(2) |
156 values[key] = ast.literal_eval(TRANSLATIONS.get(value, value)) | 170 values[key] = ast.literal_eval(TRANSLATIONS.get(value, value)) |
157 return values | 171 return values |
OLD | NEW |