Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: platform_tools/android/gyp_gen/generate_user_config.py

Issue 242203008: Allow running gyp_to_android without SkUserConfig. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « platform_tools/android/bin/gyp_to_android.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11
12 12
13 AUTOGEN_WARNING = ( 13 AUTOGEN_WARNING = (
14 """ 14 """
15 /////////////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////////////
16 // 16 //
17 // THIS FILE IS AUTOGENERATED BY GYP_TO_ANDROID.PY. DO NOT EDIT. 17 // THIS FILE IS AUTOGENERATED BY GYP_TO_ANDROID.PY. DO NOT EDIT.
18 // 18 //
19 // This file contains Skia's upstream include/config/SkUserConfig.h as a 19 // This file contains Skia's upstream include/config/SkUserConfig.h as a
20 // reference, followed by the actual defines set for Android. 20 // reference, followed by the actual defines set for Android.
21 // 21 //
22 /////////////////////////////////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////////////////////////////////
23 23
24 """ 24 """
25 ) 25 )
26 26
27 BUILD_GUARD = 'SkUserConfig_Android_DEFINED' 27 BUILD_GUARD = 'SkUserConfig_Android_DEFINED'
28 28
29 29
30 def generate_user_config(original_sk_user_config, target_dir, ordered_set): 30 def generate_user_config(original_sk_user_config, require_sk_user_config,
31 target_dir, ordered_set):
31 """Generate the SkUserConfig file specific to the Android framework. 32 """Generate the SkUserConfig file specific to the Android framework.
32 33
33 Android needs its #defines in its skia/include/core directory, so that other 34 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 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 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 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 vars_dict_lib.OrderedSet containing the defines. The result is written to
38 target_dir/SkUserConfig.h 39 target_dir/SkUserConfig.h
39 40
40 Args: 41 Args:
41 original_sk_user_config: Path to original SkUserConfig.h 42 original_sk_user_config: Path to original SkUserConfig.h
43 require_sk_user_config: If True, raise an AssertionError if
44 SkUserConfig.h does not exist. Either way, if it does exist, copy it
45 into the new file.
42 target_dir: Directory within which the modified SkUserConfig.h will be 46 target_dir: Directory within which the modified SkUserConfig.h will be
43 written. Its name will be the same basename as 47 written. Its name will be the same basename as
44 original_sk_user_config. If None, the new file will be written to the 48 original_sk_user_config. If None, the new file will be written to the
45 working directory. 49 working directory.
46 ordered_set: A vars_dict_lib.OrderedSet, containing a list of defines to 50 ordered_set: A vars_dict_lib.OrderedSet, containing a list of defines to
47 be appended to SkUserConfig. 51 be appended to SkUserConfig.
48 52
49 Raises: 53 Raises:
50 AssertionError: If original_sk_user_config does not exist. 54 AssertionError: If original_sk_user_config does not exist.
51 """ 55 """
52 56
53 assert os.path.exists(original_sk_user_config) 57 sk_user_config_exists = os.path.exists(original_sk_user_config)
58 if require_sk_user_config:
59 assert sk_user_config_exists
54 60
55 dst_filename = os.path.basename(original_sk_user_config) 61 dst_filename = os.path.basename(original_sk_user_config)
56 if target_dir: 62 if target_dir:
57 dst_filename = os.path.join(target_dir, dst_filename) 63 dst_filename = os.path.join(target_dir, dst_filename)
58 64
59 with open(dst_filename, 'w') as dst: 65 with open(dst_filename, 'w') as dst:
60 dst.write(AUTOGEN_WARNING) 66 dst.write(AUTOGEN_WARNING)
61 67
62 # Copy the original exactly. This is merely for reference. Many of the 68 # 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 69 # defines written to the file below, either manually or generated from the
64 # gyp files, have explanations in the original SkUserConfig.h 70 # gyp files, have explanations in the original SkUserConfig.h
65 with open(original_sk_user_config, 'r') as original: 71 if sk_user_config_exists:
66 for line in original: 72 with open(original_sk_user_config, 'r') as original:
hal.canary 2014/04/18 20:10:04 Possibly faster (as it doesn't care about lines en
scroggo 2014/04/18 22:24:16 Done.
67 dst.write(line) 73 for line in original:
74 dst.write(line)
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')
OLDNEW
« no previous file with comments | « platform_tools/android/bin/gyp_to_android.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698