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 """ | 8 """ |
9 Script for generating the Android framework's version of Skia from gyp | 9 Script for generating the Android framework's version of Skia from gyp |
10 files. | 10 files. |
11 """ | 11 """ |
12 | 12 |
13 import android_framework_gyp | |
14 import os | 13 import os |
15 import shutil | 14 import shutil |
16 import sys | 15 import sys |
17 import tempfile | 16 import tempfile |
18 | 17 |
19 # Find the top of trunk | 18 # Find the top of trunk |
20 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) | 19 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) |
21 SKIA_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, | 20 SKIA_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, |
22 os.pardir)) | 21 os.pardir)) |
23 | 22 |
24 # Find the directory with our helper files, and add it to the path. | 23 # Find the directory with our helper files, and add it to the path. |
25 GYP_GEN_DIR = os.path.join(SKIA_DIR, 'platform_tools', 'android', 'gyp_gen') | 24 GYP_GEN_DIR = os.path.join(SKIA_DIR, 'platform_tools', 'android', 'gyp_gen') |
26 sys.path.append(GYP_GEN_DIR) | 25 sys.path.append(GYP_GEN_DIR) |
27 | 26 |
| 27 import android_framework_gyp |
28 import gypd_parser | 28 import gypd_parser |
29 import generate_user_config | 29 import generate_user_config |
30 import makefile_writer | 30 import makefile_writer |
| 31 import tool_makefile_writer |
31 import vars_dict_lib | 32 import vars_dict_lib |
32 | 33 |
33 # Folder containing all gyp files and generated gypd files. | 34 # Folder containing all gyp files and generated gypd files. |
34 GYP_FOLDER = 'gyp' | 35 GYP_FOLDER = 'gyp' |
35 | 36 |
36 # TODO(scroggo): Update the docstrings to match the style guide: | |
37 # http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Comments | |
38 def clean_gypd_files(folder): | |
39 """ | |
40 Remove the gypd files generated by android_framework_gyp.main(). | |
41 @param folder Folder in which to delete all files ending with 'gypd'. | |
42 """ | |
43 assert os.path.isdir(folder) | |
44 files = os.listdir(folder) | |
45 for f in files: | |
46 if f.endswith('gypd'): | |
47 os.remove(os.path.join(folder, f)) | |
48 | 37 |
49 def generate_var_dict(target_dir, target_file, skia_arch_type, have_neon): | 38 def generate_var_dict(target_dir, target_file, skia_arch_type, have_neon): |
50 """ | 39 """Create a VarsDict for a particular arch type. |
51 Create a VarsDict for a particular arch type. Each paramater is passed | 40 |
52 directly to android_framework_gyp.main(). | 41 Each paramater is passed directly to android_framework_gyp.main(). |
53 @param target_dir Directory containing gyp files. | 42 |
54 @param target_file Target gyp file. | 43 Args: |
55 @param skia_arch_type Target architecture. | 44 target_dir: Directory containing gyp files. |
56 @param have_neon Whether the target should build for neon. | 45 target_file: Target gyp file. |
57 @return a VarsDict containing the variable definitions determined by gyp. | 46 skia_arch_type: Target architecture. |
| 47 have_neon: Whether the target should build for neon. |
| 48 Returns: |
| 49 A VarsDict containing the variable definitions determined by gyp. |
58 """ | 50 """ |
59 result_file = android_framework_gyp.main(target_dir, target_file, | 51 result_file = android_framework_gyp.main(target_dir, target_file, |
60 skia_arch_type, have_neon) | 52 skia_arch_type, have_neon) |
61 var_dict = vars_dict_lib.VarsDict() | 53 var_dict = vars_dict_lib.VarsDict() |
62 gypd_parser.parse_gypd(var_dict, result_file) | 54 gypd_parser.parse_gypd(var_dict, result_file, '.') |
63 clean_gypd_files(target_dir) | 55 android_framework_gyp.clean_gypd_files(target_dir) |
64 print '.', | 56 print '.', |
65 return var_dict | 57 return var_dict |
66 | 58 |
67 def main(target_dir=None, require_sk_user_config=False): | 59 def main(target_dir=None, require_sk_user_config=False): |
68 """ | 60 """Create Android.mk for the Android framework's external/skia. |
69 Read gyp files and create Android.mk for the Android framework's | 61 |
70 external/skia. | 62 Builds Android.mk using Skia's gyp files. |
71 @param target_dir Directory in which to place 'Android.mk'. If None, the file | 63 |
72 will be placed in skia's root directory. | 64 Args: |
73 @param require_sk_user_config If True, raise an AssertionError if | 65 target_dir: Directory in which to place 'Android.mk'. If None, the file |
74 SkUserConfig.h does not exist. | 66 will be placed in skia's root directory. |
| 67 require_sk_user_config: If True, raise an AssertionError if |
| 68 SkUserConfig.h does not exist. |
75 """ | 69 """ |
76 # Create a temporary folder to hold gyp and gypd files. Create it in SKIA_DIR | 70 # Create a temporary folder to hold gyp and gypd files. Create it in SKIA_DIR |
77 # so that it is a sibling of gyp/, so the relationships between gyp files and | 71 # so that it is a sibling of gyp/, so the relationships between gyp files and |
78 # other files (e.g. platform_tools/android/gyp/dependencies.gypi, referenced | 72 # other files (e.g. platform_tools/android/gyp/dependencies.gypi, referenced |
79 # by android_deps.gyp as a relative path) is unchanged. | 73 # by android_deps.gyp as a relative path) is unchanged. |
80 # Use mkdtemp to find an unused folder name, but then delete it so copytree | 74 # Use mkdtemp to find an unused folder name, but then delete it so copytree |
81 # can be called with a non-existent directory. | 75 # can be called with a non-existent directory. |
82 tmp_folder = tempfile.mkdtemp(dir=SKIA_DIR) | 76 tmp_folder = tempfile.mkdtemp(dir=SKIA_DIR) |
83 os.rmdir(tmp_folder) | 77 os.rmdir(tmp_folder) |
84 shutil.copytree(os.path.join(SKIA_DIR, GYP_FOLDER), tmp_folder) | 78 shutil.copytree(os.path.join(SKIA_DIR, GYP_FOLDER), tmp_folder) |
(...skipping 27 matching lines...) Expand all Loading... |
112 arm64_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'arm64', | 106 arm64_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'arm64', |
113 False) | 107 False) |
114 | 108 |
115 # Compute the intersection of all targets. All the files in the intersection | 109 # Compute the intersection of all targets. All the files in the intersection |
116 # should be part of the makefile always. Each dict will now contain trimmed | 110 # should be part of the makefile always. Each dict will now contain trimmed |
117 # lists containing only variable definitions specific to that configuration. | 111 # lists containing only variable definitions specific to that configuration. |
118 var_dict_list = [default_var_dict, arm_var_dict, arm_neon_var_dict, | 112 var_dict_list = [default_var_dict, arm_var_dict, arm_neon_var_dict, |
119 x86_var_dict, mips_var_dict, arm64_var_dict] | 113 x86_var_dict, mips_var_dict, arm64_var_dict] |
120 common = vars_dict_lib.intersect(var_dict_list) | 114 common = vars_dict_lib.intersect(var_dict_list) |
121 | 115 |
| 116 common.LOCAL_MODULE.add('libskia') |
| 117 |
122 # Create SkUserConfig | 118 # Create SkUserConfig |
123 user_config = os.path.join(SKIA_DIR, 'include', 'config', 'SkUserConfig.h') | 119 user_config = os.path.join(SKIA_DIR, 'include', 'config', 'SkUserConfig.h') |
124 if target_dir: | 120 if target_dir: |
125 dst_dir = target_dir | 121 dst_dir = target_dir |
126 else: | 122 else: |
127 dst_dir = os.path.join(SKIA_DIR, 'include', 'core') | 123 dst_dir = os.path.join(SKIA_DIR, 'include', 'core') |
128 | 124 |
129 generate_user_config.generate_user_config( | 125 generate_user_config.generate_user_config( |
130 original_sk_user_config=user_config, | 126 original_sk_user_config=user_config, |
131 require_sk_user_config=require_sk_user_config, target_dir=dst_dir, | 127 require_sk_user_config=require_sk_user_config, target_dir=dst_dir, |
132 ordered_set=common.DEFINES) | 128 ordered_set=common.DEFINES) |
133 | 129 |
134 # Now that the defines have been written to SkUserConfig, they are not | 130 tool_makefile_writer.generate_tool(gyp_dir=tmp_folder, |
135 # needed in Android.mk. | 131 target_file='tests.gyp', |
| 132 skia_trunk=target_dir, |
| 133 dest_dir='tests', |
| 134 skia_lib_var_dict=common, |
| 135 local_module_name='skia_test', |
| 136 local_module_tags=['eng', 'tests']) |
| 137 |
| 138 # TODO (scroggo): Generate bench/Android.mk. See skbug.com/2448 |
| 139 #tool_makefile_writer.generate_tool(gyp_dir=tmp_folder, |
| 140 # target_file='bench.gyp', |
| 141 # skia_trunk=target_dir, |
| 142 # dest_dir='bench', |
| 143 # skia_lib_var_dict=common, |
| 144 # local_module_name='skia_bench', |
| 145 # local_module_tags=['tests']) |
| 146 |
| 147 # Now that the defines have been written to SkUserConfig and they've been |
| 148 # used to skip adding them to the tools makefiles, they are not needed in |
| 149 # Android.mk. Reset DEFINES. |
136 common.DEFINES.reset() | 150 common.DEFINES.reset() |
137 | 151 |
138 # Further trim arm_neon_var_dict with arm_var_dict. After this call, | 152 # Further trim arm_neon_var_dict with arm_var_dict. After this call, |
139 # arm_var_dict (which will now be the intersection) includes all definitions | 153 # arm_var_dict (which will now be the intersection) includes all definitions |
140 # used by both arm and arm + neon, and arm_neon_var_dict will only contain | 154 # used by both arm and arm + neon, and arm_neon_var_dict will only contain |
141 # those specific to arm + neon. | 155 # those specific to arm + neon. |
142 arm_var_dict = vars_dict_lib.intersect([arm_var_dict, arm_neon_var_dict]) | 156 arm_var_dict = vars_dict_lib.intersect([arm_var_dict, arm_neon_var_dict]) |
143 | 157 |
144 # Now create a list of VarsDictData holding everything but common. | 158 # Now create a list of VarsDictData holding everything but common. |
145 deviations_from_common = [] | 159 deviations_from_common = [] |
(...skipping 14 matching lines...) Expand all Loading... |
160 'arm64')) | 174 'arm64')) |
161 | 175 |
162 makefile_writer.write_android_mk(target_dir=target_dir, | 176 makefile_writer.write_android_mk(target_dir=target_dir, |
163 common=common, deviations_from_common=deviations_from_common) | 177 common=common, deviations_from_common=deviations_from_common) |
164 | 178 |
165 finally: | 179 finally: |
166 shutil.rmtree(tmp_folder) | 180 shutil.rmtree(tmp_folder) |
167 | 181 |
168 if __name__ == '__main__': | 182 if __name__ == '__main__': |
169 main() | 183 main() |
OLD | NEW |