OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright 2014 Google Inc. | 3 # Copyright 2014 Google Inc. |
4 # | 4 # |
5 # Use of this source code is governed by a BSD-style license that can be | 5 # Use of this source code is governed by a BSD-style license that can be |
6 # found in the LICENSE file. | 6 # found in the LICENSE file. |
7 | 7 |
8 """Function for generating the SkUserConfig file, customized for Android.""" | 8 """Function for generating the SkUserConfig file, customized for Android.""" |
9 | 9 |
10 import os | 10 import os |
(...skipping 11 matching lines...) Expand all Loading... |
22 // | 22 // |
23 /////////////////////////////////////////////////////////////////////////////// | 23 /////////////////////////////////////////////////////////////////////////////// |
24 | 24 |
25 """ | 25 """ |
26 ) | 26 ) |
27 | 27 |
28 BUILD_GUARD = 'SkUserConfig_Android_DEFINED' | 28 BUILD_GUARD = 'SkUserConfig_Android_DEFINED' |
29 | 29 |
30 | 30 |
31 def generate_user_config(original_sk_user_config, require_sk_user_config, | 31 def generate_user_config(original_sk_user_config, require_sk_user_config, |
32 target_dir, ordered_set): | 32 target_dir, defines): |
33 """Generate the SkUserConfig file specific to the Android framework. | 33 """Generate the SkUserConfig file specific to the Android framework. |
34 | 34 |
35 Android needs its #defines in its skia/include/core directory, so that other | 35 Android needs its #defines in its skia/include/core directory, so that other |
36 libraries which use Skia's headers get the right definitions. This function | 36 libraries which use Skia's headers get the right definitions. This function |
37 takes the existing sample version of SkUserConfig, checked into Skia, and | 37 takes the existing sample version of SkUserConfig, checked into Skia, and |
38 appends the defines from ordered_set, which is expected to be a | 38 appends the defines from ordered_set, which is expected to be a |
39 vars_dict_lib.OrderedSet containing the defines. The result is written to | 39 vars_dict_lib.OrderedSet containing the defines. The result is written to |
40 target_dir/SkUserConfig.h | 40 target_dir/SkUserConfig.h |
41 | 41 |
42 Args: | 42 Args: |
43 original_sk_user_config: Path to original SkUserConfig.h | 43 original_sk_user_config: Path to original SkUserConfig.h |
44 require_sk_user_config: If True, raise an AssertionError if | 44 require_sk_user_config: If True, raise an AssertionError if |
45 SkUserConfig.h does not exist. Either way, if it does exist, copy it | 45 SkUserConfig.h does not exist. Either way, if it does exist, copy it |
46 into the new file. | 46 into the new file. |
47 target_dir: Directory within which the modified SkUserConfig.h will be | 47 target_dir: Directory within which the modified SkUserConfig.h will be |
48 written. Its name will be the same basename as | 48 written. Its name will be the same basename as |
49 original_sk_user_config. If None, the new file will be written to the | 49 original_sk_user_config. If None, the new file will be written to the |
50 working directory. | 50 working directory. |
51 ordered_set: A vars_dict_lib.OrderedSet, containing a list of defines to | 51 defines: Iterable of defines to be appended to SkUserConfig. |
52 be appended to SkUserConfig. | |
53 | 52 |
54 Raises: | 53 Raises: |
55 AssertionError: If original_sk_user_config does not exist. | 54 AssertionError: If original_sk_user_config does not exist. |
56 """ | 55 """ |
57 | 56 |
58 sk_user_config_exists = os.path.exists(original_sk_user_config) | 57 sk_user_config_exists = os.path.exists(original_sk_user_config) |
59 if require_sk_user_config: | 58 if require_sk_user_config: |
60 assert sk_user_config_exists | 59 assert sk_user_config_exists |
61 | 60 |
62 dst_filename = os.path.basename(original_sk_user_config) | 61 dst_filename = os.path.basename(original_sk_user_config) |
(...skipping 25 matching lines...) Expand all Loading... |
88 | 87 |
89 dst.write('#if __BYTE_ORDER == __BIG_ENDIAN\n') | 88 dst.write('#if __BYTE_ORDER == __BIG_ENDIAN\n') |
90 dst.write(' #define SK_CPU_BENDIAN\n') | 89 dst.write(' #define SK_CPU_BENDIAN\n') |
91 dst.write(' #undef SK_CPU_LENDIAN\n') | 90 dst.write(' #undef SK_CPU_LENDIAN\n') |
92 dst.write('#else\n') | 91 dst.write('#else\n') |
93 dst.write(' #define SK_CPU_LENDIAN\n') | 92 dst.write(' #define SK_CPU_LENDIAN\n') |
94 dst.write(' #undef SK_CPU_BENDIAN\n') | 93 dst.write(' #undef SK_CPU_BENDIAN\n') |
95 dst.write('#endif\n\n') | 94 dst.write('#endif\n\n') |
96 | 95 |
97 # Now add the defines from the gyp files. | 96 # Now add the defines from the gyp files. |
98 for item in ordered_set: | 97 for item in sorted(defines): |
99 # Although our defines may have '=' in them, when written to the header | 98 # Although our defines may have '=' in them, when written to the header |
100 # there should be a space between the macro and what it replaces. | 99 # there should be a space between the macro and what it replaces. |
101 dst.write('#define ' + item.replace('=', ' ') + '\n') | 100 dst.write('#define ' + item.replace('=', ' ') + '\n') |
102 | 101 |
103 dst.write('\n#endif // ' + BUILD_GUARD + '\n') | 102 dst.write('\n#endif // ' + BUILD_GUARD + '\n') |
OLD | NEW |