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_arch != Config.ARCH_ARM: | 25 if config.target_cpu != Config.ARCH_ARM: |
26 subdir += config.target_arch + "_" | 26 subdir += config.target_cpu + "_" |
27 elif config.target_os == Config.OS_CHROMEOS: | 27 elif config.target_os == Config.OS_CHROMEOS: |
28 subdir += "chromeos_" | 28 subdir += "chromeos_" |
29 subdir += "Debug" if config.is_debug else "Release" | 29 subdir += "Debug" if config.is_debug else "Release" |
30 if config.sanitizer == Config.SANITIZER_ASAN: | 30 if config.sanitizer == Config.SANITIZER_ASAN: |
31 subdir += "_asan" | 31 subdir += "_asan" |
32 if not(config.is_debug) and config.dcheck_always_on: | 32 if not(config.is_debug) and config.dcheck_always_on: |
33 subdir += "_dcheck" | 33 subdir += "_dcheck" |
34 return os.path.join(src_root, "out", subdir) | 34 return os.path.join(src_root, "out", subdir) |
35 | 35 |
36 | 36 |
(...skipping 28 matching lines...) Expand all Loading... |
65 elif config.target_os == Config.OS_CHROMEOS: | 65 elif config.target_os == Config.OS_CHROMEOS: |
66 gn_args["os"] = "chromeos" | 66 gn_args["os"] = "chromeos" |
67 gn_args["use_glib"] = False | 67 gn_args["use_glib"] = False |
68 gn_args["use_system_harfbuzz"] = False | 68 gn_args["use_system_harfbuzz"] = False |
69 elif config.target_os == Config.OS_LINUX: | 69 elif config.target_os == Config.OS_LINUX: |
70 gn_args["is_desktop_linux"] = False | 70 gn_args["is_desktop_linux"] = False |
71 gn_args["use_aura"] = False | 71 gn_args["use_aura"] = False |
72 gn_args["use_glib"] = False | 72 gn_args["use_glib"] = False |
73 gn_args["use_system_harfbuzz"] = False | 73 gn_args["use_system_harfbuzz"] = False |
74 | 74 |
75 gn_args["target_arch"] = config.target_arch | 75 gn_args["target_cpu"] = config.target_cpu |
76 | 76 |
77 return gn_args | 77 return gn_args |
78 | 78 |
79 | 79 |
80 def CommandLineForGNArgs(gn_args): | 80 def CommandLineForGNArgs(gn_args): |
81 """ | 81 """ |
82 Returns the list of gn arguments to use with the gn command line. | 82 Returns the list of gn arguments to use with the gn command line. |
83 """ | 83 """ |
84 def _ToCommandLine(key, value): | 84 def _ToCommandLine(key, value): |
85 if type(value) is bool: | 85 if type(value) is bool: |
(...skipping 10 matching lines...) Expand all Loading... |
96 config_args = {} | 96 config_args = {} |
97 config_args["is_debug"] = args.get("is_debug", False) | 97 config_args["is_debug"] = args.get("is_debug", False) |
98 config_args["sanitizer"] = ( | 98 config_args["sanitizer"] = ( |
99 Config.SANITIZER_ASAN if args.get("is_asan") else None) | 99 Config.SANITIZER_ASAN if args.get("is_asan") else None) |
100 config_args["is_clang"] = args.get("is_clang", False) | 100 config_args["is_clang"] = args.get("is_clang", False) |
101 config_args["use_goma"] = args.get("use_goma", False) | 101 config_args["use_goma"] = args.get("use_goma", False) |
102 if config_args["use_goma"]: | 102 if config_args["use_goma"]: |
103 config_args["goma_dir"] = args.get("goma_dir") | 103 config_args["goma_dir"] = args.get("goma_dir") |
104 config_args["use_nacl"] = args.get("mojo_use_nacl", False) | 104 config_args["use_nacl"] = args.get("mojo_use_nacl", False) |
105 config_args["target_os"] = args.get("os") | 105 config_args["target_os"] = args.get("os") |
106 config_args["target_arch"] = args.get("target_arch") | 106 config_args["target_cpu"] = args.get("target_cpu") |
107 config_args["dcheck_always_on"] = args.get("dcheck_always_on") | 107 config_args["dcheck_always_on"] = args.get("dcheck_always_on") |
108 return Config(**config_args) | 108 return Config(**config_args) |
109 | 109 |
110 | 110 |
111 def ParseGNConfig(build_dir): | 111 def ParseGNConfig(build_dir): |
112 """ | 112 """ |
113 Parse the gn config file present in |build_dir|. This function returns a | 113 Parse the gn config file present in |build_dir|. This function returns a |
114 dictionary with boolean values as boolean. | 114 dictionary with boolean values as boolean. |
115 """ | 115 """ |
116 TRANSLATIONS = { | 116 TRANSLATIONS = { |
117 "true": "True", | 117 "true": "True", |
118 "false": "False", | 118 "false": "False", |
119 } | 119 } |
120 gn_file = os.path.join(build_dir, "args.gn") | 120 gn_file = os.path.join(build_dir, "args.gn") |
121 values = {} | 121 values = {} |
122 with open(gn_file, "r") as f: | 122 with open(gn_file, "r") as f: |
123 for line in f.readlines(): | 123 for line in f.readlines(): |
124 line = re.sub("\s*#.*", "", line) | 124 line = re.sub("\s*#.*", "", line) |
125 result = re.match("^\s*(\w+)\s*=\s*(.*)\s*$", line) | 125 result = re.match("^\s*(\w+)\s*=\s*(.*)\s*$", line) |
126 if result: | 126 if result: |
127 key = result.group(1) | 127 key = result.group(1) |
128 value = result.group(2) | 128 value = result.group(2) |
129 values[key] = ast.literal_eval(TRANSLATIONS.get(value, value)) | 129 values[key] = ast.literal_eval(TRANSLATIONS.get(value, value)) |
130 return values | 130 return values |
OLD | NEW |