OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import multiprocessing | 6 import multiprocessing |
7 import optparse | 7 import optparse |
8 import os | 8 import os |
9 import posixpath | 9 import posixpath |
10 import sys | 10 import sys |
(...skipping 22 matching lines...) Expand all Loading... |
33 'bionic', | 33 'bionic', |
34 'newlib', | 34 'newlib', |
35 'glibc', | 35 'glibc', |
36 'pnacl', | 36 'pnacl', |
37 'win', | 37 'win', |
38 'linux', | 38 'linux', |
39 'mac', | 39 'mac', |
40 ] | 40 ] |
41 | 41 |
42 # Global verbosity setting. | 42 # Global verbosity setting. |
43 # If set to try (normally via a command line arg) then build_projects will | 43 # If set to True (normally via a command line arg) then build_projects will |
44 # add V=1 to all calls to 'make' | 44 # add V=1 to all calls to 'make' |
45 verbose = False | 45 verbose = False |
46 | 46 |
47 | 47 |
| 48 def Trace(msg): |
| 49 if verbose: |
| 50 sys.stderr.write(str(msg) + '\n') |
| 51 |
| 52 |
48 def CopyFilesFromTo(filelist, srcdir, dstdir): | 53 def CopyFilesFromTo(filelist, srcdir, dstdir): |
49 for filename in filelist: | 54 for filename in filelist: |
50 srcpath = os.path.join(srcdir, filename) | 55 srcpath = os.path.join(srcdir, filename) |
51 dstpath = os.path.join(dstdir, filename) | 56 dstpath = os.path.join(dstdir, filename) |
52 buildbot_common.CopyFile(srcpath, dstpath) | 57 buildbot_common.CopyFile(srcpath, dstpath) |
53 | 58 |
54 | 59 |
55 def UpdateHelpers(pepperdir, clobber=False): | 60 def UpdateHelpers(pepperdir, clobber=False): |
56 tools_dir = os.path.join(pepperdir, 'tools') | 61 tools_dir = os.path.join(pepperdir, 'tools') |
57 if not os.path.exists(tools_dir): | 62 if not os.path.exists(tools_dir): |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 make_cmd.append('TOOLCHAIN=all') | 227 make_cmd.append('TOOLCHAIN=all') |
223 | 228 |
224 buildbot_common.Run(make_cmd, cwd=make_dir, env=env) | 229 buildbot_common.Run(make_cmd, cwd=make_dir, env=env) |
225 if clean: | 230 if clean: |
226 # Clean to remove temporary files but keep the built | 231 # Clean to remove temporary files but keep the built |
227 buildbot_common.Run(make_cmd + ['clean'], cwd=make_dir, env=env) | 232 buildbot_common.Run(make_cmd + ['clean'], cwd=make_dir, env=env) |
228 | 233 |
229 | 234 |
230 def BuildProjects(pepperdir, project_tree, deps=True, | 235 def BuildProjects(pepperdir, project_tree, deps=True, |
231 clean=False, config='Debug'): | 236 clean=False, config='Debug'): |
232 | |
233 # Make sure we build libraries (which live in 'src') before | 237 # Make sure we build libraries (which live in 'src') before |
234 # any of the examples. | 238 # any of the examples. |
235 build_first = [p for p in project_tree if p != 'src'] | 239 build_first = [p for p in project_tree if p != 'src'] |
236 build_second = [p for p in project_tree if p == 'src'] | 240 build_second = [p for p in project_tree if p == 'src'] |
237 | 241 |
238 for branch in build_first + build_second: | 242 for branch in build_first + build_second: |
239 BuildProjectsBranch(pepperdir, branch, deps, clean, config) | 243 BuildProjectsBranch(pepperdir, branch, deps, clean, config) |
240 | 244 |
241 | 245 |
242 def main(argv): | 246 def main(argv): |
243 parser = optparse.OptionParser() | 247 parser = optparse.OptionParser() |
244 parser.add_option('-c', '--clobber', | 248 parser.add_option('-c', '--clobber', |
245 help='Clobber project directories before copying new files', | 249 help='Clobber project directories before copying new files', |
246 action='store_true', default=False) | 250 action='store_true', default=False) |
247 parser.add_option('-b', '--build', | 251 parser.add_option('-b', '--build', |
248 help='Build the projects.', action='store_true') | 252 help='Build the projects. Otherwise the projects are only copied.', |
| 253 action='store_true') |
249 parser.add_option('--config', | 254 parser.add_option('--config', |
250 help='Choose configuration to build (Debug or Release). Builds both ' | 255 help='Choose configuration to build (Debug or Release). Builds both ' |
251 'by default') | 256 'by default') |
252 parser.add_option('--bionic', | 257 parser.add_option('--bionic', |
253 help='Enable bionic projects', action='store_true') | 258 help='Enable bionic projects', action='store_true') |
254 parser.add_option('-x', '--experimental', | 259 parser.add_option('-x', '--experimental', |
255 help='Build experimental projects', action='store_true') | 260 help='Build experimental projects', action='store_true') |
256 parser.add_option('-t', '--toolchain', | 261 parser.add_option('-t', '--toolchain', |
257 help='Build using toolchain. Can be passed more than once.', | 262 help='Build using toolchain. Can be passed more than once.', |
258 action='append', default=[]) | 263 action='append', default=[]) |
259 parser.add_option('-d', '--dest', | 264 parser.add_option('-d', '--dest', |
260 help='Select which build destinations (project types) are valid.', | 265 help='Select which build destinations (project types) are valid.', |
261 action='append') | 266 action='append') |
262 parser.add_option('-v', '--verbose', action='store_true') | 267 parser.add_option('-v', '--verbose', action='store_true') |
263 | 268 |
264 # To setup bash completion for this command first install optcomplete | 269 # To setup bash completion for this command first install optcomplete |
265 # and then add this line to your .bashrc: | 270 # and then add this line to your .bashrc: |
266 # complete -F _optcomplete build_projects.py | 271 # complete -F _optcomplete build_projects.py |
267 try: | 272 try: |
268 import optcomplete | 273 import optcomplete |
269 optcomplete.autocomplete(parser) | 274 optcomplete.autocomplete(parser) |
270 except ImportError: | 275 except ImportError: |
271 pass | 276 pass |
272 | 277 |
273 options, args = parser.parse_args(argv[1:]) | 278 options, args = parser.parse_args(argv[1:]) |
274 | 279 |
| 280 global verbose |
| 281 if options.verbose: |
| 282 verbose = True |
| 283 |
| 284 buildbot_common.verbose = verbose |
| 285 |
275 if 'NACL_SDK_ROOT' in os.environ: | 286 if 'NACL_SDK_ROOT' in os.environ: |
276 # We don't want the currently configured NACL_SDK_ROOT to have any effect | 287 # We don't want the currently configured NACL_SDK_ROOT to have any effect |
277 # on the build. | 288 # on the build. |
278 del os.environ['NACL_SDK_ROOT'] | 289 del os.environ['NACL_SDK_ROOT'] |
279 | 290 |
280 pepper_ver = str(int(build_version.ChromeMajorVersion())) | 291 pepper_ver = str(int(build_version.ChromeMajorVersion())) |
281 pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver) | 292 pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver) |
282 | 293 |
283 if not options.toolchain: | 294 if not options.toolchain: |
284 # Order matters here: the default toolchain for an example's Makefile will | 295 # Order matters here: the default toolchain for an example's Makefile will |
285 # be the first toolchain in this list that is available in the example. | 296 # be the first toolchain in this list that is available in the example. |
286 # e.g. If an example supports newlib and glibc, then the default will be | 297 # e.g. If an example supports newlib and glibc, then the default will be |
287 # newlib. | 298 # newlib. |
288 options.toolchain = ['pnacl', 'newlib', 'glibc', 'host'] | 299 options.toolchain = ['pnacl', 'newlib', 'glibc', 'host'] |
289 if options.experimental or options.bionic: | 300 if options.experimental or options.bionic: |
290 options.toolchain.append('bionic') | 301 options.toolchain.append('bionic') |
291 | 302 |
292 if 'host' in options.toolchain: | 303 if 'host' in options.toolchain: |
293 options.toolchain.remove('host') | 304 options.toolchain.remove('host') |
294 options.toolchain.append(getos.GetPlatform()) | 305 options.toolchain.append(getos.GetPlatform()) |
295 print 'Adding platform: ' + getos.GetPlatform() | 306 Trace('Adding platform: ' + getos.GetPlatform()) |
296 | 307 |
297 ValidateToolchains(options.toolchain) | 308 ValidateToolchains(options.toolchain) |
298 | 309 |
299 filters = {} | 310 filters = {} |
300 if options.toolchain: | 311 if options.toolchain: |
301 filters['TOOLS'] = options.toolchain | 312 filters['TOOLS'] = options.toolchain |
302 print 'Filter by toolchain: ' + str(options.toolchain) | 313 Trace('Filter by toolchain: ' + str(options.toolchain)) |
303 if not options.experimental: | 314 if not options.experimental: |
304 filters['EXPERIMENTAL'] = False | 315 filters['EXPERIMENTAL'] = False |
305 if options.dest: | 316 if options.dest: |
306 filters['DEST'] = options.dest | 317 filters['DEST'] = options.dest |
307 print 'Filter by type: ' + str(options.dest) | 318 Trace('Filter by type: ' + str(options.dest)) |
308 if args: | 319 if args: |
309 filters['NAME'] = args | 320 filters['NAME'] = args |
310 print 'Filter by name: ' + str(args) | 321 Trace('Filter by name: ' + str(args)) |
311 | 322 |
312 try: | 323 try: |
313 project_tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters) | 324 project_tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters) |
314 except parse_dsc.ValidationError as e: | 325 except parse_dsc.ValidationError as e: |
315 buildbot_common.ErrorExit(str(e)) | 326 buildbot_common.ErrorExit(str(e)) |
316 parse_dsc.PrintProjectTree(project_tree) | 327 |
| 328 if verbose: |
| 329 parse_dsc.PrintProjectTree(project_tree) |
317 | 330 |
318 UpdateHelpers(pepperdir, clobber=options.clobber) | 331 UpdateHelpers(pepperdir, clobber=options.clobber) |
319 UpdateProjects(pepperdir, project_tree, options.toolchain, | 332 UpdateProjects(pepperdir, project_tree, options.toolchain, |
320 clobber=options.clobber) | 333 clobber=options.clobber) |
321 | 334 |
322 if options.verbose: | |
323 global verbose | |
324 verbose = True | |
325 | |
326 if options.build: | 335 if options.build: |
327 if options.config: | 336 if options.config: |
328 configs = [options.config] | 337 configs = [options.config] |
329 else: | 338 else: |
330 configs = ['Debug', 'Release'] | 339 configs = ['Debug', 'Release'] |
331 for config in configs: | 340 for config in configs: |
332 BuildProjects(pepperdir, project_tree, config=config) | 341 BuildProjects(pepperdir, project_tree, config=config) |
333 | 342 |
334 return 0 | 343 return 0 |
335 | 344 |
336 | 345 |
337 if __name__ == '__main__': | 346 if __name__ == '__main__': |
338 script_name = os.path.basename(sys.argv[0]) | 347 script_name = os.path.basename(sys.argv[0]) |
339 try: | 348 try: |
340 sys.exit(main(sys.argv)) | 349 sys.exit(main(sys.argv)) |
341 except parse_dsc.ValidationError as e: | 350 except parse_dsc.ValidationError as e: |
342 buildbot_common.ErrorExit('%s: %s' % (script_name, e)) | 351 buildbot_common.ErrorExit('%s: %s' % (script_name, e)) |
343 except KeyboardInterrupt: | 352 except KeyboardInterrupt: |
344 buildbot_common.ErrorExit('%s: interrupted' % script_name) | 353 buildbot_common.ErrorExit('%s: interrupted' % script_name) |
OLD | NEW |