blob: cc2043d0a762463c4e0a46d4215bc56036fe77ba [file] [log] [blame]
Nan Zhang581fd212018-01-10 16:06:12 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18 "android/soong/android"
19 "android/soong/java/config"
20 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080021 "path/filepath"
Nan Zhang46130972018-06-04 11:28:01 -070022 "runtime"
Nan Zhang581fd212018-01-10 16:06:12 -080023 "strings"
24
25 "github.com/google/blueprint"
26)
27
28var (
29 javadoc = pctx.AndroidStaticRule("javadoc",
30 blueprint.RuleParams{
31 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Colin Cross436b7652018-03-15 16:24:10 -070032 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang40b41b42018-10-02 16:11:17 -070033 `${config.SoongJavacWrapper} ${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070034 `$opts $bootclasspathArgs $classpathArgs $sourcepathArgs ` +
Nan Zhang581fd212018-01-10 16:06:12 -080035 `-d $outDir -quiet && ` +
36 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
Nan Zhange2ba5d42018-07-11 15:16:55 -070037 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir $postDoclavaCmds`,
Nan Zhang581fd212018-01-10 16:06:12 -080038 CommandDeps: []string{
Colin Cross436b7652018-03-15 16:24:10 -070039 "${config.ZipSyncCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080040 "${config.JavadocCmd}",
41 "${config.SoongZipCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080042 },
Nan Zhang40b41b42018-10-02 16:11:17 -070043 CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
44 Rspfile: "$out.rsp",
45 RspfileContent: "$in",
46 Restat: true,
Nan Zhang581fd212018-01-10 16:06:12 -080047 },
Nan Zhangaf322cc2018-06-19 15:15:38 -070048 "outDir", "srcJarDir", "stubsDir", "srcJars", "opts",
Nan Zhang1598a9e2018-09-04 17:14:32 -070049 "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "docZip", "postDoclavaCmds")
Nan Zhang61819ce2018-05-04 18:49:16 -070050
51 apiCheck = pctx.AndroidStaticRule("apiCheck",
52 blueprint.RuleParams{
53 Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` +
54 `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` +
Jiyong Parkeeb8a642018-05-12 22:21:20 +090055 `&& touch $out ) || (echo -e "$msg" ; exit 38)`,
Nan Zhang61819ce2018-05-04 18:49:16 -070056 CommandDeps: []string{
57 "${config.ApiCheckCmd}",
58 },
59 },
60 "classpath", "opts", "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck", "msg")
61
62 updateApi = pctx.AndroidStaticRule("updateApi",
63 blueprint.RuleParams{
Nan Zhang1598a9e2018-09-04 17:14:32 -070064 Command: `( ( cp -f $srcApiFile $destApiFile && cp -f $srcRemovedApiFile $destRemovedApiFile ) ` +
Nan Zhang61819ce2018-05-04 18:49:16 -070065 `&& touch $out ) || (echo failed to update public API ; exit 38)`,
66 },
Nan Zhang1598a9e2018-09-04 17:14:32 -070067 "srcApiFile", "destApiFile", "srcRemovedApiFile", "destRemovedApiFile")
Nan Zhang79614d12018-04-19 18:03:39 -070068
69 metalava = pctx.AndroidStaticRule("metalava",
70 blueprint.RuleParams{
Nan Zhang1598a9e2018-09-04 17:14:32 -070071 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` +
72 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070073 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang357466b2018-04-17 17:38:36 -070074 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070075 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet ` +
76 `$opts && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070077 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
78 CommandDeps: []string{
79 "${config.ZipSyncCmd}",
80 "${config.JavaCmd}",
81 "${config.MetalavaJar}",
Nan Zhang79614d12018-04-19 18:03:39 -070082 "${config.SoongZipCmd}",
83 },
84 Rspfile: "$out.rsp",
85 RspfileContent: "$in",
86 Restat: true,
87 },
Nan Zhang1598a9e2018-09-04 17:14:32 -070088 "outDir", "srcJarDir", "stubsDir", "srcJars", "javaVersion", "bootclasspathArgs",
89 "classpathArgs", "sourcepathArgs", "opts")
Nan Zhang2760dfc2018-08-24 17:32:54 +000090
91 metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck",
92 blueprint.RuleParams{
93 Command: `( rm -rf "$srcJarDir" && mkdir -p "$srcJarDir" && ` +
94 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
95 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070096 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet ` +
Nan Zhang2760dfc2018-08-24 17:32:54 +000097 `$opts && touch $out ) || ` +
98 `( echo -e "$msg" ; exit 38 )`,
99 CommandDeps: []string{
100 "${config.ZipSyncCmd}",
101 "${config.JavaCmd}",
102 "${config.MetalavaJar}",
103 },
104 Rspfile: "$out.rsp",
105 RspfileContent: "$in",
106 },
Nan Zhang1598a9e2018-09-04 17:14:32 -0700107 "srcJarDir", "srcJars", "javaVersion", "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "opts", "msg")
108
109 dokka = pctx.AndroidStaticRule("dokka",
110 blueprint.RuleParams{
111 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` +
112 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
113 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
114 `${config.JavaCmd} -jar ${config.DokkaJar} $srcJarDir ` +
115 `$classpathArgs -format dac -dacRoot /reference/kotlin -output $outDir $opts && ` +
116 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
117 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
118 CommandDeps: []string{
119 "${config.ZipSyncCmd}",
120 "${config.DokkaJar}",
121 "${config.MetalavaJar}",
122 "${config.SoongZipCmd}",
123 },
124 Restat: true,
125 },
126 "outDir", "srcJarDir", "stubsDir", "srcJars", "classpathArgs", "opts", "docZip")
Nan Zhang581fd212018-01-10 16:06:12 -0800127)
128
129func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800130 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700131 android.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800132
Nan Zhang581fd212018-01-10 16:06:12 -0800133 android.RegisterModuleType("droiddoc", DroiddocFactory)
134 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -0700135 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800136 android.RegisterModuleType("javadoc", JavadocFactory)
137 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700138
139 android.RegisterModuleType("droidstubs", DroidstubsFactory)
140 android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800141}
142
Colin Crossa1ce2a02018-06-20 15:19:39 -0700143var (
144 srcsLibTag = dependencyTag{name: "sources from javalib"}
145)
146
Nan Zhang581fd212018-01-10 16:06:12 -0800147type JavadocProperties struct {
148 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
149 // or .aidl files.
150 Srcs []string `android:"arch_variant"`
151
152 // list of directories rooted at the Android.bp file that will
153 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800154 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800155
156 // list of source files that should not be used to build the Java module.
157 // This is most useful in the arch/multilib variants to remove non-common files
158 // filegroup or genrule can be included within this property.
159 Exclude_srcs []string `android:"arch_variant"`
160
Nan Zhangb2b33de2018-02-23 11:18:47 -0800161 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800162 Libs []string `android:"arch_variant"`
163
Nan Zhang5994b622018-09-21 16:39:51 -0700164 // don't build against the default libraries (bootclasspath, legacy-test, core-junit,
165 // ext, and framework for device targets)
166 No_standard_libs *bool
167
Nan Zhange66c7272018-03-06 12:59:27 -0800168 // don't build against the framework libraries (legacy-test, core-junit,
169 // ext, and framework for device targets)
170 No_framework_libs *bool
171
Nan Zhangb2b33de2018-02-23 11:18:47 -0800172 // the java library (in classpath) for documentation that provides java srcs and srcjars.
173 Srcs_lib *string
174
175 // the base dirs under srcs_lib will be scanned for java srcs.
176 Srcs_lib_whitelist_dirs []string
177
178 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
179 Srcs_lib_whitelist_pkgs []string
180
Nan Zhang581fd212018-01-10 16:06:12 -0800181 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800182 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800183
184 // if not blank, set to the version of the sdk to compile against
185 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900186
187 Aidl struct {
188 // Top level directories to pass to aidl tool
189 Include_dirs []string
190
191 // Directories rooted at the Android.bp file to pass to aidl tool
192 Local_include_dirs []string
193 }
Nan Zhang357466b2018-04-17 17:38:36 -0700194
195 // If not blank, set the java version passed to javadoc as -source
196 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700197
198 // local files that are used within user customized droiddoc options.
199 Arg_files []string
200
201 // user customized droiddoc args.
202 // Available variables for substitution:
203 //
204 // $(location <label>): the path to the arg_files with name <label>
205 Args *string
206
207 // names of the output files used in args that will be generated
208 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800209}
210
Nan Zhang61819ce2018-05-04 18:49:16 -0700211type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900212 // path to the API txt file that the new API extracted from source code is checked
213 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700214 Api_file *string
215
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900216 // path to the API txt file that the new @removed API extractd from source code is
217 // checked against. The path can be local to the module or from other module (via
218 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700219 Removed_api_file *string
220
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900221 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700222 Args *string
223}
224
Nan Zhang581fd212018-01-10 16:06:12 -0800225type DroiddocProperties struct {
226 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800227 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800228
Nan Zhanga40da042018-08-01 12:48:00 -0700229 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800230 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800231
232 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800233 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800234
235 // proofread file contains all of the text content of the javadocs concatenated into one file,
236 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800237 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800238
239 // a todo file lists the program elements that are missing documentation.
240 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800241 Todo_file *string
242
243 // directory under current module source that provide additional resources (images).
244 Resourcesdir *string
245
246 // resources output directory under out/soong/.intermediates.
247 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800248
Nan Zhange2ba5d42018-07-11 15:16:55 -0700249 // if set to true, collect the values used by the Dev tools and
250 // write them in files packaged with the SDK. Defaults to false.
251 Write_sdk_values *bool
252
253 // index.html under current module will be copied to docs out dir, if not null.
254 Static_doc_index_redirect *string
255
256 // source.properties under current module will be copied to docs out dir, if not null.
257 Static_doc_properties *string
258
Nan Zhang581fd212018-01-10 16:06:12 -0800259 // a list of files under current module source dir which contains known tags in Java sources.
260 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800261 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700262
263 // the tag name used to distinguish if the API files belong to public/system/test.
264 Api_tag_name *string
265
266 // the generated public API filename by Doclava.
267 Api_filename *string
268
David Brazdilfbe4cc32018-05-31 13:56:46 +0100269 // the generated public Dex API filename by Doclava.
270 Dex_api_filename *string
271
Nan Zhang28c68b92018-03-13 16:17:01 -0700272 // the generated private API filename by Doclava.
273 Private_api_filename *string
274
275 // the generated private Dex API filename by Doclava.
276 Private_dex_api_filename *string
277
278 // the generated removed API filename by Doclava.
279 Removed_api_filename *string
280
David Brazdilaac0c3c2018-04-24 16:23:29 +0100281 // the generated removed Dex API filename by Doclava.
282 Removed_dex_api_filename *string
283
Mathew Inwood76c3de12018-06-22 15:28:11 +0100284 // mapping of dex signatures to source file and line number. This is a temporary property and
285 // will be deleted; you probably shouldn't be using it.
286 Dex_mapping_filename *string
287
Nan Zhang28c68b92018-03-13 16:17:01 -0700288 // the generated exact API filename by Doclava.
289 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700290
Nan Zhang66dc2362018-08-14 20:41:04 -0700291 // the generated proguard filename by Doclava.
292 Proguard_filename *string
293
Nan Zhang853f4202018-04-12 16:55:56 -0700294 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
295 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700296
297 Check_api struct {
298 Last_released ApiToCheck
299
300 Current ApiToCheck
301 }
Nan Zhang79614d12018-04-19 18:03:39 -0700302
Nan Zhang1598a9e2018-09-04 17:14:32 -0700303 // if set to true, generate docs through Dokka instead of Doclava.
304 Dokka_enabled *bool
305}
306
307type DroidstubsProperties struct {
308 // the tag name used to distinguish if the API files belong to public/system/test.
309 Api_tag_name *string
310
Nan Zhang199645c2018-09-19 12:40:06 -0700311 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700312 Api_filename *string
313
Nan Zhang199645c2018-09-19 12:40:06 -0700314 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700315 Dex_api_filename *string
316
Nan Zhang199645c2018-09-19 12:40:06 -0700317 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700318 Private_api_filename *string
319
Nan Zhang199645c2018-09-19 12:40:06 -0700320 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700321 Private_dex_api_filename *string
322
Nan Zhang199645c2018-09-19 12:40:06 -0700323 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700324 Removed_api_filename *string
325
Nan Zhang199645c2018-09-19 12:40:06 -0700326 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700327 Removed_dex_api_filename *string
328
Nan Zhang9c69a122018-08-22 10:22:08 -0700329 // mapping of dex signatures to source file and line number. This is a temporary property and
330 // will be deleted; you probably shouldn't be using it.
331 Dex_mapping_filename *string
332
Nan Zhang199645c2018-09-19 12:40:06 -0700333 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700334 Exact_api_filename *string
335
Nan Zhang199645c2018-09-19 12:40:06 -0700336 // the generated proguard filename by Metalava.
337 Proguard_filename *string
338
Nan Zhang1598a9e2018-09-04 17:14:32 -0700339 Check_api struct {
340 Last_released ApiToCheck
341
342 Current ApiToCheck
343 }
Nan Zhang79614d12018-04-19 18:03:39 -0700344
345 // user can specify the version of previous released API file in order to do compatibility check.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700346 Previous_api *string
Nan Zhang79614d12018-04-19 18:03:39 -0700347
348 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700349 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700350
Pete Gillin77167902018-09-19 18:16:26 +0100351 // a list of top-level directories containing files to merge qualifier annotations (i.e. those intended to be included in the stubs written) from.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700352 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700353
Pete Gillin77167902018-09-19 18:16:26 +0100354 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
355 Merge_inclusion_annotations_dirs []string
356
Nan Zhang1598a9e2018-09-04 17:14:32 -0700357 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
358 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700359
360 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
361 Api_levels_annotations_enabled *bool
362
363 // the dirs which Metalava extracts API levels annotations from.
364 Api_levels_annotations_dirs []string
365
366 // if set to true, collect the values used by the Dev tools and
367 // write them in files packaged with the SDK. Defaults to false.
368 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700369
370 // If set to true, .xml based public API file will be also generated, and
371 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
372 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800373}
374
Nan Zhanga40da042018-08-01 12:48:00 -0700375//
376// Common flags passed down to build rule
377//
378type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700379 bootClasspathArgs string
380 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700381 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700382 dokkaClasspathArgs string
383 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700384
Nan Zhanga40da042018-08-01 12:48:00 -0700385 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700386 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700387 postDoclavaCmds string
388
Nan Zhang9c69a122018-08-22 10:22:08 -0700389 metalavaStubsFlags string
390 metalavaAnnotationsFlags string
391 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700392
Nan Zhang71bbe632018-09-17 14:32:21 -0700393 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700394}
395
396func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
397 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
398 android.InitDefaultableModule(module)
399}
400
Nan Zhang1598a9e2018-09-04 17:14:32 -0700401func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
402 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
403 return true
404 } else if String(apiToCheck.Api_file) != "" {
405 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
406 } else if String(apiToCheck.Removed_api_file) != "" {
407 panic("for " + apiVersionTag + " api_file has to be non-empty!")
408 }
409
410 return false
411}
412
413type ApiFilePath interface {
414 ApiFilePath() android.Path
415}
416
417func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
418 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
419 ctx.Build(pctx, android.BuildParams{
420 Rule: updateApi,
421 Description: "Update API",
422 Output: output,
423 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
424 destApiFile, destRemovedApiFile),
425 Args: map[string]string{
426 "destApiFile": destApiFile.String(),
427 "srcApiFile": srcApiFile.String(),
428 "destRemovedApiFile": destRemovedApiFile.String(),
429 "srcRemovedApiFile": srcRemovedApiFile.String(),
430 },
431 })
432}
433
Nan Zhanga40da042018-08-01 12:48:00 -0700434//
435// Javadoc
436//
Nan Zhang581fd212018-01-10 16:06:12 -0800437type Javadoc struct {
438 android.ModuleBase
439 android.DefaultableModuleBase
440
441 properties JavadocProperties
442
443 srcJars android.Paths
444 srcFiles android.Paths
445 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700446 argFiles android.Paths
447
448 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800449
Nan Zhangccff0f72018-03-08 17:26:16 -0800450 docZip android.WritablePath
451 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800452}
453
Nan Zhangb2b33de2018-02-23 11:18:47 -0800454func (j *Javadoc) Srcs() android.Paths {
455 return android.Paths{j.stubsSrcJar}
456}
457
Nan Zhang581fd212018-01-10 16:06:12 -0800458func JavadocFactory() android.Module {
459 module := &Javadoc{}
460
461 module.AddProperties(&module.properties)
462
463 InitDroiddocModule(module, android.HostAndDeviceSupported)
464 return module
465}
466
467func JavadocHostFactory() android.Module {
468 module := &Javadoc{}
469
470 module.AddProperties(&module.properties)
471
472 InitDroiddocModule(module, android.HostSupported)
473 return module
474}
475
Nan Zhanga40da042018-08-01 12:48:00 -0700476var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800477
Colin Cross83bb3162018-06-25 15:48:06 -0700478func (j *Javadoc) sdkVersion() string {
479 return String(j.properties.Sdk_version)
480}
481
482func (j *Javadoc) minSdkVersion() string {
483 return j.sdkVersion()
484}
485
Nan Zhang581fd212018-01-10 16:06:12 -0800486func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
487 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700488 if !Bool(j.properties.No_standard_libs) {
489 sdkDep := decodeSdkDep(ctx, sdkContext(j))
490 if sdkDep.useDefaultLibs {
491 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
492 if ctx.Config().TargetOpenJDK9() {
493 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
494 }
495 if !Bool(j.properties.No_framework_libs) {
496 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
497 }
498 } else if sdkDep.useModule {
499 if ctx.Config().TargetOpenJDK9() {
500 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
501 }
502 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700503 }
Nan Zhang581fd212018-01-10 16:06:12 -0800504 }
505 }
506
Colin Cross42d48b72018-08-29 14:10:52 -0700507 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700508 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700509 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700510 }
Nan Zhang581fd212018-01-10 16:06:12 -0800511
512 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
513
514 // exclude_srcs may contain filegroup or genrule.
515 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700516
517 // arg_files may contains filegroup or genrule.
518 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800519}
520
Nan Zhangb2b33de2018-02-23 11:18:47 -0800521func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
522 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
523 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900524 // convert foo.bar.baz to foo/bar/baz
525 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
526 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800527 if _, found := whitelistPathPrefixes[prefix]; !found {
528 whitelistPathPrefixes[prefix] = true
529 }
530 }
531 }
532}
533
Nan Zhanga40da042018-08-01 12:48:00 -0700534func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
535 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900536
537 // aidl flags.
538 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
539 if len(aidlFlags) > 0 {
540 // optimization.
541 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
542 flags.aidlFlags = "$aidlFlags"
543 }
544
545 return flags
546}
547
548func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
549 aidlIncludeDirs android.Paths) []string {
550
551 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
552 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
553
554 var flags []string
555 if aidlPreprocess.Valid() {
556 flags = append(flags, "-p"+aidlPreprocess.String())
557 } else {
558 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
559 }
560
561 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
562 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
563 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
564 flags = append(flags, "-I"+src.String())
565 }
566
567 return flags
568}
569
570func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700571 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900572
573 outSrcFiles := make(android.Paths, 0, len(srcFiles))
574
575 for _, srcFile := range srcFiles {
576 switch srcFile.Ext() {
577 case ".aidl":
578 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
579 outSrcFiles = append(outSrcFiles, javaFile)
580 default:
581 outSrcFiles = append(outSrcFiles, srcFile)
582 }
583 }
584
585 return outSrcFiles
586}
587
Nan Zhang581fd212018-01-10 16:06:12 -0800588func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
589 var deps deps
590
Colin Cross83bb3162018-06-25 15:48:06 -0700591 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800592 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700593 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800594 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700595 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800596 }
597
598 ctx.VisitDirectDeps(func(module android.Module) {
599 otherName := ctx.OtherModuleName(module)
600 tag := ctx.OtherModuleDependencyTag(module)
601
Colin Cross2d24c1b2018-05-23 10:59:18 -0700602 switch tag {
603 case bootClasspathTag:
604 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800605 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700606 } else {
607 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
608 }
609 case libTag:
610 switch dep := module.(type) {
611 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800612 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700613 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700614 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900615 linkType := javaSdk
616 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
617 linkType = javaSystem
618 } else if sdkVersion == "" {
619 linkType = javaPlatform
620 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900621 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700622 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800623 checkProducesJars(ctx, dep)
624 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800625 default:
626 ctx.ModuleErrorf("depends on non-java module %q", otherName)
627 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700628 case srcsLibTag:
629 switch dep := module.(type) {
630 case Dependency:
631 srcs := dep.(SrcDependency).CompiledSrcs()
632 whitelistPathPrefixes := make(map[string]bool)
633 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
634 for _, src := range srcs {
635 if _, ok := src.(android.WritablePath); ok { // generated sources
636 deps.srcs = append(deps.srcs, src)
637 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700638 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700639 if strings.HasPrefix(src.Rel(), k) {
640 deps.srcs = append(deps.srcs, src)
641 break
642 }
643 }
644 }
645 }
646 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
647 default:
648 ctx.ModuleErrorf("depends on non-java module %q", otherName)
649 }
Nan Zhang357466b2018-04-17 17:38:36 -0700650 case systemModulesTag:
651 if deps.systemModules != nil {
652 panic("Found two system module dependencies")
653 }
654 sm := module.(*SystemModules)
655 if sm.outputFile == nil {
656 panic("Missing directory for system module dependency")
657 }
658 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800659 }
660 })
661 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
662 // may contain filegroup or genrule.
663 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700664 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900665 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800666
667 // srcs may depend on some genrule output.
668 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800669 j.srcJars = append(j.srcJars, deps.srcJars...)
670
Nan Zhang581fd212018-01-10 16:06:12 -0800671 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800672 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800673
674 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800675 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800676
Nan Zhang9c69a122018-08-22 10:22:08 -0700677 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800678 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
679 }
680 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800681
Nan Zhang1598a9e2018-09-04 17:14:32 -0700682 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
683 argFilesMap := map[string]android.Path{}
684
685 for _, f := range j.argFiles {
686 if _, exists := argFilesMap[f.Rel()]; !exists {
687 argFilesMap[f.Rel()] = f
688 } else {
689 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
690 f, argFilesMap[f.Rel()], f.Rel())
691 }
692 }
693
694 var err error
695 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
696 if strings.HasPrefix(name, "location ") {
697 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
698 if f, ok := argFilesMap[label]; ok {
699 return f.String(), nil
700 } else {
701 return "", fmt.Errorf("unknown location label %q", label)
702 }
703 } else if name == "genDir" {
704 return android.PathForModuleGen(ctx).String(), nil
705 }
706 return "", fmt.Errorf("unknown variable '$(%s)'", name)
707 })
708
709 if err != nil {
710 ctx.PropertyErrorf("args", "%s", err.Error())
711 }
712
Nan Zhang581fd212018-01-10 16:06:12 -0800713 return deps
714}
715
716func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
717 j.addDeps(ctx)
718}
719
720func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
721 deps := j.collectDeps(ctx)
722
723 var implicits android.Paths
724 implicits = append(implicits, deps.bootClasspath...)
725 implicits = append(implicits, deps.classpath...)
726
Nan Zhang1598a9e2018-09-04 17:14:32 -0700727 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700728
Colin Cross83bb3162018-06-25 15:48:06 -0700729 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700730 if len(deps.bootClasspath) > 0 {
731 var systemModules classpath
732 if deps.systemModules != nil {
733 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800734 }
Colin Cross997262f2018-06-19 22:49:39 -0700735 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
736 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800737 }
738 if len(deps.classpath.Strings()) > 0 {
739 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
740 }
741
742 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700743 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800744
Nan Zhangaf322cc2018-06-19 15:15:38 -0700745 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800746
Nan Zhang1598a9e2018-09-04 17:14:32 -0700747 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
748
Nan Zhang581fd212018-01-10 16:06:12 -0800749 ctx.Build(pctx, android.BuildParams{
750 Rule: javadoc,
751 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800752 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800753 ImplicitOutput: j.docZip,
754 Inputs: j.srcFiles,
755 Implicits: implicits,
756 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700757 "outDir": android.PathForModuleOut(ctx, "out").String(),
758 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
759 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800760 "srcJars": strings.Join(j.srcJars.Strings(), " "),
761 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700762 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800763 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700764 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800765 "docZip": j.docZip.String(),
766 },
767 })
768}
769
Nan Zhanga40da042018-08-01 12:48:00 -0700770//
771// Droiddoc
772//
773type Droiddoc struct {
774 Javadoc
775
776 properties DroiddocProperties
777 apiFile android.WritablePath
778 dexApiFile android.WritablePath
779 privateApiFile android.WritablePath
780 privateDexApiFile android.WritablePath
781 removedApiFile android.WritablePath
782 removedDexApiFile android.WritablePath
783 exactApiFile android.WritablePath
784 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700785 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700786
787 checkCurrentApiTimestamp android.WritablePath
788 updateCurrentApiTimestamp android.WritablePath
789 checkLastReleasedApiTimestamp android.WritablePath
790
Nan Zhanga40da042018-08-01 12:48:00 -0700791 apiFilePath android.Path
792}
793
Nan Zhanga40da042018-08-01 12:48:00 -0700794func DroiddocFactory() android.Module {
795 module := &Droiddoc{}
796
797 module.AddProperties(&module.properties,
798 &module.Javadoc.properties)
799
800 InitDroiddocModule(module, android.HostAndDeviceSupported)
801 return module
802}
803
804func DroiddocHostFactory() android.Module {
805 module := &Droiddoc{}
806
807 module.AddProperties(&module.properties,
808 &module.Javadoc.properties)
809
810 InitDroiddocModule(module, android.HostSupported)
811 return module
812}
813
814func (d *Droiddoc) ApiFilePath() android.Path {
815 return d.apiFilePath
816}
817
Nan Zhang581fd212018-01-10 16:06:12 -0800818func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
819 d.Javadoc.addDeps(ctx)
820
Nan Zhang79614d12018-04-19 18:03:39 -0700821 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800822 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
823 }
824
Nan Zhang581fd212018-01-10 16:06:12 -0800825 // knowntags may contain filegroup or genrule.
826 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700827
Nan Zhange2ba5d42018-07-11 15:16:55 -0700828 if String(d.properties.Static_doc_index_redirect) != "" {
829 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
830 }
831
832 if String(d.properties.Static_doc_properties) != "" {
833 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
834 }
835
Nan Zhang1598a9e2018-09-04 17:14:32 -0700836 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700837 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
838 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
839 }
840
Nan Zhang1598a9e2018-09-04 17:14:32 -0700841 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700842 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
843 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
844 }
Nan Zhang581fd212018-01-10 16:06:12 -0800845}
846
Nan Zhang66dc2362018-08-14 20:41:04 -0700847func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
848 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700849 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800850
Nan Zhanga40da042018-08-01 12:48:00 -0700851 *implicits = append(*implicits, deps.bootClasspath...)
852 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800853
Nan Zhangc94f9d82018-06-26 10:02:26 -0700854 if len(deps.bootClasspath.Strings()) > 0 {
855 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700856 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700857 }
Nan Zhanga40da042018-08-01 12:48:00 -0700858 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700859 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700860 dokkaClasspath := classpath{}
861 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
862 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
863 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700864
Nan Zhang9c69a122018-08-22 10:22:08 -0700865 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
866 // based stubs generation.
867 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
868 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
869 // the correct package name base path.
870 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
871 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
872 } else {
873 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
874 }
Nan Zhang581fd212018-01-10 16:06:12 -0800875
Nan Zhanga40da042018-08-01 12:48:00 -0700876 return flags, nil
877}
Nan Zhang581fd212018-01-10 16:06:12 -0800878
Nan Zhanga40da042018-08-01 12:48:00 -0700879func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700880 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800881
Nan Zhanga40da042018-08-01 12:48:00 -0700882 *implicits = append(*implicits, jsilver)
883 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700884
Nan Zhang46130972018-06-04 11:28:01 -0700885 var date string
886 if runtime.GOOS == "darwin" {
887 date = `date -r`
888 } else {
889 date = `date -d`
890 }
891
Nan Zhang443fa522018-08-20 20:58:28 -0700892 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
893 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
894 // 1.9 language features.
895 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700896 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800897 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700898 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700899
Nan Zhanga40da042018-08-01 12:48:00 -0700900 if String(d.properties.Custom_template) == "" {
901 // TODO: This is almost always droiddoc-templates-sdk
902 ctx.PropertyErrorf("custom_template", "must specify a template")
903 }
904
905 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700906 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700907 *implicits = append(*implicits, t.deps...)
908 args = args + " -templatedir " + t.dir.String()
909 } else {
910 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
911 }
912 })
913
914 if len(d.properties.Html_dirs) > 0 {
915 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
916 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
917 args = args + " -htmldir " + htmlDir.String()
918 }
919
920 if len(d.properties.Html_dirs) > 1 {
921 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
922 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
923 args = args + " -htmldir2 " + htmlDir2.String()
924 }
925
926 if len(d.properties.Html_dirs) > 2 {
927 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
928 }
929
930 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
931 *implicits = append(*implicits, knownTags...)
932
933 for _, kt := range knownTags {
934 args = args + " -knowntags " + kt.String()
935 }
936
937 for _, hdf := range d.properties.Hdf {
938 args = args + " -hdf " + hdf
939 }
940
941 if String(d.properties.Proofread_file) != "" {
942 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
943 args = args + " -proofread " + proofreadFile.String()
944 }
945
946 if String(d.properties.Todo_file) != "" {
947 // tricky part:
948 // we should not compute full path for todo_file through PathForModuleOut().
949 // the non-standard doclet will get the full path relative to "-o".
950 args = args + " -todo " + String(d.properties.Todo_file)
951 }
952
953 if String(d.properties.Resourcesdir) != "" {
954 // TODO: should we add files under resourcesDir to the implicits? It seems that
955 // resourcesDir is one sub dir of htmlDir
956 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
957 args = args + " -resourcesdir " + resourcesDir.String()
958 }
959
960 if String(d.properties.Resourcesoutdir) != "" {
961 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
962 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
963 }
964 return args
965}
966
Nan Zhang1598a9e2018-09-04 17:14:32 -0700967func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
968 implicitOutputs *android.WritablePaths) string {
969 var doclavaFlags string
970 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
971 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
972 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700973 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
974 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700975 *implicitOutputs = append(*implicitOutputs, d.apiFile)
976 d.apiFilePath = d.apiFile
977 }
978
Nan Zhang1598a9e2018-09-04 17:14:32 -0700979 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
980 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
981 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700982 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
983 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700984 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
985 }
986
987 if String(d.properties.Private_api_filename) != "" {
988 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
989 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700990 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
991 }
992
993 if String(d.properties.Dex_api_filename) != "" {
994 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
995 doclavaFlags += " -dexApi " + d.dexApiFile.String()
996 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
997 }
998
999 if String(d.properties.Private_dex_api_filename) != "" {
1000 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1001 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001002 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1003 }
1004
1005 if String(d.properties.Removed_dex_api_filename) != "" {
1006 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1007 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001008 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1009 }
1010
1011 if String(d.properties.Exact_api_filename) != "" {
1012 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1013 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001014 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1015 }
1016
1017 if String(d.properties.Dex_mapping_filename) != "" {
1018 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1019 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001020 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1021 }
1022
Nan Zhang66dc2362018-08-14 20:41:04 -07001023 if String(d.properties.Proguard_filename) != "" {
1024 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1025 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001026 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1027 }
1028
Nan Zhanga40da042018-08-01 12:48:00 -07001029 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001030 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001031 }
1032
1033 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001034 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001035 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001036
1037 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001038}
1039
1040func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1041 var cmds string
1042 if String(d.properties.Static_doc_index_redirect) != "" {
1043 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1044 "static_doc_index_redirect")
1045 *implicits = append(*implicits, static_doc_index_redirect)
1046 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001047 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001048 }
1049
1050 if String(d.properties.Static_doc_properties) != "" {
1051 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1052 "static_doc_properties")
1053 *implicits = append(*implicits, static_doc_properties)
1054 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001055 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001056 }
1057 return cmds
1058}
1059
Nan Zhang1598a9e2018-09-04 17:14:32 -07001060func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1061 implicitOutputs android.WritablePaths,
1062 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1063 ctx.Build(pctx, android.BuildParams{
1064 Rule: javadoc,
1065 Description: "Doclava",
1066 Output: d.Javadoc.stubsSrcJar,
1067 Inputs: d.Javadoc.srcFiles,
1068 Implicits: implicits,
1069 ImplicitOutputs: implicitOutputs,
1070 Args: map[string]string{
1071 "outDir": android.PathForModuleOut(ctx, "out").String(),
1072 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1073 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1074 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1075 "opts": opts,
1076 "bootclasspathArgs": bootclasspathArgs,
1077 "classpathArgs": classpathArgs,
1078 "sourcepathArgs": sourcepathArgs,
1079 "docZip": d.Javadoc.docZip.String(),
1080 "postDoclavaCmds": postDoclavaCmds,
1081 },
1082 })
1083}
1084
1085func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1086 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1087 ctx.Build(pctx, android.BuildParams{
1088 Rule: apiCheck,
1089 Description: "Doclava Check API",
1090 Output: output,
1091 Inputs: nil,
1092 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1093 checkApiClasspath...),
1094 Args: map[string]string{
1095 "msg": msg,
1096 "classpath": checkApiClasspath.FormJavaClassPath(""),
1097 "opts": opts,
1098 "apiFile": apiFile.String(),
1099 "apiFileToCheck": d.apiFile.String(),
1100 "removedApiFile": removedApiFile.String(),
1101 "removedApiFileToCheck": d.removedApiFile.String(),
1102 },
1103 })
1104}
1105
1106func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1107 classpathArgs, opts string) {
1108 ctx.Build(pctx, android.BuildParams{
1109 Rule: dokka,
1110 Description: "Dokka",
1111 Output: d.Javadoc.stubsSrcJar,
1112 Inputs: d.Javadoc.srcFiles,
1113 Implicits: implicits,
1114 Args: map[string]string{
1115 "outDir": android.PathForModuleOut(ctx, "out").String(),
1116 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1117 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1118 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1119 "classpathArgs": classpathArgs,
1120 "opts": opts,
1121 "docZip": d.Javadoc.docZip.String(),
1122 },
1123 })
1124}
1125
1126func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1127 deps := d.Javadoc.collectDeps(ctx)
1128
1129 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1130 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1131 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1132 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1133
1134 var implicits android.Paths
1135 implicits = append(implicits, d.Javadoc.srcJars...)
1136 implicits = append(implicits, d.Javadoc.argFiles...)
1137
1138 var implicitOutputs android.WritablePaths
1139 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1140 for _, o := range d.Javadoc.properties.Out {
1141 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1142 }
1143
1144 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1145 if err != nil {
1146 return
1147 }
1148
1149 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1150 if Bool(d.properties.Dokka_enabled) {
1151 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1152 } else {
1153 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1154 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1155 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1156 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1157 flags.postDoclavaCmds)
1158 }
1159
1160 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1161 !ctx.Config().IsPdkBuild() {
1162 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1163 "check_api.current.api_file")
1164 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1165 "check_api.current_removed_api_file")
1166
1167 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1168 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1169 fmt.Sprintf(`\n******************************\n`+
1170 `You have tried to change the API from what has been previously approved.\n\n`+
1171 `To make these errors go away, you have two choices:\n`+
1172 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1173 ` errors above.\n\n`+
1174 ` 2. You can update current.txt by executing the following command:\n`+
1175 ` make %s-update-current-api\n\n`+
1176 ` To submit the revised current.txt to the main Android repository,\n`+
1177 ` you will need approval.\n`+
1178 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1179 d.checkCurrentApiTimestamp)
1180
1181 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1182 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1183 d.updateCurrentApiTimestamp)
1184 }
1185
1186 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1187 !ctx.Config().IsPdkBuild() {
1188 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1189 "check_api.last_released.api_file")
1190 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1191 "check_api.last_released.removed_api_file")
1192
1193 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1194 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1195 `\n******************************\n`+
1196 `You have tried to change the API from what has been previously released in\n`+
1197 `an SDK. Please fix the errors listed above.\n`+
1198 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1199 d.checkLastReleasedApiTimestamp)
1200 }
1201}
1202
1203//
1204// Droidstubs
1205//
1206type Droidstubs struct {
1207 Javadoc
1208
Nan Zhang71bbe632018-09-17 14:32:21 -07001209 properties DroidstubsProperties
1210 apiFile android.WritablePath
1211 apiXmlFile android.WritablePath
1212 lastReleasedApiXmlFile android.WritablePath
1213 dexApiFile android.WritablePath
1214 privateApiFile android.WritablePath
1215 privateDexApiFile android.WritablePath
1216 removedApiFile android.WritablePath
1217 removedDexApiFile android.WritablePath
1218 apiMappingFile android.WritablePath
1219 exactApiFile android.WritablePath
Nan Zhang199645c2018-09-19 12:40:06 -07001220 proguardFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001221
1222 checkCurrentApiTimestamp android.WritablePath
1223 updateCurrentApiTimestamp android.WritablePath
1224 checkLastReleasedApiTimestamp android.WritablePath
1225
1226 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001227 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001228
1229 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001230
1231 jdiffDocZip android.WritablePath
1232 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001233}
1234
1235func DroidstubsFactory() android.Module {
1236 module := &Droidstubs{}
1237
1238 module.AddProperties(&module.properties,
1239 &module.Javadoc.properties)
1240
1241 InitDroiddocModule(module, android.HostAndDeviceSupported)
1242 return module
1243}
1244
1245func DroidstubsHostFactory() android.Module {
1246 module := &Droidstubs{}
1247
1248 module.AddProperties(&module.properties,
1249 &module.Javadoc.properties)
1250
1251 InitDroiddocModule(module, android.HostSupported)
1252 return module
1253}
1254
1255func (d *Droidstubs) ApiFilePath() android.Path {
1256 return d.apiFilePath
1257}
1258
1259func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1260 d.Javadoc.addDeps(ctx)
1261
1262 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1263 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1264 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1265 }
1266
1267 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1268 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1269 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1270 }
1271
1272 if String(d.properties.Previous_api) != "" {
1273 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1274 }
1275
1276 if len(d.properties.Merge_annotations_dirs) != 0 {
1277 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1278 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1279 }
1280 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001281
Pete Gillin77167902018-09-19 18:16:26 +01001282 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1283 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1284 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1285 }
1286 }
1287
Nan Zhang9c69a122018-08-22 10:22:08 -07001288 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1289 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1290 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1291 }
1292 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001293}
1294
1295func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1296 deps deps) (droiddocBuilderFlags, error) {
1297 var flags droiddocBuilderFlags
1298
1299 *implicits = append(*implicits, deps.bootClasspath...)
1300 *implicits = append(*implicits, deps.classpath...)
1301
1302 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1303 // since it doesn't support system modules yet.
1304 if len(deps.bootClasspath.Strings()) > 0 {
1305 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1306 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1307 }
1308 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1309
1310 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
1311
1312 return flags, nil
1313}
1314
1315func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1316 implicitOutputs *android.WritablePaths) string {
1317 var metalavaFlags string
1318 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1319 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1320 String(d.properties.Api_filename) != "" {
1321 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1322 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1323 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1324 d.apiFilePath = d.apiFile
1325 }
1326
1327 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1328 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1329 String(d.properties.Removed_api_filename) != "" {
1330 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1331 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1332 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1333 }
1334
1335 if String(d.properties.Private_api_filename) != "" {
1336 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1337 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1338 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1339 }
1340
1341 if String(d.properties.Dex_api_filename) != "" {
1342 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1343 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1344 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1345 }
1346
1347 if String(d.properties.Private_dex_api_filename) != "" {
1348 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1349 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1350 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1351 }
1352
1353 if String(d.properties.Removed_dex_api_filename) != "" {
1354 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1355 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1356 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1357 }
1358
1359 if String(d.properties.Exact_api_filename) != "" {
1360 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1361 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1362 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1363 }
1364
Nan Zhang9c69a122018-08-22 10:22:08 -07001365 if String(d.properties.Dex_mapping_filename) != "" {
1366 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1367 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1368 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1369 }
1370
Nan Zhang199645c2018-09-19 12:40:06 -07001371 if String(d.properties.Proguard_filename) != "" {
1372 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1373 metalavaFlags += " --proguard " + d.proguardFile.String()
1374 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1375 }
1376
Nan Zhang9c69a122018-08-22 10:22:08 -07001377 if Bool(d.properties.Write_sdk_values) {
1378 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1379 }
1380
Nan Zhang1598a9e2018-09-04 17:14:32 -07001381 if Bool(d.properties.Create_doc_stubs) {
1382 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1383 } else {
1384 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1385 }
1386
1387 return metalavaFlags
1388}
1389
1390func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
1391 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
Nan Zhanga40da042018-08-01 12:48:00 -07001392 var flags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001393 if Bool(d.properties.Annotations_enabled) {
1394 if String(d.properties.Previous_api) == "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001395 ctx.PropertyErrorf("metalava_previous_api",
1396 "has to be non-empty if annotations was enabled!")
1397 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001398 previousApi := ctx.ExpandSource(String(d.properties.Previous_api),
Nan Zhangde860a42018-08-08 16:32:21 -07001399 "metalava_previous_api")
1400 *implicits = append(*implicits, previousApi)
Nan Zhangde860a42018-08-08 16:32:21 -07001401
Nan Zhangd05a4362018-08-15 13:28:54 -07001402 flags += " --include-annotations --migrate-nullness " + previousApi.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001403
1404 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1405 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1406
Nan Zhangf4936b02018-08-01 15:00:28 -07001407 flags += " --extract-annotations " + d.annotationsZip.String()
1408
Nan Zhang1598a9e2018-09-04 17:14:32 -07001409 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001410 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001411 "has to be non-empty if annotations was enabled!")
1412 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001413 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1414 if t, ok := m.(*ExportedDroiddocDir); ok {
1415 *implicits = append(*implicits, t.deps...)
Pete Gillin77167902018-09-19 18:16:26 +01001416 flags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001417 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001418 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001419 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1420 }
1421 })
Nan Zhanga40da042018-08-01 12:48:00 -07001422 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1423 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction "
1424 }
Pete Gillin77167902018-09-19 18:16:26 +01001425 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1426 if t, ok := m.(*ExportedDroiddocDir); ok {
1427 *implicits = append(*implicits, t.deps...)
1428 flags += " --merge-inclusion-annotations " + t.dir.String()
1429 } else {
1430 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1431 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1432 }
1433 })
Nan Zhanga40da042018-08-01 12:48:00 -07001434
1435 return flags
1436}
1437
Nan Zhang9c69a122018-08-22 10:22:08 -07001438func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1439 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1440 var flags string
1441 if Bool(d.properties.Api_levels_annotations_enabled) {
1442 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1443 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1444
1445 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1446 ctx.PropertyErrorf("api_levels_annotations_dirs",
1447 "has to be non-empty if api levels annotations was enabled!")
1448 }
1449
1450 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1451 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1452 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1453
1454 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1455 if t, ok := m.(*ExportedDroiddocDir); ok {
1456 var androidJars android.Paths
1457 for _, dep := range t.deps {
1458 if strings.HasSuffix(dep.String(), "android.jar") {
1459 androidJars = append(androidJars, dep)
1460 }
1461 }
1462 *implicits = append(*implicits, androidJars...)
1463 flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar "
1464 } else {
1465 ctx.PropertyErrorf("api_levels_annotations_dirs",
1466 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1467 }
1468 })
1469
1470 }
1471
1472 return flags
1473}
1474
Nan Zhang71bbe632018-09-17 14:32:21 -07001475func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1476 implicitOutputs *android.WritablePaths) string {
1477 var flags string
1478 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1479 if d.apiFile.String() == "" {
1480 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1481 }
1482
1483 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1484 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1485
1486 flags = " --api-xml " + d.apiXmlFile.String()
1487
1488 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1489 ctx.PropertyErrorf("check_api.last_released.api_file",
1490 "has to be non-empty if jdiff was enabled!")
1491 }
1492 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1493 "check_api.last_released.api_file")
1494 *implicits = append(*implicits, lastReleasedApi)
1495
1496 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1497 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1498
1499 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1500 d.lastReleasedApiXmlFile.String()
1501 }
1502
1503 return flags
1504}
1505
Nan Zhang1598a9e2018-09-04 17:14:32 -07001506func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1507 implicitOutputs android.WritablePaths, javaVersion,
1508 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001509
Nan Zhang86d2d552018-08-09 15:33:27 -07001510 ctx.Build(pctx, android.BuildParams{
1511 Rule: metalava,
1512 Description: "Metalava",
1513 Output: d.Javadoc.stubsSrcJar,
1514 Inputs: d.Javadoc.srcFiles,
1515 Implicits: implicits,
1516 ImplicitOutputs: implicitOutputs,
1517 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001518 "outDir": android.PathForModuleOut(ctx, "out").String(),
1519 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1520 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1521 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001522 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001523 "bootclasspathArgs": bootclasspathArgs,
1524 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001525 "sourcepathArgs": sourcepathArgs,
1526 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001527 },
1528 })
1529}
1530
Nan Zhang1598a9e2018-09-04 17:14:32 -07001531func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1532 apiFile, removedApiFile android.Path, implicits android.Paths,
1533 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001534 output android.WritablePath) {
1535 ctx.Build(pctx, android.BuildParams{
1536 Rule: metalavaApiCheck,
1537 Description: "Metalava Check API",
1538 Output: output,
1539 Inputs: d.Javadoc.srcFiles,
1540 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1541 implicits...),
1542 Args: map[string]string{
1543 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1544 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1545 "javaVersion": javaVersion,
1546 "bootclasspathArgs": bootclasspathArgs,
1547 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001548 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001549 "opts": opts,
1550 "msg": msg,
1551 },
1552 })
1553}
1554
Nan Zhang71bbe632018-09-17 14:32:21 -07001555func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1556 implicitOutputs android.WritablePaths,
1557 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1558 ctx.Build(pctx, android.BuildParams{
1559 Rule: javadoc,
1560 Description: "Jdiff",
1561 Output: d.jdiffStubsSrcJar,
1562 Inputs: d.Javadoc.srcFiles,
1563 Implicits: implicits,
1564 ImplicitOutputs: implicitOutputs,
1565 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001566 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1567 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1568 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001569 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1570 "opts": opts,
1571 "bootclasspathArgs": bootclasspathArgs,
1572 "classpathArgs": classpathArgs,
1573 "sourcepathArgs": sourcepathArgs,
1574 "docZip": d.jdiffDocZip.String(),
1575 },
1576 })
1577}
1578
Nan Zhang1598a9e2018-09-04 17:14:32 -07001579func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001580 deps := d.Javadoc.collectDeps(ctx)
1581
1582 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001583
Nan Zhanga40da042018-08-01 12:48:00 -07001584 var implicits android.Paths
1585 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001586 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001587
1588 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001589 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001590 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1591 }
1592
1593 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001594 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001595 jdiffImplicits := implicits
1596
Nan Zhanga40da042018-08-01 12:48:00 -07001597 if err != nil {
1598 return
1599 }
1600
Nan Zhang1598a9e2018-09-04 17:14:32 -07001601 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1602 flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001603 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001604 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1605
Nan Zhang1598a9e2018-09-04 17:14:32 -07001606 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1607 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1608 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1609 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1610 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001611 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001612 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1613 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Nan Zhang9c69a122018-08-22 10:22:08 -07001614 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001615 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001616
Nan Zhang1598a9e2018-09-04 17:14:32 -07001617 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1618 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001619 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1620 "check_api.current.api_file")
1621 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1622 "check_api.current_removed_api_file")
1623
Nan Zhang2760dfc2018-08-24 17:32:54 +00001624 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001625 opts := d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1626 " --check-compatibility:removed:current " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001627
Nan Zhang1598a9e2018-09-04 17:14:32 -07001628 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1629 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1630 fmt.Sprintf(`\n******************************\n`+
1631 `You have tried to change the API from what has been previously approved.\n\n`+
1632 `To make these errors go away, you have two choices:\n`+
1633 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1634 ` errors above.\n\n`+
1635 ` 2. You can update current.txt by executing the following command:\n`+
1636 ` make %s-update-current-api\n\n`+
1637 ` To submit the revised current.txt to the main Android repository,\n`+
1638 ` you will need approval.\n`+
1639 `******************************\n`, ctx.ModuleName()),
1640 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001641
1642 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001643 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1644 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001645 }
Nan Zhanga40da042018-08-01 12:48:00 -07001646
Nan Zhang1598a9e2018-09-04 17:14:32 -07001647 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1648 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001649 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1650 "check_api.last_released.api_file")
1651 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1652 "check_api.last_released.removed_api_file")
1653
Nan Zhang2760dfc2018-08-24 17:32:54 +00001654 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001655 opts := d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1656 " --check-compatibility:removed:released " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001657
Nan Zhang1598a9e2018-09-04 17:14:32 -07001658 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1659 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1660 `\n******************************\n`+
1661 `You have tried to change the API from what has been previously released in\n`+
1662 `an SDK. Please fix the errors listed above.\n`+
1663 `******************************\n`,
1664 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001665 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001666
1667 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1668
Nan Zhang86b06202018-09-21 17:09:21 -07001669 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1670 // since there's cron job downstream that fetch this .zip file periodically.
1671 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001672 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1673 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1674
1675 var jdiffImplicitOutputs android.WritablePaths
1676 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1677
1678 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1679 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1680
1681 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1682 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1683 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1684 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1685 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1686 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1687
1688 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1689 flags.sourcepathArgs, opts)
1690 }
Nan Zhang581fd212018-01-10 16:06:12 -08001691}
Dan Willemsencc090972018-02-26 14:33:31 -08001692
Nan Zhanga40da042018-08-01 12:48:00 -07001693//
Nan Zhangf4936b02018-08-01 15:00:28 -07001694// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001695//
Dan Willemsencc090972018-02-26 14:33:31 -08001696var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001697var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001698var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001699var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001700
Nan Zhangf4936b02018-08-01 15:00:28 -07001701type ExportedDroiddocDirProperties struct {
1702 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001703 Path *string
1704}
1705
Nan Zhangf4936b02018-08-01 15:00:28 -07001706type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001707 android.ModuleBase
1708
Nan Zhangf4936b02018-08-01 15:00:28 -07001709 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001710
1711 deps android.Paths
1712 dir android.Path
1713}
1714
Nan Zhangf4936b02018-08-01 15:00:28 -07001715func ExportedDroiddocDirFactory() android.Module {
1716 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001717 module.AddProperties(&module.properties)
1718 android.InitAndroidModule(module)
1719 return module
1720}
1721
Nan Zhangf4936b02018-08-01 15:00:28 -07001722func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001723
Nan Zhangf4936b02018-08-01 15:00:28 -07001724func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001725 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1726 d.dir = path
1727 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1728}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001729
1730//
1731// Defaults
1732//
1733type DocDefaults struct {
1734 android.ModuleBase
1735 android.DefaultsModuleBase
1736}
1737
1738func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1739}
1740
1741func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1742}
1743
1744func DocDefaultsFactory() android.Module {
1745 module := &DocDefaults{}
1746
1747 module.AddProperties(
1748 &JavadocProperties{},
1749 &DroiddocProperties{},
1750 )
1751
1752 android.InitDefaultsModule(module)
1753
1754 return module
1755}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001756
1757func StubsDefaultsFactory() android.Module {
1758 module := &DocDefaults{}
1759
1760 module.AddProperties(
1761 &JavadocProperties{},
1762 &DroidstubsProperties{},
1763 )
1764
1765 android.InitDefaultsModule(module)
1766
1767 return module
1768}