OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 # [Conditional] | 416 # [Conditional] |
417 def conditional_if_endif(code, conditional_string): | 417 def conditional_if_endif(code, conditional_string): |
418 # Jinja2 filter to generate if/endif directive blocks | 418 # Jinja2 filter to generate if/endif directive blocks |
419 if not conditional_string: | 419 if not conditional_string: |
420 return code | 420 return code |
421 return ('#if %s\n' % conditional_string + | 421 return ('#if %s\n' % conditional_string + |
422 code + | 422 code + |
423 '#endif // %s\n' % conditional_string) | 423 '#endif // %s\n' % conditional_string) |
424 | 424 |
425 | 425 |
| 426 def maybe_add_conditional(code, test, conditional): |
| 427 if not test: |
| 428 return code |
| 429 return generate_indented_conditional(code, conditional) |
| 430 |
426 # [Exposed] | 431 # [Exposed] |
427 def exposed_if(code, exposed_test): | 432 def exposed_if(code, exposed_test): |
428 if not exposed_test: | 433 return maybe_add_conditional(code, exposed_test, 'executionContext && (%s)'
% exposed_test) |
429 return code | |
430 return generate_indented_conditional(code, 'executionContext && (%s)' % expo
sed_test) | |
431 | 434 |
432 | 435 |
433 # [RuntimeEnabled] | 436 # [RuntimeEnabled] |
434 def runtime_enabled_if(code, runtime_enabled_function_name): | 437 def runtime_enabled_if(code, runtime_enabled_function_name): |
435 if not runtime_enabled_function_name: | 438 return maybe_add_conditional(code, runtime_enabled_function_name, '%s()' % r
untime_enabled_function_name) |
436 return code | |
437 return generate_indented_conditional(code, '%s()' % runtime_enabled_function
_name) | |
438 | 439 |
439 | 440 |
440 ################################################################################ | 441 ################################################################################ |
441 | 442 |
442 def main(argv): | 443 def main(argv): |
443 # If file itself executed, cache templates | 444 # If file itself executed, cache templates |
444 try: | 445 try: |
445 cache_dir = argv[1] | 446 cache_dir = argv[1] |
446 dummy_filename = argv[2] | 447 dummy_filename = argv[2] |
447 except IndexError as err: | 448 except IndexError as err: |
(...skipping 10 matching lines...) Expand all Loading... |
458 | 459 |
459 # Create a dummy file as output for the build system, | 460 # Create a dummy file as output for the build system, |
460 # since filenames of individual cache files are unpredictable and opaque | 461 # since filenames of individual cache files are unpredictable and opaque |
461 # (they are hashes of the template path, which varies based on environment) | 462 # (they are hashes of the template path, which varies based on environment) |
462 with open(dummy_filename, 'w') as dummy_file: | 463 with open(dummy_filename, 'w') as dummy_file: |
463 pass # |open| creates or touches the file | 464 pass # |open| creates or touches the file |
464 | 465 |
465 | 466 |
466 if __name__ == '__main__': | 467 if __name__ == '__main__': |
467 sys.exit(main(sys.argv)) | 468 sys.exit(main(sys.argv)) |
OLD | NEW |