blob: 9cc76e514543e7d59c8905310792e39a36e30285 [file] [log] [blame]
Chun-ta Lin56112372014-07-16 06:35:59 +00001# Copyright (c) 2012 The Chromium OS 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.
4
5import os
6
7# Protobuffer compilation
8def ProtocolBufferEmitter(target, source, env):
9 """ Inputs:
10 target: list of targets to compile to
11 source: list of sources to compile
12 env: the scons environment in which we are compiling
13 Outputs:
14 target: the list of targets we'll emit
15 source: the list of sources we'll compile"""
16 output = str(source[0])
17 output = output[0:output.rfind('.proto')]
18 target = [
19 output + '.pb.cc',
20 output + '.pb.h',
21 ]
22 return target, source
23
24def ProtocolBufferGenerator(source, target, env, for_signature):
25 """ Inputs:
26 source: list of sources to process
27 target: list of targets to generate
28 env: scons environment in which we are working
29 for_signature: unused
30 Outputs: a list of commands to execute to generate the targets from
31 the sources."""
32 commands = [
33 '/usr/bin/protoc '
34 ' --proto_path . ${SOURCES} --cpp_out .']
35 return commands
36
37proto_builder = Builder(generator = ProtocolBufferGenerator,
38 emitter = ProtocolBufferEmitter,
39 single_source = 1,
40 suffix = '.pb.cc')
41
42def DbusBindingsEmitter(target, source, env):
43 """ Inputs:
44 target: unused
45 source: list containing the source .xml file
46 env: the scons environment in which we are compiling
47 Outputs:
48 target: the list of targets we'll emit
49 source: the list of sources we'll process"""
50 output = str(source[0])
51 output = output[0:output.rfind('.xml')]
52 target = [
53 output + '.dbusserver.h',
54 output + '.dbusclient.h'
55 ]
56 return target, source
57
58def DbusBindingsGenerator(source, target, env, for_signature):
59 """ Inputs:
60 source: list of sources to process
61 target: list of targets to generate
62 env: scons environment in which we are working
63 for_signature: unused
64 Outputs: a list of commands to execute to generate the targets from
65 the sources."""
66 commands = []
67 for target_file in target:
68 if str(target_file).endswith('.dbusserver.h'):
69 mode_flag = '--mode=glib-server '
70 else:
71 mode_flag = '--mode=glib-client '
72 cmd = '/usr/bin/dbus-binding-tool %s --prefix=update_engine_service ' \
73 '%s > %s' % (mode_flag, str(source[0]), str(target_file))
74 commands.append(cmd)
75 return commands
76
77dbus_bindings_builder = Builder(generator = DbusBindingsGenerator,
78 emitter = DbusBindingsEmitter,
79 single_source = 1,
80 suffix = 'dbusclient.h')
81
82# Public key generation
83def PublicKeyEmitter(target, source, env):
84 """ Inputs:
85 target: list of targets to compile to
86 source: list of sources to compile
87 env: the scons environment in which we are compiling
88 Outputs:
89 target: the list of targets we'll emit
90 source: the list of sources we'll compile"""
91 targets = []
92 for source_file in source:
93 output = str(source_file)
94 output = output[0:output.rfind('.pem')]
95 output += '.pub.pem'
96 targets.append(output)
97 return targets, source
98
99def PublicKeyGenerator(source, target, env, for_signature):
100 """ Inputs:
101 source: list of sources to process
102 target: list of targets to generate
103 env: scons environment in which we are working
104 for_signature: unused
105 Outputs: a list of commands to execute to generate the targets from
106 the sources."""
107 commands = []
108 for source_file in source:
109 output = str(source_file)
110 output = output[0:output.rfind('.pem')]
111 output += '.pub.pem'
112 cmd = '/usr/bin/openssl rsa -in %s -pubout -out %s' % (source_file, output)
113 commands.append(cmd)
114 return commands
115
116public_key_builder = Builder(generator = PublicKeyGenerator,
117 emitter = PublicKeyEmitter,
118 suffix = '.pub.pem')
119
120env = Environment()
121for key in Split('CC CXX AR RANLIB LD NM'):
122 value = os.environ.get(key)
123 if value != None:
124 env[key] = value
125for key in Split('CFLAGS CCFLAGS LDFLAGS CPPPATH LIBPATH'):
126 value = os.environ.get(key)
127 if value != None:
128 env[key] = Split(value)
129
130for key in Split('PKG_CONFIG_LIBDIR PKG_CONFIG_PATH SYSROOT'):
131 if os.environ.has_key(key):
132 env['ENV'][key] = os.environ[key]
133
134
135env['LINKFLAGS'] = Split("""
136 -Wl,--gc-sections""")
137env['LINKFLAGS'] += env.get('LDFLAGS', [])
138
139env['CCFLAGS'] = Split("""
140 -g
141 -ffunction-sections
142 -fno-exceptions
143 -fno-strict-aliasing
144 -std=gnu++11
145 -Wall
146 -Wextra
147 -Werror
148 -Wno-unused-parameter
149 -Wno-deprecated-register
150 -D__STDC_FORMAT_MACROS=1
151 -D_FILE_OFFSET_BITS=64
152 -D_POSIX_C_SOURCE=199309L""")
153env['CCFLAGS'] += env['CFLAGS']
154
155BASE_VER = os.environ.get('BASE_VER', '271506')
156env['LIBS'] = Split("""bz2
157 gflags
158 policy-%s
159 rootdev
160 rt
161 vboot_host""" % (BASE_VER,))
162env['CPPPATH'] = ['..']
163env['BUILDERS']['ProtocolBuffer'] = proto_builder
164env['BUILDERS']['DbusBindings'] = dbus_bindings_builder
165env['BUILDERS']['PublicKey'] = public_key_builder
166
167# Fix issue with scons not passing pkg-config vars through the environment.
168for key in Split('PKG_CONFIG_LIBDIR PKG_CONFIG_PATH'):
169 if os.environ.has_key(key):
170 env['ENV'][key] = os.environ[key]
171
172pkgconfig = os.environ.get('PKG_CONFIG', 'pkg-config')
173
174env.ParseConfig(pkgconfig + ' --cflags --libs ' + ' '.join((
175 'dbus-1',
176 'dbus-glib-1',
177 'ext2fs',
178 'gio-2.0',
179 'gio-unix-2.0',
180 'glib-2.0',
181 'gthread-2.0',
182 'libchrome-%s' % BASE_VER,
183 'libchromeos-%s' % BASE_VER,
184 'libcrypto',
185 'libcurl',
186 'libmetrics-%s' % BASE_VER,
187 'libssl',
188 'libxml-2.0',
189 'protobuf')))
190env.ProtocolBuffer('update_metadata.pb.cc', 'update_metadata.proto')
191env.PublicKey('unittest_key.pub.pem', 'unittest_key.pem')
192env.PublicKey('unittest_key2.pub.pem', 'unittest_key2.pem')
193
194# Target name is derived from the source .xml filename. The passed name is
195# unused.
196env.DbusBindings(None, 'update_engine.xml')
197
198if ARGUMENTS.get('debug', 0):
199 env['CCFLAGS'] += ['-fprofile-arcs', '-ftest-coverage']
200 env['LIBS'] += ['bz2', 'gcov']
201
202sources = Split("""action_processor.cc
203 bzip.cc
204 bzip_extent_writer.cc
205 certificate_checker.cc
206 chrome_browser_proxy_resolver.cc
207 clock.cc
208 connection_manager.cc
209 constants.cc
210 dbus_service.cc
211 delta_performer.cc
212 download_action.cc
213 extent_ranges.cc
214 extent_writer.cc
215 file_descriptor.cc
216 file_writer.cc
217 filesystem_copier_action.cc
218 hardware.cc
219 http_common.cc
220 http_fetcher.cc
221 hwid_override.cc
222 install_plan.cc
223 libcurl_http_fetcher.cc
224 metrics.cc
225 multi_range_http_fetcher.cc
226 omaha_hash_calculator.cc
227 omaha_request_action.cc
228 omaha_request_params.cc
229 omaha_response_handler_action.cc
230 p2p_manager.cc
231 payload_constants.cc
232 payload_generator/cycle_breaker.cc
233 payload_generator/delta_diff_generator.cc
234 payload_generator/extent_mapper.cc
235 payload_generator/filesystem_iterator.cc
236 payload_generator/full_update_generator.cc
237 payload_generator/graph_utils.cc
238 payload_generator/metadata.cc
239 payload_generator/tarjan.cc
240 payload_generator/topological_sort.cc
241 payload_signer.cc
242 payload_state.cc
243 postinstall_runner_action.cc
244 prefs.cc
245 proxy_resolver.cc
246 real_system_state.cc
247 simple_key_value_store.cc
248 subprocess.cc
249 terminator.cc
250 update_attempter.cc
251 update_check_scheduler.cc
252 update_manager/boxed_value.cc
253 update_manager/chromeos_policy.cc
254 update_manager/evaluation_context.cc
255 update_manager/event_loop.cc
256 update_manager/policy.cc
257 update_manager/real_config_provider.cc
258 update_manager/real_device_policy_provider.cc
259 update_manager/real_random_provider.cc
260 update_manager/real_shill_provider.cc
261 update_manager/real_system_provider.cc
262 update_manager/real_time_provider.cc
263 update_manager/real_updater_provider.cc
264 update_manager/state_factory.cc
265 update_manager/update_manager.cc
266 update_metadata.pb.cc
267 utils.cc""")
268main = ['main.cc']
269
270unittest_sources = Split("""action_pipe_unittest.cc
271 action_processor_unittest.cc
272 action_unittest.cc
273 bzip_extent_writer_unittest.cc
274 certificate_checker_unittest.cc
275 chrome_browser_proxy_resolver_unittest.cc
276 connection_manager_unittest.cc
277 delta_performer_unittest.cc
278 download_action_unittest.cc
279 extent_ranges_unittest.cc
280 extent_writer_unittest.cc
281 fake_prefs.cc
282 fake_system_state.cc
283 file_writer_unittest.cc
284 filesystem_copier_action_unittest.cc
285 http_fetcher_unittest.cc
286 hwid_override_unittest.cc
287 mock_http_fetcher.cc
288 omaha_hash_calculator_unittest.cc
289 omaha_request_action_unittest.cc
290 omaha_request_params_unittest.cc
291 omaha_response_handler_action_unittest.cc
292 p2p_manager_unittest.cc
293 payload_generator/cycle_breaker_unittest.cc
294 payload_generator/delta_diff_generator_unittest.cc
295 payload_generator/extent_mapper_unittest.cc
296 payload_generator/filesystem_iterator_unittest.cc
297 payload_generator/full_update_generator_unittest.cc
298 payload_generator/graph_utils_unittest.cc
299 payload_generator/metadata_unittest.cc
300 payload_generator/tarjan_unittest.cc
301 payload_generator/topological_sort_unittest.cc
302 payload_signer_unittest.cc
303 payload_state_unittest.cc
304 postinstall_runner_action_unittest.cc
305 prefs_unittest.cc
306 simple_key_value_store_unittest.cc
307 subprocess_unittest.cc
308 terminator_unittest.cc
309 test_utils.cc
310 update_attempter_unittest.cc
311 update_check_scheduler_unittest.cc
312 update_manager/boxed_value_unittest.cc
313 update_manager/chromeos_policy_unittest.cc
314 update_manager/evaluation_context_unittest.cc
315 update_manager/event_loop_unittest.cc
316 update_manager/generic_variables_unittest.cc
317 update_manager/prng_unittest.cc
318 update_manager/real_config_provider_unittest.cc
319 update_manager/real_device_policy_provider_unittest.cc
320 update_manager/real_random_provider_unittest.cc
321 update_manager/real_shill_provider_unittest.cc
322 update_manager/real_system_provider_unittest.cc
323 update_manager/real_time_provider_unittest.cc
324 update_manager/real_updater_provider_unittest.cc
325 update_manager/umtest_utils.cc
326 update_manager/update_manager_unittest.cc
327 update_manager/variable_unittest.cc
328 utils_unittest.cc
329 zip_unittest.cc""")
330unittest_main = ['testrunner.cc']
331
332client_main = ['update_engine_client.cc']
333
334delta_generator_main = ['payload_generator/generate_delta_main.cc']
335
336# Hack to generate header files first. They are generated as a side effect
337# of generating other files (usually their corresponding .c(c) files),
338# so we make all sources depend on those other files.
339all_sources = []
340all_sources.extend(sources)
341all_sources.extend(unittest_sources)
342all_sources.extend(main)
343all_sources.extend(unittest_main)
344all_sources.extend(client_main)
345all_sources.extend(delta_generator_main)
346for source in all_sources:
347 if source.endswith('_unittest.cc'):
348 env.Depends(source, 'unittest_key.pub.pem')
349 if source.endswith('.pb.cc'):
350 continue
351 env.Depends(source, 'update_metadata.pb.cc')
352 env.Depends(source, 'update_engine.dbusclient.h')
353
354update_engine_core = env.Library('update_engine_core', sources)
355env.Prepend(LIBS=[update_engine_core])
356
357env.Program('update_engine', main)
358
359client_cmd = env.Program('update_engine_client', client_main);
360
361delta_generator_cmd = env.Program('delta_generator',
362 delta_generator_main)
363
364http_server_cmd = env.Program('test_http_server', 'test_http_server.cc')
365
366unittest_env = env.Clone()
367unittest_env.Append(LIBS=['gmock', 'gtest'])
368unittest_cmd = unittest_env.Program('update_engine_unittests',
369 unittest_sources + unittest_main)
370Clean(unittest_cmd, Glob('*.gcda') + Glob('*.gcno') + Glob('*.gcov') +
371 Split('html app.info'))