Home | History | Annotate | Download | only in java
      1 // Copyright 2015 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 
     15 package java
     16 
     17 import (
     18 	"fmt"
     19 	"io"
     20 	"strings"
     21 
     22 	"android/soong/android"
     23 )
     24 
     25 func (library *Library) AndroidMkHostDex(w io.Writer, name string, data android.AndroidMkData) {
     26 	if Bool(library.deviceProperties.Hostdex) && !library.Host() {
     27 		fmt.Fprintln(w, "include $(CLEAR_VARS)")
     28 		fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
     29 		fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
     30 		fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
     31 		if library.dexJarFile != nil {
     32 			fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.dexJarFile.String())
     33 		} else {
     34 			fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationAndResourcesJar.String())
     35 		}
     36 		if library.dexJarFile != nil {
     37 			fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
     38 		}
     39 		fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
     40 		fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
     41 		fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
     42 		if r := library.deviceProperties.Target.Hostdex.Required; len(r) > 0 {
     43 			fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(r, " "))
     44 		}
     45 		fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
     46 	}
     47 }
     48 
     49 func (library *Library) AndroidMk() android.AndroidMkData {
     50 	return android.AndroidMkData{
     51 		Class:      "JAVA_LIBRARIES",
     52 		OutputFile: android.OptionalPathForPath(library.outputFile),
     53 		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
     54 		Extra: []android.AndroidMkExtraFunc{
     55 			func(w io.Writer, outputFile android.Path) {
     56 				if len(library.logtagsSrcs) > 0 {
     57 					var logtags []string
     58 					for _, l := range library.logtagsSrcs {
     59 						logtags = append(logtags, l.Rel())
     60 					}
     61 					fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(logtags, " "))
     62 				}
     63 
     64 				if library.installFile == nil {
     65 					fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
     66 				}
     67 				if library.dexJarFile != nil {
     68 					fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
     69 				}
     70 				if len(library.dexpreopter.builtInstalled) > 0 {
     71 					fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", library.dexpreopter.builtInstalled)
     72 				}
     73 				fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.sdkVersion())
     74 				fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
     75 				fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
     76 
     77 				if library.jacocoReportClassesFile != nil {
     78 					fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", library.jacocoReportClassesFile.String())
     79 				}
     80 
     81 				if len(library.exportedSdkLibs) != 0 {
     82 					fmt.Fprintln(w, "LOCAL_EXPORT_SDK_LIBRARIES :=", strings.Join(library.exportedSdkLibs, " "))
     83 				}
     84 
     85 				if len(library.additionalCheckedModules) != 0 {
     86 					fmt.Fprintln(w, "LOCAL_ADDITIONAL_CHECKED_MODULE +=", strings.Join(library.additionalCheckedModules.Strings(), " "))
     87 				}
     88 
     89 				// Temporary hack: export sources used to compile framework.jar to Make
     90 				// to be used for droiddoc
     91 				// TODO(ccross): remove this once droiddoc is in soong
     92 				if (library.Name() == "framework") || (library.Name() == "framework-annotation-proc") {
     93 					fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCS :=", strings.Join(library.compiledJavaSrcs.Strings(), " "))
     94 					fmt.Fprintln(w, "SOONG_FRAMEWORK_SRCJARS :=", strings.Join(library.compiledSrcJars.Strings(), " "))
     95 				}
     96 			},
     97 		},
     98 		Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
     99 			android.WriteAndroidMkData(w, data)
    100 			library.AndroidMkHostDex(w, name, data)
    101 		},
    102 	}
    103 }
    104 
    105 // Called for modules that are a component of a test suite.
    106 func testSuiteComponent(w io.Writer, test_suites []string) {
    107 	fmt.Fprintln(w, "LOCAL_MODULE_TAGS := tests")
    108 	if len(test_suites) > 0 {
    109 		fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
    110 			strings.Join(test_suites, " "))
    111 	} else {
    112 		fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE := null-suite")
    113 	}
    114 }
    115 
    116 func (j *Test) AndroidMk() android.AndroidMkData {
    117 	data := j.Library.AndroidMk()
    118 	data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
    119 		testSuiteComponent(w, j.testProperties.Test_suites)
    120 		if j.testConfig != nil {
    121 			fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", j.testConfig.String())
    122 		}
    123 	})
    124 
    125 	androidMkWriteTestData(j.data, &data)
    126 
    127 	return data
    128 }
    129 
    130 func (j *TestHelperLibrary) AndroidMk() android.AndroidMkData {
    131 	data := j.Library.AndroidMk()
    132 	data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
    133 		testSuiteComponent(w, j.testHelperLibraryProperties.Test_suites)
    134 	})
    135 
    136 	return data
    137 }
    138 
    139 func (prebuilt *Import) AndroidMk() android.AndroidMkData {
    140 	return android.AndroidMkData{
    141 		Class:      "JAVA_LIBRARIES",
    142 		OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
    143 		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
    144 		Extra: []android.AndroidMkExtraFunc{
    145 			func(w io.Writer, outputFile android.Path) {
    146 				fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable))
    147 				fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
    148 				fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.combinedClasspathFile.String())
    149 				fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
    150 			},
    151 		},
    152 	}
    153 }
    154 
    155 func (prebuilt *DexImport) AndroidMk() android.AndroidMkData {
    156 	return android.AndroidMkData{
    157 		Class:      "JAVA_LIBRARIES",
    158 		OutputFile: android.OptionalPathForPath(prebuilt.maybeStrippedDexJarFile),
    159 		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
    160 		Extra: []android.AndroidMkExtraFunc{
    161 			func(w io.Writer, outputFile android.Path) {
    162 				if prebuilt.dexJarFile != nil {
    163 					fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", prebuilt.dexJarFile.String())
    164 					// TODO(b/125517186): export the dex jar as a classes jar to match some mis-uses in Make until
    165 					// boot_jars_package_check.mk can check dex jars.
    166 					fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.dexJarFile.String())
    167 					fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.dexJarFile.String())
    168 				}
    169 				if len(prebuilt.dexpreopter.builtInstalled) > 0 {
    170 					fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", prebuilt.dexpreopter.builtInstalled)
    171 				}
    172 			},
    173 		},
    174 	}
    175 }
    176 
    177 func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
    178 	return android.AndroidMkData{
    179 		Class:      "JAVA_LIBRARIES",
    180 		OutputFile: android.OptionalPathForPath(prebuilt.classpathFile),
    181 		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
    182 		Extra: []android.AndroidMkExtraFunc{
    183 			func(w io.Writer, outputFile android.Path) {
    184 				fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
    185 				fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String())
    186 				fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.classpathFile.String())
    187 				fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String())
    188 				fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
    189 				fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
    190 				fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", prebuilt.manifest.String())
    191 				fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
    192 			},
    193 		},
    194 	}
    195 }
    196 
    197 func (binary *Binary) AndroidMk() android.AndroidMkData {
    198 
    199 	if !binary.isWrapperVariant {
    200 		return android.AndroidMkData{
    201 			Class:      "JAVA_LIBRARIES",
    202 			OutputFile: android.OptionalPathForPath(binary.outputFile),
    203 			Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
    204 			Extra: []android.AndroidMkExtraFunc{
    205 				func(w io.Writer, outputFile android.Path) {
    206 					fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", binary.headerJarFile.String())
    207 					fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", binary.implementationAndResourcesJar.String())
    208 					if binary.dexJarFile != nil {
    209 						fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", binary.dexJarFile.String())
    210 					}
    211 					if len(binary.dexpreopter.builtInstalled) > 0 {
    212 						fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", binary.dexpreopter.builtInstalled)
    213 					}
    214 				},
    215 			},
    216 			Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
    217 				android.WriteAndroidMkData(w, data)
    218 
    219 				fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
    220 			},
    221 		}
    222 	} else {
    223 		return android.AndroidMkData{
    224 			Class:      "EXECUTABLES",
    225 			OutputFile: android.OptionalPathForPath(binary.wrapperFile),
    226 			Extra: []android.AndroidMkExtraFunc{
    227 				func(w io.Writer, outputFile android.Path) {
    228 					fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
    229 				},
    230 			},
    231 			Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
    232 				android.WriteAndroidMkData(w, data)
    233 
    234 				// Ensure that the wrapper script timestamp is always updated when the jar is updated
    235 				fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
    236 				fmt.Fprintln(w, "jar_installed_module :=")
    237 			},
    238 		}
    239 	}
    240 }
    241 
    242 func (app *AndroidApp) AndroidMk() android.AndroidMkData {
    243 	return android.AndroidMkData{
    244 		Class:      "APPS",
    245 		OutputFile: android.OptionalPathForPath(app.outputFile),
    246 		Include:    "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
    247 		Extra: []android.AndroidMkExtraFunc{
    248 			func(w io.Writer, outputFile android.Path) {
    249 				// TODO(jungjw): This, outputting two LOCAL_MODULE lines, works, but is not ideal. Find a better solution.
    250 				if app.Name() != app.installApkName {
    251 					fmt.Fprintln(w, "# Overridden by PRODUCT_PACKAGE_NAME_OVERRIDES")
    252 					fmt.Fprintln(w, "LOCAL_MODULE :=", app.installApkName)
    253 				}
    254 				fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", app.exportPackage.String())
    255 				if app.dexJarFile != nil {
    256 					fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
    257 				}
    258 				if app.implementationAndResourcesJar != nil {
    259 					fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationAndResourcesJar.String())
    260 				}
    261 				if app.headerJarFile != nil {
    262 					fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())
    263 				}
    264 				if app.bundleFile != nil {
    265 					fmt.Fprintln(w, "LOCAL_SOONG_BUNDLE :=", app.bundleFile.String())
    266 				}
    267 				if app.jacocoReportClassesFile != nil {
    268 					fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
    269 				}
    270 				if app.proguardDictionary != nil {
    271 					fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", app.proguardDictionary.String())
    272 				}
    273 
    274 				if app.Name() == "framework-res" {
    275 					fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
    276 					// Make base_rules.mk not put framework-res in a subdirectory called
    277 					// framework_res.
    278 					fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
    279 				}
    280 
    281 				filterRRO := func(filter overlayType) android.Paths {
    282 					var paths android.Paths
    283 					for _, d := range app.rroDirs {
    284 						if d.overlayType == filter {
    285 							paths = append(paths, d.path)
    286 						}
    287 					}
    288 					// Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
    289 					// expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
    290 					return android.ReversePaths(paths)
    291 				}
    292 				deviceRRODirs := filterRRO(device)
    293 				if len(deviceRRODirs) > 0 {
    294 					fmt.Fprintln(w, "LOCAL_SOONG_DEVICE_RRO_DIRS :=", strings.Join(deviceRRODirs.Strings(), " "))
    295 				}
    296 				productRRODirs := filterRRO(product)
    297 				if len(productRRODirs) > 0 {
    298 					fmt.Fprintln(w, "LOCAL_SOONG_PRODUCT_RRO_DIRS :=", strings.Join(productRRODirs.Strings(), " "))
    299 				}
    300 
    301 				if Bool(app.appProperties.Export_package_resources) {
    302 					fmt.Fprintln(w, "LOCAL_EXPORT_PACKAGE_RESOURCES := true")
    303 				}
    304 
    305 				fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", app.manifestPath.String())
    306 
    307 				if Bool(app.appProperties.Privileged) {
    308 					fmt.Fprintln(w, "LOCAL_PRIVILEGED_MODULE := true")
    309 				}
    310 
    311 				fmt.Fprintln(w, "LOCAL_CERTIFICATE :=", app.certificate.Pem.String())
    312 				if overriddenPkgs := app.getOverriddenPackages(); len(overriddenPkgs) > 0 {
    313 					fmt.Fprintln(w, "LOCAL_OVERRIDES_PACKAGES :=", strings.Join(overriddenPkgs, " "))
    314 				}
    315 
    316 				for _, jniLib := range app.installJniLibs {
    317 					fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), "+=", jniLib.name)
    318 				}
    319 				if len(app.dexpreopter.builtInstalled) > 0 {
    320 					fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", app.dexpreopter.builtInstalled)
    321 				}
    322 				for _, split := range app.aapt.splits {
    323 					install := "$(LOCAL_MODULE_PATH)/" + strings.TrimSuffix(app.installApkName, ".apk") + split.suffix + ".apk"
    324 					fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED +=", split.path.String()+":"+install)
    325 				}
    326 			},
    327 		},
    328 	}
    329 }
    330 
    331 func (a *AndroidApp) getOverriddenPackages() []string {
    332 	var overridden []string
    333 	if len(a.appProperties.Overrides) > 0 {
    334 		overridden = append(overridden, a.appProperties.Overrides...)
    335 	}
    336 	if a.Name() != a.installApkName {
    337 		overridden = append(overridden, a.Name())
    338 	}
    339 	return overridden
    340 }
    341 
    342 func (a *AndroidTest) AndroidMk() android.AndroidMkData {
    343 	data := a.AndroidApp.AndroidMk()
    344 	data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
    345 		testSuiteComponent(w, a.testProperties.Test_suites)
    346 		if a.testConfig != nil {
    347 			fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", a.testConfig.String())
    348 		}
    349 	})
    350 	androidMkWriteTestData(a.data, &data)
    351 
    352 	return data
    353 }
    354 
    355 func (a *AndroidTestHelperApp) AndroidMk() android.AndroidMkData {
    356 	data := a.AndroidApp.AndroidMk()
    357 	data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
    358 		testSuiteComponent(w, a.appTestHelperAppProperties.Test_suites)
    359 	})
    360 
    361 	return data
    362 }
    363 
    364 func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
    365 	data := a.Library.AndroidMk()
    366 
    367 	data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
    368 		if a.aarFile != nil {
    369 			fmt.Fprintln(w, "LOCAL_SOONG_AAR :=", a.aarFile.String())
    370 		}
    371 		if a.proguardDictionary != nil {
    372 			fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", a.proguardDictionary.String())
    373 		}
    374 
    375 		if a.Name() == "framework-res" {
    376 			fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)")
    377 			// Make base_rules.mk not put framework-res in a subdirectory called
    378 			// framework_res.
    379 			fmt.Fprintln(w, "LOCAL_NO_STANDARD_LIBRARIES := true")
    380 		}
    381 
    382 		fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
    383 		fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
    384 		fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.manifestPath.String())
    385 		fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
    386 			strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
    387 		fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
    388 	})
    389 
    390 	return data
    391 }
    392 
    393 func (jd *Javadoc) AndroidMk() android.AndroidMkData {
    394 	return android.AndroidMkData{
    395 		Class:      "JAVA_LIBRARIES",
    396 		OutputFile: android.OptionalPathForPath(jd.stubsSrcJar),
    397 		Include:    "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
    398 		Extra: []android.AndroidMkExtraFunc{
    399 			func(w io.Writer, outputFile android.Path) {
    400 				if BoolDefault(jd.properties.Installable, true) {
    401 					fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", jd.docZip.String())
    402 				}
    403 				if jd.stubsSrcJar != nil {
    404 					fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", jd.stubsSrcJar.String())
    405 				}
    406 			},
    407 		},
    408 	}
    409 }
    410 
    411 func (ddoc *Droiddoc) AndroidMk() android.AndroidMkData {
    412 	return android.AndroidMkData{
    413 		Class:      "JAVA_LIBRARIES",
    414 		OutputFile: android.OptionalPathForPath(ddoc.stubsSrcJar),
    415 		Include:    "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
    416 		Extra: []android.AndroidMkExtraFunc{
    417 			func(w io.Writer, outputFile android.Path) {
    418 				if BoolDefault(ddoc.Javadoc.properties.Installable, true) && ddoc.Javadoc.docZip != nil {
    419 					fmt.Fprintln(w, "LOCAL_DROIDDOC_DOC_ZIP := ", ddoc.Javadoc.docZip.String())
    420 				}
    421 				if ddoc.Javadoc.stubsSrcJar != nil {
    422 					fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", ddoc.Javadoc.stubsSrcJar.String())
    423 				}
    424 				if ddoc.checkCurrentApiTimestamp != nil {
    425 					fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-current-api")
    426 					fmt.Fprintln(w, ddoc.Name()+"-check-current-api:",
    427 						ddoc.checkCurrentApiTimestamp.String())
    428 
    429 					fmt.Fprintln(w, ".PHONY: checkapi")
    430 					fmt.Fprintln(w, "checkapi:",
    431 						ddoc.checkCurrentApiTimestamp.String())
    432 
    433 					fmt.Fprintln(w, ".PHONY: droidcore")
    434 					fmt.Fprintln(w, "droidcore: checkapi")
    435 				}
    436 				if ddoc.updateCurrentApiTimestamp != nil {
    437 					fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-update-current-api")
    438 					fmt.Fprintln(w, ddoc.Name()+"-update-current-api:",
    439 						ddoc.updateCurrentApiTimestamp.String())
    440 
    441 					fmt.Fprintln(w, ".PHONY: update-api")
    442 					fmt.Fprintln(w, "update-api:",
    443 						ddoc.updateCurrentApiTimestamp.String())
    444 				}
    445 				if ddoc.checkLastReleasedApiTimestamp != nil {
    446 					fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-last-released-api")
    447 					fmt.Fprintln(w, ddoc.Name()+"-check-last-released-api:",
    448 						ddoc.checkLastReleasedApiTimestamp.String())
    449 
    450 					if ddoc.Name() == "api-stubs-docs" || ddoc.Name() == "system-api-stubs-docs" {
    451 						fmt.Fprintln(w, ".PHONY: checkapi")
    452 						fmt.Fprintln(w, "checkapi:",
    453 							ddoc.checkLastReleasedApiTimestamp.String())
    454 
    455 						fmt.Fprintln(w, ".PHONY: droidcore")
    456 						fmt.Fprintln(w, "droidcore: checkapi")
    457 					}
    458 				}
    459 				apiFilePrefix := "INTERNAL_PLATFORM_"
    460 				if String(ddoc.properties.Api_tag_name) != "" {
    461 					apiFilePrefix += String(ddoc.properties.Api_tag_name) + "_"
    462 				}
    463 				if ddoc.apiFile != nil {
    464 					fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", ddoc.apiFile.String())
    465 				}
    466 				if ddoc.dexApiFile != nil {
    467 					fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", ddoc.dexApiFile.String())
    468 				}
    469 				if ddoc.privateApiFile != nil {
    470 					fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", ddoc.privateApiFile.String())
    471 				}
    472 				if ddoc.privateDexApiFile != nil {
    473 					fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", ddoc.privateDexApiFile.String())
    474 				}
    475 				if ddoc.removedApiFile != nil {
    476 					fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", ddoc.removedApiFile.String())
    477 				}
    478 				if ddoc.removedDexApiFile != nil {
    479 					fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", ddoc.removedDexApiFile.String())
    480 				}
    481 				if ddoc.exactApiFile != nil {
    482 					fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", ddoc.exactApiFile.String())
    483 				}
    484 				if ddoc.proguardFile != nil {
    485 					fmt.Fprintln(w, apiFilePrefix+"PROGUARD_FILE := ", ddoc.proguardFile.String())
    486 				}
    487 			},
    488 		},
    489 	}
    490 }
    491 
    492 func (dstubs *Droidstubs) AndroidMk() android.AndroidMkData {
    493 	return android.AndroidMkData{
    494 		Class:      "JAVA_LIBRARIES",
    495 		OutputFile: android.OptionalPathForPath(dstubs.stubsSrcJar),
    496 		Include:    "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk",
    497 		Extra: []android.AndroidMkExtraFunc{
    498 			func(w io.Writer, outputFile android.Path) {
    499 				if dstubs.Javadoc.stubsSrcJar != nil {
    500 					fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", dstubs.Javadoc.stubsSrcJar.String())
    501 				}
    502 				if dstubs.apiVersionsXml != nil {
    503 					fmt.Fprintln(w, "LOCAL_DROIDDOC_API_VERSIONS_XML := ", dstubs.apiVersionsXml.String())
    504 				}
    505 				if dstubs.annotationsZip != nil {
    506 					fmt.Fprintln(w, "LOCAL_DROIDDOC_ANNOTATIONS_ZIP := ", dstubs.annotationsZip.String())
    507 				}
    508 				if dstubs.jdiffDocZip != nil {
    509 					fmt.Fprintln(w, "LOCAL_DROIDDOC_JDIFF_DOC_ZIP := ", dstubs.jdiffDocZip.String())
    510 				}
    511 				if dstubs.checkCurrentApiTimestamp != nil {
    512 					fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api")
    513 					fmt.Fprintln(w, dstubs.Name()+"-check-current-api:",
    514 						dstubs.checkCurrentApiTimestamp.String())
    515 
    516 					fmt.Fprintln(w, ".PHONY: checkapi")
    517 					fmt.Fprintln(w, "checkapi:",
    518 						dstubs.checkCurrentApiTimestamp.String())
    519 
    520 					fmt.Fprintln(w, ".PHONY: droidcore")
    521 					fmt.Fprintln(w, "droidcore: checkapi")
    522 				}
    523 				if dstubs.updateCurrentApiTimestamp != nil {
    524 					fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api")
    525 					fmt.Fprintln(w, dstubs.Name()+"-update-current-api:",
    526 						dstubs.updateCurrentApiTimestamp.String())
    527 
    528 					fmt.Fprintln(w, ".PHONY: update-api")
    529 					fmt.Fprintln(w, "update-api:",
    530 						dstubs.updateCurrentApiTimestamp.String())
    531 				}
    532 				if dstubs.checkLastReleasedApiTimestamp != nil {
    533 					fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api")
    534 					fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
    535 						dstubs.checkLastReleasedApiTimestamp.String())
    536 
    537 					if dstubs.Name() == "api-stubs-docs" || dstubs.Name() == "system-api-stubs-docs" {
    538 						fmt.Fprintln(w, ".PHONY: checkapi")
    539 						fmt.Fprintln(w, "checkapi:",
    540 							dstubs.checkLastReleasedApiTimestamp.String())
    541 
    542 						fmt.Fprintln(w, ".PHONY: droidcore")
    543 						fmt.Fprintln(w, "droidcore: checkapi")
    544 					}
    545 				}
    546 				if dstubs.checkNullabilityWarningsTimestamp != nil {
    547 					fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings")
    548 					fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:",
    549 						dstubs.checkNullabilityWarningsTimestamp.String())
    550 
    551 					fmt.Fprintln(w, ".PHONY:", "droidcore")
    552 					fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings")
    553 				}
    554 				apiFilePrefix := "INTERNAL_PLATFORM_"
    555 				if String(dstubs.properties.Api_tag_name) != "" {
    556 					apiFilePrefix += String(dstubs.properties.Api_tag_name) + "_"
    557 				}
    558 				if dstubs.apiFile != nil {
    559 					fmt.Fprintln(w, apiFilePrefix+"API_FILE := ", dstubs.apiFile.String())
    560 				}
    561 				if dstubs.dexApiFile != nil {
    562 					fmt.Fprintln(w, apiFilePrefix+"DEX_API_FILE := ", dstubs.dexApiFile.String())
    563 				}
    564 				if dstubs.privateApiFile != nil {
    565 					fmt.Fprintln(w, apiFilePrefix+"PRIVATE_API_FILE := ", dstubs.privateApiFile.String())
    566 				}
    567 				if dstubs.privateDexApiFile != nil {
    568 					fmt.Fprintln(w, apiFilePrefix+"PRIVATE_DEX_API_FILE := ", dstubs.privateDexApiFile.String())
    569 				}
    570 				if dstubs.removedApiFile != nil {
    571 					fmt.Fprintln(w, apiFilePrefix+"REMOVED_API_FILE := ", dstubs.removedApiFile.String())
    572 				}
    573 				if dstubs.removedDexApiFile != nil {
    574 					fmt.Fprintln(w, apiFilePrefix+"REMOVED_DEX_API_FILE := ", dstubs.removedDexApiFile.String())
    575 				}
    576 				if dstubs.exactApiFile != nil {
    577 					fmt.Fprintln(w, apiFilePrefix+"EXACT_API_FILE := ", dstubs.exactApiFile.String())
    578 				}
    579 			},
    580 		},
    581 	}
    582 }
    583 
    584 func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
    585 	var testFiles []string
    586 	for _, d := range data {
    587 		testFiles = append(testFiles, d.String()+":"+d.Rel())
    588 	}
    589 	if len(testFiles) > 0 {
    590 		ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
    591 			fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUPPORT_FILES := "+strings.Join(testFiles, " "))
    592 		})
    593 	}
    594 }
    595