| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 49 gn_args = {} | 51 gn_args = {} |
| 50 | 52 |
| 51 gn_args["is_debug"] = bool(config.is_debug) | 53 gn_args["is_debug"] = bool(config.is_debug) |
| 52 gn_args["is_official_build"] = bool(config.is_official_build) | 54 gn_args["is_official_build"] = bool(config.is_official_build) |
| 53 gn_args["is_asan"] = config.sanitizer == Config.SANITIZER_ASAN | 55 gn_args["is_asan"] = config.sanitizer == Config.SANITIZER_ASAN |
| 54 | 56 |
| 55 if config.is_clang is not None: | 57 if config.is_clang is not None: |
| 56 gn_args["is_clang"] = bool(config.is_clang) | 58 gn_args["is_clang"] = bool(config.is_clang) |
| 57 else: | 59 else: |
| 58 gn_args["is_clang"] = config.target_os not in (Config.OS_ANDROID, | 60 gn_args["is_clang"] = config.target_os not in (Config.OS_ANDROID, |
| 61 Config.OS_FNL, |
| 59 Config.OS_WINDOWS) | 62 Config.OS_WINDOWS) |
| 60 | 63 |
| 61 if config.values.get("use_goma"): | 64 if config.values.get("use_goma"): |
| 62 gn_args["use_goma"] = True | 65 gn_args["use_goma"] = True |
| 63 gn_args["goma_dir"] = config.values["goma_dir"] | 66 gn_args["goma_dir"] = config.values["goma_dir"] |
| 64 else: | 67 else: |
| 65 gn_args["use_goma"] = False | 68 gn_args["use_goma"] = False |
| 66 | 69 |
| 67 gn_args["dcheck_always_on"] = config.dcheck_always_on | 70 gn_args["dcheck_always_on"] = config.dcheck_always_on |
| 68 | 71 |
| 69 if config.target_os == Config.OS_ANDROID: | 72 if config.target_os == Config.OS_ANDROID: |
| 70 gn_args["target_os"] = "android" | 73 gn_args["target_os"] = "android" |
| 74 elif config.target_os == Config.OS_FNL: |
| 75 gn_args["target_os"] = "fnl" |
| 76 gn_args["use_aura"] = False |
| 77 gn_args["use_glib"] = False |
| 78 gn_args["use_ozone"] = True |
| 79 gn_args["use_system_harfbuzz"] = False |
| 80 gn_args["target_sysroot"] = config.values.get("target_sysroot", "") |
| 81 gn_args["toolchain_prefix"] = config.values.get("toolchain_prefix", "") |
| 71 elif config.target_os == Config.OS_IOS: | 82 elif config.target_os == Config.OS_IOS: |
| 72 gn_args["target_os"] = "ios" | 83 gn_args["target_os"] = "ios" |
| 73 gn_args["ios_deployment_target"] = "7.0" | 84 gn_args["ios_deployment_target"] = "7.0" |
| 74 gn_args["clang_use_chrome_plugins"] = False | 85 gn_args["clang_use_chrome_plugins"] = False |
| 75 if config.is_simulator: | 86 if config.is_simulator: |
| 76 gn_args["use_libjpeg_turbo"] = False | 87 gn_args["use_libjpeg_turbo"] = False |
| 77 gn_args["use_ios_simulator"] = config.is_simulator | 88 gn_args["use_ios_simulator"] = config.is_simulator |
| 78 elif config.target_os == Config.OS_LINUX: | 89 elif config.target_os == Config.OS_LINUX: |
| 79 gn_args["use_aura"] = False | 90 gn_args["use_aura"] = False |
| 80 gn_args["use_glib"] = False | 91 gn_args["use_glib"] = False |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 if config_args["use_goma"]: | 136 if config_args["use_goma"]: |
| 126 config_args["goma_dir"] = args.get("goma_dir") | 137 config_args["goma_dir"] = args.get("goma_dir") |
| 127 config_args["use_nacl"] = args.get("mojo_use_nacl", False) | 138 config_args["use_nacl"] = args.get("mojo_use_nacl", False) |
| 128 config_args["mojo_use_go"] = args.get("mojo_use_go", False) | 139 config_args["mojo_use_go"] = args.get("mojo_use_go", False) |
| 129 if config_args["mojo_use_go"]: | 140 if config_args["mojo_use_go"]: |
| 130 config_args["go_build_tool"] = args.get("go_build_tool") | 141 config_args["go_build_tool"] = args.get("go_build_tool") |
| 131 config_args["target_os"] = args.get("target_os") | 142 config_args["target_os"] = args.get("target_os") |
| 132 config_args["target_cpu"] = args.get("target_cpu") | 143 config_args["target_cpu"] = args.get("target_cpu") |
| 133 config_args["dcheck_always_on"] = args.get("dcheck_always_on") | 144 config_args["dcheck_always_on"] = args.get("dcheck_always_on") |
| 134 config_args["is_simulator"] = args.get("use_ios_simulator", False) | 145 config_args["is_simulator"] = args.get("use_ios_simulator", False) |
| 146 if "target_sysroot" in args: |
| 147 config_args["target_sysroot"] = args.get("target_sysroot") |
| 148 if "toolchain_prefix" in args: |
| 149 config_args["toolchain_prefix"] = args.get("toolchain_prefix") |
| 135 return Config(**config_args) | 150 return Config(**config_args) |
| 136 | 151 |
| 137 | 152 |
| 138 def ParseGNConfig(build_dir): | 153 def ParseGNConfig(build_dir): |
| 139 """ | 154 """ |
| 140 Parse the gn config file present in |build_dir|. This function returns a | 155 Parse the gn config file present in |build_dir|. This function returns a |
| 141 dictionary with boolean values as boolean. | 156 dictionary with boolean values as boolean. |
| 142 """ | 157 """ |
| 143 TRANSLATIONS = { | 158 TRANSLATIONS = { |
| 144 "true": "True", | 159 "true": "True", |
| 145 "false": "False", | 160 "false": "False", |
| 146 } | 161 } |
| 147 gn_file = os.path.join(build_dir, "args.gn") | 162 gn_file = os.path.join(build_dir, "args.gn") |
| 148 values = {} | 163 values = {} |
| 149 with open(gn_file, "r") as f: | 164 with open(gn_file, "r") as f: |
| 150 for line in f.readlines(): | 165 for line in f.readlines(): |
| 151 line = re.sub("\s*#.*", "", line) | 166 line = re.sub("\s*#.*", "", line) |
| 152 result = re.match("^\s*(\w+)\s*=\s*(.*)\s*$", line) | 167 result = re.match("^\s*(\w+)\s*=\s*(.*)\s*$", line) |
| 153 if result: | 168 if result: |
| 154 key = result.group(1) | 169 key = result.group(1) |
| 155 value = result.group(2) | 170 value = result.group(2) |
| 156 values[key] = ast.literal_eval(TRANSLATIONS.get(value, value)) | 171 values[key] = ast.literal_eval(TRANSLATIONS.get(value, value)) |
| 157 return values | 172 return values |
| OLD | NEW |