OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 |
| 3 # Copyright 2014 Google Inc. |
| 4 # |
| 5 # Use of this source code is governed by a BSD-style license that can be |
| 6 # found in the LICENSE file. |
| 7 |
| 8 """Function for generating the SkUserConfig file, customized for Android.""" |
| 9 |
| 10 import os |
| 11 |
| 12 |
| 13 AUTOGEN_WARNING = ( |
| 14 """ |
| 15 /////////////////////////////////////////////////////////////////////////////// |
| 16 // |
| 17 // THIS FILE IS AUTOGENERATED BY GYP_TO_ANDROID.PY. DO NOT EDIT. |
| 18 // |
| 19 // This file contains Skia's upstream include/config/SkUserConfig.h as a |
| 20 // reference, followed by the actual defines set for Android. |
| 21 // |
| 22 /////////////////////////////////////////////////////////////////////////////// |
| 23 |
| 24 """ |
| 25 ) |
| 26 |
| 27 BUILD_GUARD = 'SkUserConfig_Android_DEFINED' |
| 28 |
| 29 |
| 30 def generate_user_config(original_sk_user_config, target_dir, ordered_set): |
| 31 """Generate the SkUserConfig file specific to the Android framework. |
| 32 |
| 33 Android needs its #defines in its skia/include/core directory, so that other |
| 34 libraries which use Skia's headers get the right definitions. This function |
| 35 takes the existing sample version of SkUserConfig, checked into Skia, and |
| 36 appends the defines from ordered_set, which is expected to be a |
| 37 vars_dict_lib.OrderedSet containing the defines. The result is written to |
| 38 target_dir/SkUserConfig.h |
| 39 |
| 40 Args: |
| 41 original_sk_user_config: Path to original SkUserConfig.h |
| 42 target_dir: Directory within which the modified SkUserConfig.h will be |
| 43 written. Its name will be the same basename as |
| 44 original_sk_user_config. If None, the new file will be written to the |
| 45 working directory. |
| 46 ordered_set: A vars_dict_lib.OrderedSet, containing a list of defines to |
| 47 be appended to SkUserConfig. |
| 48 |
| 49 Raises: |
| 50 AssertionError: If original_sk_user_config does not exist. |
| 51 """ |
| 52 |
| 53 assert os.path.exists(original_sk_user_config) |
| 54 |
| 55 dst_filename = os.path.basename(original_sk_user_config) |
| 56 if target_dir: |
| 57 dst_filename = os.path.join(target_dir, dst_filename) |
| 58 |
| 59 with open(dst_filename, 'w') as dst: |
| 60 dst.write(AUTOGEN_WARNING) |
| 61 |
| 62 # Copy the original exactly. This is merely for reference. Many of the |
| 63 # defines written to the file below, either manually or generated from the |
| 64 # gyp files, have explanations in the original SkUserConfig.h |
| 65 with open(original_sk_user_config, 'r') as original: |
| 66 for line in original: |
| 67 dst.write(line) |
| 68 |
| 69 # Now add the defines specific to Android. Write a custom build guard to |
| 70 # ensure they don't get defined more than once. |
| 71 dst.write('\n// Android defines:\n') |
| 72 dst.write('#ifndef ' + BUILD_GUARD + '\n') |
| 73 dst.write('#define ' + BUILD_GUARD + '\n') |
| 74 |
| 75 # Add conditional defines manually: |
| 76 |
| 77 # do this build check for other tools that still read this header |
| 78 dst.write('#ifdef ANDROID\n') |
| 79 dst.write('\t#include <utils/misc.h>\n') |
| 80 dst.write('#endif\n\n') |
| 81 |
| 82 dst.write('#if __BYTE_ORDER == __BIG_ENDIAN\n') |
| 83 dst.write('\t#define SK_CPU_BENDIAN\n') |
| 84 dst.write('\t#undef SK_CPU_LENDIAN\n') |
| 85 dst.write('#else\n') |
| 86 dst.write('\t#define SK_CPU_LENDIAN\n') |
| 87 dst.write('\t#undef SK_CPU_BENDIAN\n') |
| 88 dst.write('#endif\n\n') |
| 89 |
| 90 # Now add the defines from the gyp files. |
| 91 for item in ordered_set: |
| 92 # Although our defines may have '=' in them, when written to the header |
| 93 # there should be a space between the macro and what it replaces. |
| 94 dst.write('#define ' + item.replace('=', ' ') + '\n') |
| 95 |
| 96 dst.write('\n#endif // ' + BUILD_GUARD + '\n') |
OLD | NEW |