OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 Google Inc. All rights reserved. | 3 # Copyright (c) 2012 Google Inc. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
| 7 from __future__ import print_function |
| 8 |
7 import copy | 9 import copy |
8 import gyp.input | 10 import gyp.input |
9 import optparse | 11 import optparse |
10 import os.path | 12 import os.path |
11 import re | 13 import re |
12 import shlex | 14 import shlex |
13 import sys | 15 import sys |
14 import traceback | 16 import traceback |
15 from gyp.common import GypError | 17 from gyp.common import GypError |
16 | 18 |
| 19 try: |
| 20 basestring = basestring |
| 21 except NameError: |
| 22 basestring = str |
| 23 |
17 # Default debug modes for GYP | 24 # Default debug modes for GYP |
18 debug = {} | 25 debug = {} |
19 | 26 |
20 # List of "official" debug modes, but you can use anything you like. | 27 # List of "official" debug modes, but you can use anything you like. |
21 DEBUG_GENERAL = 'general' | 28 DEBUG_GENERAL = 'general' |
22 DEBUG_VARIABLES = 'variables' | 29 DEBUG_VARIABLES = 'variables' |
23 DEBUG_INCLUDES = 'includes' | 30 DEBUG_INCLUDES = 'includes' |
24 | 31 |
25 | |
26 def DebugOutput(mode, message, *args): | 32 def DebugOutput(mode, message, *args): |
27 if 'all' in gyp.debug or mode in gyp.debug: | 33 if 'all' in gyp.debug or mode in gyp.debug: |
28 ctx = ('unknown', 0, 'unknown') | 34 ctx = ('unknown', 0, 'unknown') |
29 try: | 35 try: |
30 f = traceback.extract_stack(limit=2) | 36 f = traceback.extract_stack(limit=2) |
31 if f: | 37 if f: |
32 ctx = f[0][:3] | 38 ctx = f[0][:3] |
33 except: | 39 except: |
34 pass | 40 pass |
35 if args: | 41 if args: |
36 message %= args | 42 message %= args |
37 print '%s:%s:%d:%s %s' % (mode.upper(), os.path.basename(ctx[0]), | 43 print('%s:%s:%d:%s %s' % (mode.upper(), os.path.basename(ctx[0]), |
38 ctx[1], ctx[2], message) | 44 ctx[1], ctx[2], message)) |
39 | 45 |
40 def FindBuildFiles(): | 46 def FindBuildFiles(): |
41 extension = '.gyp' | 47 extension = '.gyp' |
42 files = os.listdir(os.getcwd()) | 48 files = os.listdir(os.getcwd()) |
43 build_files = [] | 49 build_files = [] |
44 for file in files: | 50 for file in files: |
45 if file.endswith(extension): | 51 if file.endswith(extension): |
46 build_files.append(file) | 52 build_files.append(file) |
47 return build_files | 53 return build_files |
48 | 54 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 if not path: | 206 if not path: |
201 return os.path.curdir | 207 return os.path.curdir |
202 return path | 208 return path |
203 | 209 |
204 def Noop(value): | 210 def Noop(value): |
205 return value | 211 return value |
206 | 212 |
207 # We always want to ignore the environment when regenerating, to avoid | 213 # We always want to ignore the environment when regenerating, to avoid |
208 # duplicate or changed flags in the environment at the time of regeneration. | 214 # duplicate or changed flags in the environment at the time of regeneration. |
209 flags = ['--ignore-environment'] | 215 flags = ['--ignore-environment'] |
210 for name, metadata in options._regeneration_metadata.iteritems(): | 216 for name, metadata in options._regeneration_metadata.items(): |
211 opt = metadata['opt'] | 217 opt = metadata['opt'] |
212 value = getattr(options, name) | 218 value = getattr(options, name) |
213 value_predicate = metadata['type'] == 'path' and FixPath or Noop | 219 value_predicate = metadata['type'] == 'path' and FixPath or Noop |
214 action = metadata['action'] | 220 action = metadata['action'] |
215 env_name = metadata['env_name'] | 221 env_name = metadata['env_name'] |
216 if action == 'append': | 222 if action == 'append': |
217 flags.extend(RegenerateAppendFlag(opt, value, value_predicate, | 223 flags.extend(RegenerateAppendFlag(opt, value, value_predicate, |
218 env_name, options)) | 224 env_name, options)) |
219 elif action in ('store', None): # None is a synonym for 'store'. | 225 elif action in ('store', None): # None is a synonym for 'store'. |
220 if value: | 226 if value: |
221 flags.append(FormatOpt(opt, value_predicate(value))) | 227 flags.append(FormatOpt(opt, value_predicate(value))) |
222 elif options.use_environment and env_name and os.environ.get(env_name): | 228 elif options.use_environment and env_name and os.environ.get(env_name): |
223 flags.append(FormatOpt(opt, value_predicate(os.environ.get(env_name)))) | 229 flags.append(FormatOpt(opt, value_predicate(os.environ.get(env_name)))) |
224 elif action in ('store_true', 'store_false'): | 230 elif action in ('store_true', 'store_false'): |
225 if ((action == 'store_true' and value) or | 231 if ((action == 'store_true' and value) or |
226 (action == 'store_false' and not value)): | 232 (action == 'store_false' and not value)): |
227 flags.append(opt) | 233 flags.append(opt) |
228 elif options.use_environment and env_name: | 234 elif options.use_environment and env_name: |
229 print >>sys.stderr, ('Warning: environment regeneration unimplemented ' | 235 print(('Warning: environment regeneration unimplemented ' |
230 'for %s flag %r env_name %r' % (action, opt, | 236 'for %s flag %r env_name %r' % (action, opt, |
231 env_name)) | 237 env_name)), |
| 238 file=sys.stderr) |
232 else: | 239 else: |
233 print >>sys.stderr, ('Warning: regeneration unimplemented for action %r ' | 240 print(('Warning: regeneration unimplemented for action %r ' |
234 'flag %r' % (action, opt)) | 241 'flag %r' % (action, opt)), file=sys.stderr) |
235 | 242 |
236 return flags | 243 return flags |
237 | 244 |
238 class RegeneratableOptionParser(optparse.OptionParser): | 245 class RegeneratableOptionParser(optparse.OptionParser): |
239 def __init__(self): | 246 def __init__(self): |
240 self.__regeneratable_options = {} | 247 self.__regeneratable_options = {} |
241 optparse.OptionParser.__init__(self) | 248 optparse.OptionParser.__init__(self) |
242 | 249 |
243 def add_option(self, *args, **kw): | 250 def add_option(self, *args, **kw): |
244 """Add an option to the parser. | 251 """Add an option to the parser. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 # TODO(mark): Chromium-specific hack! | 431 # TODO(mark): Chromium-specific hack! |
425 # For Chromium, the gyp "depth" variable should always be a relative path | 432 # For Chromium, the gyp "depth" variable should always be a relative path |
426 # to Chromium's top-level "src" directory. If no depth variable was set | 433 # to Chromium's top-level "src" directory. If no depth variable was set |
427 # on the command line, try to find a "src" directory by looking at the | 434 # on the command line, try to find a "src" directory by looking at the |
428 # absolute path to each build file's directory. The first "src" component | 435 # absolute path to each build file's directory. The first "src" component |
429 # found will be treated as though it were the path used for --depth. | 436 # found will be treated as though it were the path used for --depth. |
430 if not options.depth: | 437 if not options.depth: |
431 for build_file in build_files: | 438 for build_file in build_files: |
432 build_file_dir = os.path.abspath(os.path.dirname(build_file)) | 439 build_file_dir = os.path.abspath(os.path.dirname(build_file)) |
433 build_file_dir_components = build_file_dir.split(os.path.sep) | 440 build_file_dir_components = build_file_dir.split(os.path.sep) |
434 components_len = len(build_file_dir_components) | 441 for component in reversed(build_file_dir_components): |
435 for index in xrange(components_len - 1, -1, -1): | 442 if component == 'src': |
436 if build_file_dir_components[index] == 'src': | |
437 options.depth = os.path.sep.join(build_file_dir_components) | 443 options.depth = os.path.sep.join(build_file_dir_components) |
438 break | 444 break |
439 del build_file_dir_components[index] | 445 del build_file_dir_components[-1] |
440 | 446 |
441 # If the inner loop found something, break without advancing to another | 447 # If the inner loop found something, break without advancing to another |
442 # build file. | 448 # build file. |
443 if options.depth: | 449 if options.depth: |
444 break | 450 break |
445 | 451 |
446 if not options.depth: | 452 if not options.depth: |
447 raise GypError('Could not automatically locate src directory. This is' | 453 raise GypError('Could not automatically locate src directory. This is' |
448 'a temporary Chromium feature that will be removed. Use' | 454 'a temporary Chromium feature that will be removed. Use' |
449 '--depth as a workaround.') | 455 '--depth as a workaround.') |
(...skipping 18 matching lines...) Expand all Loading... |
468 "cmdline_default_variables: %s", cmdline_default_variables) | 474 "cmdline_default_variables: %s", cmdline_default_variables) |
469 | 475 |
470 # Set up includes. | 476 # Set up includes. |
471 includes = [] | 477 includes = [] |
472 | 478 |
473 # If ~/.gyp/include.gypi exists, it'll be forcibly included into every | 479 # If ~/.gyp/include.gypi exists, it'll be forcibly included into every |
474 # .gyp file that's loaded, before anything else is included. | 480 # .gyp file that's loaded, before anything else is included. |
475 if home_dot_gyp != None: | 481 if home_dot_gyp != None: |
476 default_include = os.path.join(home_dot_gyp, 'include.gypi') | 482 default_include = os.path.join(home_dot_gyp, 'include.gypi') |
477 if os.path.exists(default_include): | 483 if os.path.exists(default_include): |
478 print 'Using overrides found in ' + default_include | 484 print('Using overrides found in ' + default_include) |
479 includes.append(default_include) | 485 includes.append(default_include) |
480 | 486 |
481 # Command-line --include files come after the default include. | 487 # Command-line --include files come after the default include. |
482 if options.includes: | 488 if options.includes: |
483 includes.extend(options.includes) | 489 includes.extend(options.includes) |
484 | 490 |
485 # Generator flags should be prefixed with the target generator since they | 491 # Generator flags should be prefixed with the target generator since they |
486 # are global across all generator runs. | 492 # are global across all generator runs. |
487 gen_flags = [] | 493 gen_flags = [] |
488 if options.use_environment: | 494 if options.use_environment: |
489 gen_flags += ShlexEnv('GYP_GENERATOR_FLAGS') | 495 gen_flags += ShlexEnv('GYP_GENERATOR_FLAGS') |
490 if options.generator_flags: | 496 if options.generator_flags: |
491 gen_flags += options.generator_flags | 497 gen_flags += options.generator_flags |
492 generator_flags = NameValueListToDict(gen_flags) | 498 generator_flags = NameValueListToDict(gen_flags) |
493 if DEBUG_GENERAL in gyp.debug.keys(): | 499 if DEBUG_GENERAL in gyp.debug: |
494 DebugOutput(DEBUG_GENERAL, "generator_flags: %s", generator_flags) | 500 DebugOutput(DEBUG_GENERAL, "generator_flags: %s", generator_flags) |
495 | 501 |
496 # Generate all requested formats (use a set in case we got one format request | 502 # Generate all requested formats (use a set in case we got one format request |
497 # twice) | 503 # twice) |
498 for format in set(options.formats): | 504 for format in set(options.formats): |
499 params = {'options': options, | 505 params = {'options': options, |
500 'build_files': build_files, | 506 'build_files': build_files, |
501 'generator_flags': generator_flags, | 507 'generator_flags': generator_flags, |
502 'cwd': os.getcwd(), | 508 'cwd': os.getcwd(), |
503 'build_files_arg': build_files_arg, | 509 'build_files_arg': build_files_arg, |
(...skipping 12 matching lines...) Expand all Loading... |
516 # TODO(mark): Pass |data| for now because the generator needs a list of | 522 # TODO(mark): Pass |data| for now because the generator needs a list of |
517 # build files that came in. In the future, maybe it should just accept | 523 # build files that came in. In the future, maybe it should just accept |
518 # a list, and not the whole data dict. | 524 # a list, and not the whole data dict. |
519 # NOTE: flat_list is the flattened dependency graph specifying the order | 525 # NOTE: flat_list is the flattened dependency graph specifying the order |
520 # that targets may be built. Build systems that operate serially or that | 526 # that targets may be built. Build systems that operate serially or that |
521 # need to have dependencies defined before dependents reference them should | 527 # need to have dependencies defined before dependents reference them should |
522 # generate targets in the order specified in flat_list. | 528 # generate targets in the order specified in flat_list. |
523 generator.GenerateOutput(flat_list, targets, data, params) | 529 generator.GenerateOutput(flat_list, targets, data, params) |
524 | 530 |
525 if options.configs: | 531 if options.configs: |
526 valid_configs = targets[flat_list[0]]['configurations'].keys() | 532 valid_configs = targets[flat_list[0]]['configurations'] |
527 for conf in options.configs: | 533 for conf in options.configs: |
528 if conf not in valid_configs: | 534 if conf not in valid_configs: |
529 raise GypError('Invalid config specified via --build: %s' % conf) | 535 raise GypError('Invalid config specified via --build: %s' % conf) |
530 generator.PerformBuild(data, options.configs, params) | 536 generator.PerformBuild(data, options.configs, params) |
531 | 537 |
532 # Done | 538 # Done |
533 return 0 | 539 return 0 |
534 | 540 |
535 | 541 |
536 def main(args): | 542 def main(args): |
537 try: | 543 try: |
538 return gyp_main(args) | 544 return gyp_main(args) |
539 except GypError, e: | 545 except GypError as e: |
540 sys.stderr.write("gyp: %s\n" % e) | 546 sys.stderr.write("gyp: %s\n" % e) |
541 return 1 | 547 return 1 |
542 | 548 |
543 # NOTE: setuptools generated console_scripts calls function with no arguments | 549 # NOTE: setuptools generated console_scripts calls function with no arguments |
544 def script_main(): | 550 def script_main(): |
545 return main(sys.argv[1:]) | 551 return main(sys.argv[1:]) |
546 | 552 |
547 if __name__ == '__main__': | 553 if __name__ == '__main__': |
548 sys.exit(script_main()) | 554 sys.exit(script_main()) |
OLD | NEW |