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