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

Side by Side Diff: platform_tools/android/bin/gyp_to_android.py

Issue 140503007: Scripts to generate Android.mk for framework Skia. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Respond to Elliot's comments in patch set 20. Created 6 years, 10 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
OLDNEW
(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 generate_var_dict(target_dir, target_file, skia_arch_type, have_neon):
48 """
49 Create a VarsDict for a particular arch type. Each paramater is passed
50 directly to android_framework_gyp.main().
51 @param target_dir Directory containing gyp files.
52 @param target_file Target gyp file.
53 @param skia_arch_type Target architecture.
54 @param have_neon Whether the target should build for neon.
55 @return a VarsDict containing the variable definitions determined by gyp.
56 """
57 result_file = android_framework_gyp.main(target_dir, target_file,
58 skia_arch_type, have_neon)
59 var_dict = vars_dict_lib.VarsDict()
60 gypd_parser.parse_gypd(var_dict, result_file)
61 clean_gypd_files(target_dir)
62 print '.',
63 return var_dict
64
65 def main(target_dir=None):
66 """
67 Read gyp files and create Android.mk for the Android framework's
68 external/skia.
69 @param target_dir Directory in which to place 'Android.mk'. If None, the file
70 will be placed in skia's root directory.
71 """
72 # Create a temporary folder to hold gyp and gypd files. Create it in SKIA_DIR
73 # so that it is a sibling of gyp/, so the relationships between gyp files and
74 # other files (e.g. platform_tools/android/gyp/dependencies.gypi, referenced
75 # by android_deps.gyp as a relative path) is unchanged.
76 # Use mkdtemp to find an unused folder name, but then delete it so copytree
77 # can be called with a non-existent directory.
78 tmp_folder = tempfile.mkdtemp(dir=SKIA_DIR)
79 os.rmdir(tmp_folder)
80 shutil.copytree(os.path.join(SKIA_DIR, GYP_FOLDER), tmp_folder)
81
82 try:
83 main_gyp_file = 'android_framework_lib.gyp'
84
85 print 'Creating Android.mk',
86
87 # Generate a separate VarsDict for each architecture type. For each
88 # archtype:
89 # 1. call android_framework_gyp.main() to generate gypd files
90 # 2. call parse_gypd to read those gypd files into the VarsDict
91 # 3. delete the gypd files
92 #
93 # Once we have the VarsDict for each architecture type, we combine them all
94 # into a single Android.mk file, which can build targets of any
95 # architecture type.
96
97 # The default uses a non-existant archtype, to find all the general
98 # variable definitions.
99 default_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'other',
100 False)
101 arm_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'arm', False)
102 arm_neon_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'arm',
103 True)
104 if variables.INCLUDE_X86_OPTS:
105 x86_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'x86', False)
106 else:
107 x86_var_dict = None
108
109 # Compute the intersection of all targets. All the files in the intersection
110 # should be part of the makefile always. Each dict will now contain trimmed
111 # lists containing only variable definitions specific to that configuration.
112 var_dict_list = [default_var_dict, arm_var_dict, arm_neon_var_dict]
113 if variables.INCLUDE_X86_OPTS:
114 var_dict_list.append(x86_var_dict)
115 common = vars_dict_lib.intersect(var_dict_list)
116
117 # Further trim arm_neon_var_dict with arm_var_dict. After this call,
118 # arm_var_dict (which will now be the intersection) includes all definitions
119 # used by both arm and arm + neon, and arm_neon_var_dict will only contain
120 # those specific to arm + neon.
121 arm_var_dict = vars_dict_lib.intersect([arm_var_dict, arm_neon_var_dict])
122
123 makefile_writer.write_android_mk(target_dir=target_dir,
124 common=common,
125 arm=arm_var_dict,
126 arm_neon=arm_neon_var_dict,
127 x86=x86_var_dict,
128 default=default_var_dict)
129
130 finally:
131 shutil.rmtree(tmp_folder)
132
133 if __name__ == '__main__':
134 main()
OLDNEW
« no previous file with comments | « platform_tools/android/bin/android_framework_gyp.py ('k') | platform_tools/android/gyp_gen/gypd_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698