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

Side by Side Diff: build/config/android/internal_rules.gni

Issue 269943005: Add android_library template (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « build/config/android/config.gni ('k') | build/config/android/rules.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import("//build/config/android/config.gni")
6
7
8 # Write the target's .build_config file. This is a json file that contains a
9 # dictionary of information about how to build this target (things that
10 # require knowledge about this target's dependencies and cannot be calculated
11 # at gn-time). There is a special syntax to add a value in that dictionary to
12 # an action/action_foreachs args:
13 # --python-arg=@($rebased_build_config_path:key0:key1)
14 # At runtime, such an arg will be replaced by the value in the build_config.
15 # See build/android/gyp/write_build_config.py and
16 # build/android/gyp/util/build_utils.py:ExpandFileArgs
17 template("write_build_config") {
18 assert(defined(invoker.type))
19 assert(defined(invoker.base_path))
20
21 base_path = invoker.base_path
22 type = invoker.type
23 build_config = base_path + ".build_config"
24
25 assert(type == "android_library" || type == "android_binary")
26
27 action(target_name) {
28 script = "//build/android/gyp/write_build_config.py"
29 depfile = "$target_gen_dir/$target_name.d"
30
31 deps = []
32 if (defined(invoker.deps)) {
33 deps += invoker.deps
34 }
35
36 outputs = [
37 depfile,
38 build_config
39 ]
40
41 possible_deps_configs = []
42 foreach(d, deps) {
43 dep_gen_dir = get_label_info(d, "target_gen_dir")
44 dep_name = get_label_info(d, "name")
45 possible_deps_configs += [ "$dep_gen_dir/$dep_name.build_config" ]
46 }
47 rebase_possible_deps_configs = rebase_path(possible_deps_configs)
48 args = [
49 "--type", type,
50 "--depfile", rebase_path(depfile, root_build_dir),
51 "--possible-deps-configs=$rebase_possible_deps_configs",
52 "--build-config", rebase_path(build_config, root_build_dir),
53 ]
54
55 if (type == "android_library") {
56 jar_path = base_path + ".jar"
57 args += [
58 "--jar-path", rebase_path(jar_path, root_build_dir),
59 ]
60 }
61 }
62 }
1 63
2 # Creates a zip archive of the inputs. 64 # Creates a zip archive of the inputs.
3 # If base_dir is provided, the archive paths will be relative to it. 65 # If base_dir is provided, the archive paths will be relative to it.
4 template("zip") { 66 template("zip") {
5 assert(defined(invoker.inputs)) 67 assert(defined(invoker.inputs))
6 assert(defined(invoker.output)) 68 assert(defined(invoker.output))
7 69
8 rebase_inputs = rebase_path(invoker.inputs) 70 rebase_inputs = rebase_path(invoker.inputs, root_build_dir)
9 rebase_output = rebase_path(invoker.output) 71 rebase_output = rebase_path(invoker.output, root_build_dir)
10 action(target_name) { 72 action(target_name) {
11 script = "//build/android/gn/zip.py" 73 script = "//build/android/gn/zip.py"
12 depfile = "$target_gen_dir/$target_name.d" 74 depfile = "$target_gen_dir/$target_name.d"
13 source_prereqs = invoker.inputs 75 source_prereqs = invoker.inputs
14 outputs = [depfile, invoker.output] 76 outputs = [
77 depfile,
78 invoker.output
79 ]
15 args = [ 80 args = [
16 "--depfile", rebase_path(depfile, root_build_dir), 81 "--depfile", rebase_path(depfile, root_build_dir),
17 "--inputs=$rebase_inputs", 82 "--inputs=$rebase_inputs",
18 "--output=$rebase_output", 83 "--output=$rebase_output",
19 ] 84 ]
20 if (defined(invoker.base_dir)) { 85 if (defined(invoker.base_dir)) {
21 args += [ 86 args += [
22 "--base-dir", rebase_path(invoker.base_dir) 87 "--base-dir", rebase_path(invoker.base_dir, root_build_dir)
23 ] 88 ]
24 } 89 }
25 } 90 }
26 } 91 }
27 92
93 # Compiles and jars a set of java_files.
94 #
95 # Outputs:
96 # $jar_path.jar
97 # $jar_path.jar.TOC
98 #
99 # Variables
100 # java_files: List of .java files to compile.
101 # java_deps: List of java dependencies. These should all have a .jar output
102 # at "${target_gen_dir}/${target_name}.jar.
103 # chromium_code: If 1, enable extra warnings.
104 # srcjar_deps: List of srcjar dependencies. The .java files contained in the
105 # dependencies srcjar outputs will be compiled and added to the output jar.
106 # jar_path: Use this to explicitly set the output jar path. Defaults to
107 # "${target_gen_dir}/${target_name}.jar.
108 template("java_library") {
109 assert(defined(invoker.java_files))
110 assert(defined(invoker.build_config))
111 assert(defined(invoker.jar_path))
112
113 java_files = invoker.java_files
114 jar_path = invoker.jar_path
115 jar_toc_path = jar_path + ".TOC"
116
117 build_config = invoker.build_config
118
119 jar_excluded_patterns = []
120 if (defined(invoker.jar_excluded_patterns)) {
121 jar_excluded_patterns += invoker.jar_excluded_patterns
122 }
123
124 chromium_code = false
125 if (defined(invoker.chromium_code)) {
126 chromium_code = chromium_code || invoker.chromium_code
127 }
128
129 srcjar_deps = []
130 if (defined(invoker.srcjar_deps)) {
131 srcjar_deps += invoker.srcjar_deps
132 }
133
134 java_srcjars = []
135 foreach(dep, srcjar_deps) {
136 dep_gen_dir = get_label_info(dep, "target_gen_dir")
137 dep_name = get_label_info(dep, "name")
138 java_srcjars += [ "$dep_gen_dir/$dep_name.srcjar" ]
139 }
140 # Mark srcjar_deps as used.
141 assert(srcjar_deps == [] || srcjar_deps != [])
142
143 rebase_jar_path = rebase_path(jar_path, root_build_dir)
144
145 system_jars = [ "${android_sdk}/android.jar" ]
146 action("${target_name}__javac") {
147 script = "//build/android/gyp/javac.py"
148 depfile = "$target_gen_dir/$target_name.d"
149 outputs = [
150 depfile,
151 jar_path,
152 jar_path + ".md5.stamp"
153 ]
154 sources = java_files + java_srcjars
155 source_prereqs = system_jars + [ build_config ]
156
157 rebase_system_jars = rebase_path(system_jars, root_build_dir)
158 rebase_java_srcjars = rebase_path(java_srcjars, root_build_dir)
159 rebase_build_config = rebase_path(build_config, root_build_dir)
160 rebase_depfile = rebase_path(depfile, root_build_dir)
161 args = [
162 "--depfile=$rebase_depfile",
163 "--classpath=$rebase_system_jars",
164 "--classpath=@($rebase_build_config:javac:classpath)",
165 "--jar-path=$rebase_jar_path",
166 "--java-srcjars=$rebase_java_srcjars",
167 "--jar-excluded-classes=$jar_excluded_patterns",
168 ]
169 if (chromium_code) {
170 args += [ "--chromium-code" ]
171 }
172
173 args += rebase_path(java_files, root_build_dir)
174 }
175
176 # TODO(cjhopman): proguard
177
178 rebase_jar_toc_path = rebase_path(jar_toc_path, root_build_dir)
179 action("${target_name}__jar_toc") {
180 script = "//build/android/gyp/jar_toc.py"
181 depfile = "$target_gen_dir/$target_name.d"
182 outputs = [
183 depfile,
184 jar_toc_path,
185 jar_toc_path + ".md5.stamp"
186 ]
187 source_prereqs = [ jar_path ]
188 args = [
189 "--depfile", rebase_path(depfile, root_build_dir),
190 "--jar-path=${rebase_jar_path}",
191 "--toc-path=${rebase_jar_toc_path}",
192 ]
193 }
194
195 group(target_name) {
196 deps = [
197 ":${target_name}__javac",
198 ":${target_name}__jar_toc",
199 ]
200 }
201 }
202
203 # This adds Android-specific parts to the java_library template.
204 #
205 # Runs Android lint against the compiled java files.
206 # Dexes the output jar for inclusion in an APK.
207 template("android_java_library") {
208 assert(defined(invoker.java_files))
209
210 assert(defined(invoker.build_config))
211 assert(defined(invoker.jar_path))
212
213 java_library("${target_name}__java_library") {
214 if (defined(invoker.jar_excluded_patterns)) {
215 jar_excluded_patterns = invoker.jar_excluded_patterns
216 }
217 build_config = invoker.build_config
218 java_files = invoker.java_files
219 jar_path = invoker.jar_path
220
221 if (defined(invoker.srcjar_deps)) {
222 srcjar_deps = invoker.srcjar_deps
223 }
224 }
225
226 # TODO(cjhopman): lint
227 # TODO(cjhopman): dex
228
229 group(target_name) {
230 deps = [
231 ":${target_name}__java_library"
232 ]
233 }
234 }
OLDNEW
« no previous file with comments | « build/config/android/config.gni ('k') | build/config/android/rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698