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.
14 """A Config contains a dictionary that species a build configuration."""
16 # Valid values for target_os:
17 OS_ANDROID
= "android"
18 OS_CHROMEOS
= "chromeos"
21 OS_WINDOWS
= "windows"
23 # Valid values for target_cpu:
28 def __init__(self
, build_dir
=None, target_os
=None, target_cpu
=None,
29 is_debug
=None, apk_name
="MojoRunner.apk"):
30 """Function arguments take precedence over GN args and default values."""
31 assert target_os
in (None, Config
.OS_ANDROID
, Config
.OS_CHROMEOS
,
32 Config
.OS_LINUX
, Config
.OS_MAC
, Config
.OS_WINDOWS
)
33 assert target_cpu
in (None, Config
.ARCH_X86
, Config
.ARCH_X64
,
35 assert is_debug
in (None, True, False)
38 "build_dir": build_dir
,
39 "target_os": self
.GetHostOS(),
40 "target_cpu": self
.GetHostCPU(),
42 "dcheck_always_on": False,
48 if target_os
is not None:
49 self
.values
["target_os"] = target_os
50 if target_cpu
is not None:
51 self
.values
["target_cpu"] = target_cpu
52 if is_debug
is not None:
53 self
.values
["is_debug"] = is_debug
57 if sys
.platform
== "linux2":
58 return Config
.OS_LINUX
59 if sys
.platform
== "darwin":
61 if sys
.platform
== "win32":
62 return Config
.OS_WINDOWS
63 raise NotImplementedError("Unsupported host OS")
67 # Derived from //native_client/pynacl/platform.py
68 machine
= platform
.machine()
69 if machine
in ("x86", "x86-32", "x86_32", "x8632", "i386", "i686", "ia32",
71 return Config
.ARCH_X86
72 if machine
in ("x86-64", "amd64", "AMD64", "x86_64", "x8664", "64"):
73 return Config
.ARCH_X64
74 if machine
.startswith("arm"):
75 return Config
.ARCH_ARM
76 raise Exception("Cannot identify CPU arch: %s" % machine
)
78 def _ParseGNArgs(self
):
79 """Parse the gn config file from the build directory, if it exists."""
80 TRANSLATIONS
= { "true": "True", "false": "False", }
81 if self
.values
["build_dir"] is None:
83 gn_file
= os
.path
.join(self
.values
["build_dir"], "args.gn")
84 if not os
.path
.isfile(gn_file
):
87 with
open(gn_file
, "r") as f
:
89 line
= re
.sub("\s*#.*", "", line
)
90 result
= re
.match("^\s*(\w+)\s*=\s*(.*)\s*$", line
)
93 value
= result
.group(2)
94 self
.values
[key
] = ast
.literal_eval(TRANSLATIONS
.get(value
, value
))
96 # Getters for standard fields ------------------------------------------------
100 """Build directory path."""
101 return self
.values
["build_dir"]
105 """OS of the build/test target."""
106 return self
.values
["target_os"]
109 def target_cpu(self
):
110 """CPU arch of the build/test target."""
111 return self
.values
["target_cpu"]
115 """Is Debug build?"""
116 return self
.values
["is_debug"]
119 def dcheck_always_on(self
):
120 """DCHECK and MOJO_DCHECK are fatal even in release builds"""
121 return self
.values
["dcheck_always_on"]
126 return self
.values
["is_asan"]
130 """Name of the APK file to run"""
131 return self
.values
["apk_name"]