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, is_verbose
=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)
36 assert is_verbose
in (None, True, False)
39 'build_dir': build_dir
,
40 'target_os': self
.GetHostOS(),
41 'target_cpu': self
.GetHostCPU(),
44 'dcheck_always_on': False,
50 if target_os
is not None:
51 self
.values
['target_os'] = target_os
52 if target_cpu
is not None:
53 self
.values
['target_cpu'] = target_cpu
54 if is_debug
is not None:
55 self
.values
['is_debug'] = is_debug
56 if is_verbose
is not None:
57 self
.values
['is_verbose'] = is_verbose
61 if sys
.platform
== 'linux2':
62 return Config
.OS_LINUX
63 if sys
.platform
== 'darwin':
65 if sys
.platform
== 'win32':
66 return Config
.OS_WINDOWS
67 raise NotImplementedError('Unsupported host OS')
71 # Derived from //native_client/pynacl/platform.py
72 machine
= platform
.machine()
73 if machine
in ('x86', 'x86-32', 'x86_32', 'x8632', 'i386', 'i686', 'ia32',
75 return Config
.ARCH_X86
76 if machine
in ('x86-64', 'amd64', 'AMD64', 'x86_64', 'x8664', '64'):
77 return Config
.ARCH_X64
78 if machine
.startswith('arm'):
79 return Config
.ARCH_ARM
80 raise Exception('Cannot identify CPU arch: %s' % machine
)
82 def _ParseGNArgs(self
):
83 '''Parse the gn config file from the build directory, if it exists.'''
84 TRANSLATIONS
= { 'true': 'True', 'false': 'False', }
85 if self
.values
['build_dir'] is None:
87 gn_file
= os
.path
.join(self
.values
['build_dir'], 'args.gn')
88 if not os
.path
.isfile(gn_file
):
91 with
open(gn_file
, 'r') as f
:
93 line
= re
.sub('\s*#.*', '', line
)
94 result
= re
.match('^\s*(\w+)\s*=\s*(.*)\s*$', line
)
97 value
= result
.group(2)
98 self
.values
[key
] = ast
.literal_eval(TRANSLATIONS
.get(value
, value
))
100 # Getters for standard fields ------------------------------------------------
104 '''Build directory path.'''
105 return self
.values
['build_dir']
109 '''OS of the build/test target.'''
110 return self
.values
['target_os']
113 def target_cpu(self
):
114 '''CPU arch of the build/test target.'''
115 return self
.values
['target_cpu']
119 '''Is Debug build?'''
120 return self
.values
['is_debug']
123 def is_verbose(self
):
124 '''Should print additional logging information?'''
125 return self
.values
['is_verbose']
128 def dcheck_always_on(self
):
129 '''DCHECK and MOJO_DCHECK are fatal even in release builds'''
130 return self
.values
['dcheck_always_on']
135 return self
.values
['is_asan']
139 '''Name of the APK file to run'''
140 return self
.values
['apk_name']