Chromium Code Reviews| 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 """ | |
| 9 Script for generating the Android framework's version of Skia from gyp | |
| 10 files. | |
| 11 """ | |
| 12 | |
| 13 import android_framework_gyp | |
| 14 import os | |
| 15 import shutil | |
| 16 import sys | |
| 17 import tempfile | |
| 18 | |
| 19 # Find the top of trunk | |
| 20 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) | |
| 21 SKIA_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, | |
| 22 os.pardir)) | |
| 23 | |
| 24 # 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') | |
| 26 sys.path.append(GYP_GEN_DIR) | |
| 27 | |
| 28 import gypd_parser | |
| 29 import makefile_writer | |
| 30 import variables | |
| 31 import vars_dict_lib | |
| 32 | |
| 33 # Folder containing all gyp files and generated gypd files. | |
| 34 GYP_FOLDER = 'gyp' | |
| 35 | |
| 36 def clean_gypd_files(folder): | |
| 37 """ | |
| 38 Remove the gypd files generated by android_framework_gyp.main(). | |
| 39 @param folder Folder in which to delete all files ending with 'gypd'. | |
| 40 """ | |
| 41 assert os.path.isdir(folder) | |
| 42 files = os.listdir(folder) | |
| 43 for f in files: | |
| 44 if f.endswith('gypd'): | |
| 45 os.remove(os.path.join(folder, f)) | |
| 46 | |
| 47 def main(target_dir=None): | |
| 48 """ | |
| 49 Read gyp files and create Android.mk for the Android framework's | |
| 50 external/skia. | |
| 51 @param target_dir Directory in which to place 'Android.mk'. If None, the file | |
| 52 will be placed in skia's root directory. | |
| 53 """ | |
| 54 # Create a temporary folder to hold gyp and gypd files. Create it in SKIA_DIR | |
| 55 # so that it is a sibling of gyp/, so the relationships between gyp files and | |
| 56 # other files (e.g. platform_tools/android/gyp/dependencies.gypi, referenced | |
| 57 # by android_deps.gyp as a relative path) is unchanged. | |
| 58 # Use mkdtemp to find an unused folder name, but then delete it so copytree | |
| 59 # can be called with a non-existent directory. | |
| 60 tmp_folder = tempfile.mkdtemp(dir=SKIA_DIR) | |
| 61 os.rmdir(tmp_folder) | |
| 62 shutil.copytree(os.path.join(SKIA_DIR, GYP_FOLDER), tmp_folder) | |
| 63 | |
| 64 try: | |
| 65 main_gyp_file = 'android_framework_lib.gyp' | |
| 66 main_gypd_file = os.path.join(tmp_folder, main_gyp_file + 'd') | |
| 67 | |
| 68 print 'Creating Android.mk', | |
| 69 | |
| 70 # Call the script to generate gypd files, first using a non-existant | |
|
epoger
2014/02/03 17:26:32
If the following writeup is accurate, I think it m
scroggo
2014/02/03 23:22:31
Done.
| |
| 71 # archtype. | |
| 72 android_framework_gyp.main(tmp_folder, main_gyp_file, 'other', False) | |
|
epoger
2014/02/03 17:26:32
If my writeup above is true, maybe you could reduc
scroggo
2014/02/03 23:22:31
Done.
| |
| 73 # And store its variables in the default dict | |
| 74 default_var_dict = vars_dict_lib.VarsDict() | |
| 75 gypd_parser.parse_gypd(default_var_dict, main_gypd_file) | |
| 76 clean_gypd_files(tmp_folder) | |
| 77 | |
| 78 print '.', | |
| 79 | |
| 80 # Now do the same for Arm. arm_var_dict will contain all the variable | |
| 81 # definitions needed to build with arm (meaning that it will share most | |
| 82 # with default_var_dict). | |
| 83 android_framework_gyp.main(tmp_folder, main_gyp_file, 'arm', False) | |
| 84 arm_var_dict = vars_dict_lib.VarsDict() | |
| 85 gypd_parser.parse_gypd(arm_var_dict, main_gypd_file) | |
| 86 clean_gypd_files(tmp_folder) | |
| 87 | |
| 88 print '.', | |
| 89 | |
| 90 # Now do the same for Arm/Neon. | |
| 91 android_framework_gyp.main(tmp_folder, main_gyp_file, 'arm', True) | |
| 92 arm_neon_var_dict = vars_dict_lib.VarsDict() | |
| 93 gypd_parser.parse_gypd(arm_neon_var_dict, main_gypd_file) | |
| 94 clean_gypd_files(tmp_folder) | |
| 95 | |
| 96 print '.' | |
| 97 | |
| 98 # Now do the same for x86. | |
| 99 x86_var_dict = vars_dict_lib.VarsDict() | |
| 100 if variables.INCLUDE_X86_OPTS: | |
| 101 android_framework_gyp.main(tmp_folder, main_gyp_file, 'x86', False) | |
| 102 gypd_parser.parse_gypd(x86_var_dict, main_gypd_file) | |
| 103 clean_gypd_files(tmp_folder) | |
| 104 | |
| 105 # Compute the intersection of all targets. All the files in the intersection | |
| 106 # should be part of the makefile always. Each dict will now contain trimmed | |
| 107 # lists containing only variable definitions specific to that configuration. | |
| 108 var_dict_list = [default_var_dict, arm_var_dict, arm_neon_var_dict] | |
| 109 if variables.INCLUDE_X86_OPTS: | |
| 110 var_dict_list.append(x86_var_dict) | |
| 111 common = vars_dict_lib.intersect(var_dict_list) | |
| 112 | |
| 113 # Further trim arm_neon_var_dict with arm_var_dict. After this call, | |
| 114 # arm_var_dict (which will now be the intersection) includes all definitions | |
| 115 # used by both arm and arm + neon, and arm_neon_var_dict will only contain | |
| 116 # those specific to arm + neon. | |
| 117 arm_var_dict = vars_dict_lib.intersect([arm_var_dict, arm_neon_var_dict]) | |
|
epoger
2014/02/03 17:26:32
So, after this call, does arm_neon_var_dict someho
scroggo
2014/02/03 23:22:31
Leaving as is, and adding a TODO in makefile_write
| |
| 118 | |
| 119 makefile_writer.write_android_mk(target_dir, common, arm_var_dict, | |
|
epoger
2014/02/03 17:26:32
please use named parameters
makefile_writer.write
scroggo
2014/02/03 23:22:31
Done.
| |
| 120 arm_neon_var_dict, x86_var_dict, | |
| 121 default_var_dict) | |
| 122 | |
| 123 finally: | |
| 124 shutil.rmtree(tmp_folder) | |
| 125 | |
| 126 if __name__ == '__main__': | |
| 127 main() | |
| OLD | NEW |