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 15package java 16 17import ( 18 "fmt" 19 "io" 20 21 "android/soong/android" 22) 23 24func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries { 25 hostDexNeeded := Bool(library.deviceProperties.Hostdex) && !library.Host() 26 if library.hideApexVariantFromMake { 27 hostDexNeeded = false 28 } 29 30 if hostDexNeeded { 31 var output android.Path 32 if library.dexJarFile.IsSet() { 33 output = library.dexJarFile.Path() 34 } else { 35 output = library.implementationAndResourcesJar 36 } 37 return android.AndroidMkEntries{ 38 Class: "JAVA_LIBRARIES", 39 SubName: "-hostdex", 40 OutputFile: android.OptionalPathForPath(output), 41 Required: library.deviceProperties.Target.Hostdex.Required, 42 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", 43 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 44 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 45 entries.SetBool("LOCAL_IS_HOST_MODULE", true) 46 entries.SetPath("LOCAL_PREBUILT_MODULE_FILE", output) 47 if library.dexJarFile.IsSet() { 48 entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile.Path()) 49 } 50 entries.SetPath("LOCAL_SOONG_INSTALLED_MODULE", library.hostdexInstallFile) 51 entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile) 52 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar) 53 entries.SetString("LOCAL_MODULE_STEM", library.Stem()+"-hostdex") 54 }, 55 }, 56 } 57 } 58 return android.AndroidMkEntries{Disabled: true} 59} 60 61func (library *Library) AndroidMkEntries() []android.AndroidMkEntries { 62 var entriesList []android.AndroidMkEntries 63 64 if library.Os() == android.Windows { 65 // Make does not support Windows Java modules 66 return nil 67 } 68 69 if library.hideApexVariantFromMake { 70 // For a java library built for an APEX, we don't need a Make module for itself. Otherwise, it 71 // will conflict with the platform variant because they have the same module name in the 72 // makefile. However, we need to add its dexpreopt outputs as sub-modules, if it is preopted. 73 dexpreoptEntries := library.dexpreopter.AndroidMkEntriesForApex() 74 if len(dexpreoptEntries) > 0 { 75 entriesList = append(entriesList, dexpreoptEntries...) 76 } 77 entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true}) 78 } else if !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) { 79 // Platform variant. If not available for the platform, we don't need Make module. 80 entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true}) 81 } else { 82 entriesList = append(entriesList, android.AndroidMkEntries{ 83 Class: "JAVA_LIBRARIES", 84 OutputFile: android.OptionalPathForPath(library.outputFile), 85 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", 86 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 87 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 88 if len(library.logtagsSrcs) > 0 { 89 var logtags []string 90 for _, l := range library.logtagsSrcs { 91 logtags = append(logtags, l.Rel()) 92 } 93 entries.AddStrings("LOCAL_LOGTAGS_FILES", logtags...) 94 } 95 96 if library.installFile == nil { 97 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true) 98 } 99 if library.dexJarFile.IsSet() { 100 entries.SetPath("LOCAL_SOONG_DEX_JAR", library.dexJarFile.Path()) 101 } 102 if len(library.dexpreopter.builtInstalled) > 0 { 103 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", library.dexpreopter.builtInstalled) 104 } 105 entries.SetString("LOCAL_SDK_VERSION", library.sdkVersion.String()) 106 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar) 107 entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile) 108 109 if library.jacocoReportClassesFile != nil { 110 entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", library.jacocoReportClassesFile) 111 } 112 113 requiredUsesLibs, optionalUsesLibs := library.classLoaderContexts.UsesLibs() 114 entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", append(requiredUsesLibs, optionalUsesLibs...)...) 115 116 entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_DICT", library.dexer.proguardDictionary) 117 entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_USAGE_ZIP", library.dexer.proguardUsageZip) 118 entries.SetString("LOCAL_MODULE_STEM", library.Stem()) 119 120 entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", library.linter.reports) 121 122 if library.dexpreopter.configPath != nil { 123 entries.SetPath("LOCAL_SOONG_DEXPREOPT_CONFIG", library.dexpreopter.configPath) 124 } 125 }, 126 }, 127 }) 128 } 129 130 entriesList = append(entriesList, library.AndroidMkEntriesHostDex()) 131 132 return entriesList 133} 134 135// Called for modules that are a component of a test suite. 136func testSuiteComponent(entries *android.AndroidMkEntries, test_suites []string, perTestcaseDirectory bool) { 137 entries.SetString("LOCAL_MODULE_TAGS", "tests") 138 if len(test_suites) > 0 { 139 entries.AddCompatibilityTestSuites(test_suites...) 140 } else { 141 entries.AddCompatibilityTestSuites("null-suite") 142 } 143 entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", perTestcaseDirectory) 144} 145 146func (j *Test) AndroidMkEntries() []android.AndroidMkEntries { 147 entriesList := j.Library.AndroidMkEntries() 148 entries := &entriesList[0] 149 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 150 testSuiteComponent(entries, j.testProperties.Test_suites, Bool(j.testProperties.Per_testcase_directory)) 151 if j.testConfig != nil { 152 entries.SetPath("LOCAL_FULL_TEST_CONFIG", j.testConfig) 153 } 154 androidMkWriteExtraTestConfigs(j.extraTestConfigs, entries) 155 androidMkWriteTestData(j.data, entries) 156 if !BoolDefault(j.testProperties.Auto_gen_config, true) { 157 entries.SetString("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", "true") 158 } 159 entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", j.testProperties.Test_mainline_modules...) 160 if Bool(j.testProperties.Test_options.Unit_test) { 161 entries.SetBool("LOCAL_IS_UNIT_TEST", true) 162 } 163 }) 164 165 return entriesList 166} 167 168func androidMkWriteExtraTestConfigs(extraTestConfigs android.Paths, entries *android.AndroidMkEntries) { 169 if len(extraTestConfigs) > 0 { 170 entries.AddStrings("LOCAL_EXTRA_FULL_TEST_CONFIGS", extraTestConfigs.Strings()...) 171 } 172} 173 174func (j *TestHelperLibrary) AndroidMkEntries() []android.AndroidMkEntries { 175 entriesList := j.Library.AndroidMkEntries() 176 entries := &entriesList[0] 177 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 178 testSuiteComponent(entries, j.testHelperLibraryProperties.Test_suites, Bool(j.testHelperLibraryProperties.Per_testcase_directory)) 179 }) 180 181 return entriesList 182} 183 184func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries { 185 if prebuilt.hideApexVariantFromMake { 186 // For a library imported from a prebuilt APEX, we don't need a Make module for itself, as we 187 // don't need to install it. However, we need to add its dexpreopt outputs as sub-modules, if it 188 // is preopted. 189 dexpreoptEntries := prebuilt.dexpreopter.AndroidMkEntriesForApex() 190 return append(dexpreoptEntries, android.AndroidMkEntries{Disabled: true}) 191 } 192 if !prebuilt.ContainingSdk().Unversioned() { 193 return []android.AndroidMkEntries{android.AndroidMkEntries{ 194 Disabled: true, 195 }} 196 } 197 return []android.AndroidMkEntries{android.AndroidMkEntries{ 198 Class: "JAVA_LIBRARIES", 199 OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile), 200 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", 201 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 202 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 203 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !Bool(prebuilt.properties.Installable)) 204 if prebuilt.dexJarFile.IsSet() { 205 entries.SetPath("LOCAL_SOONG_DEX_JAR", prebuilt.dexJarFile.Path()) 206 } 207 entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.combinedClasspathFile) 208 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.combinedClasspathFile) 209 entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String()) 210 entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem()) 211 }, 212 }, 213 }} 214} 215 216func (prebuilt *DexImport) AndroidMkEntries() []android.AndroidMkEntries { 217 if prebuilt.hideApexVariantFromMake { 218 return []android.AndroidMkEntries{android.AndroidMkEntries{ 219 Disabled: true, 220 }} 221 } 222 return []android.AndroidMkEntries{android.AndroidMkEntries{ 223 Class: "JAVA_LIBRARIES", 224 OutputFile: android.OptionalPathForPath(prebuilt.dexJarFile.Path()), 225 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", 226 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 227 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 228 if prebuilt.dexJarFile.IsSet() { 229 entries.SetPath("LOCAL_SOONG_DEX_JAR", prebuilt.dexJarFile.Path()) 230 } 231 if len(prebuilt.dexpreopter.builtInstalled) > 0 { 232 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", prebuilt.dexpreopter.builtInstalled) 233 } 234 entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem()) 235 }, 236 }, 237 }} 238} 239 240func (prebuilt *AARImport) AndroidMkEntries() []android.AndroidMkEntries { 241 if prebuilt.hideApexVariantFromMake { 242 return []android.AndroidMkEntries{{ 243 Disabled: true, 244 }} 245 } 246 return []android.AndroidMkEntries{android.AndroidMkEntries{ 247 Class: "JAVA_LIBRARIES", 248 OutputFile: android.OptionalPathForPath(prebuilt.classpathFile), 249 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", 250 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 251 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 252 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) 253 entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.classpathFile) 254 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.classpathFile) 255 entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", prebuilt.exportPackage) 256 entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags) 257 entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile) 258 entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest) 259 entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String()) 260 }, 261 }, 262 }} 263} 264 265func (binary *Binary) AndroidMkEntries() []android.AndroidMkEntries { 266 if binary.Os() == android.Windows { 267 // Make does not support Windows Java modules 268 return nil 269 } 270 271 if !binary.isWrapperVariant { 272 return []android.AndroidMkEntries{android.AndroidMkEntries{ 273 Class: "JAVA_LIBRARIES", 274 OutputFile: android.OptionalPathForPath(binary.outputFile), 275 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", 276 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 277 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 278 entries.SetPath("LOCAL_SOONG_HEADER_JAR", binary.headerJarFile) 279 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", binary.implementationAndResourcesJar) 280 if binary.dexJarFile.IsSet() { 281 entries.SetPath("LOCAL_SOONG_DEX_JAR", binary.dexJarFile.Path()) 282 } 283 if len(binary.dexpreopter.builtInstalled) > 0 { 284 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", binary.dexpreopter.builtInstalled) 285 } 286 }, 287 }, 288 ExtraFooters: []android.AndroidMkExtraFootersFunc{ 289 func(w io.Writer, name, prefix, moduleDir string) { 290 fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)") 291 }, 292 }, 293 }} 294 } else { 295 outputFile := binary.wrapperFile 296 297 return []android.AndroidMkEntries{android.AndroidMkEntries{ 298 Class: "EXECUTABLES", 299 OutputFile: android.OptionalPathForPath(outputFile), 300 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 301 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 302 entries.SetBool("LOCAL_STRIP_MODULE", false) 303 }, 304 }, 305 ExtraFooters: []android.AndroidMkExtraFootersFunc{ 306 func(w io.Writer, name, prefix, moduleDir string) { 307 // Ensure that the wrapper script timestamp is always updated when the jar is updated 308 fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)") 309 fmt.Fprintln(w, "jar_installed_module :=") 310 }, 311 }, 312 }} 313 } 314} 315 316func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries { 317 if app.hideApexVariantFromMake || app.IsHideFromMake() { 318 return []android.AndroidMkEntries{android.AndroidMkEntries{ 319 Disabled: true, 320 }} 321 } 322 return []android.AndroidMkEntries{android.AndroidMkEntries{ 323 Class: "APPS", 324 OutputFile: android.OptionalPathForPath(app.outputFile), 325 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk", 326 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 327 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 328 // App module names can be overridden. 329 entries.SetString("LOCAL_MODULE", app.installApkName) 330 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", app.appProperties.PreventInstall) 331 entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", app.exportPackage) 332 if app.dexJarFile.IsSet() { 333 entries.SetPath("LOCAL_SOONG_DEX_JAR", app.dexJarFile.Path()) 334 } 335 if app.implementationAndResourcesJar != nil { 336 entries.SetPath("LOCAL_SOONG_CLASSES_JAR", app.implementationAndResourcesJar) 337 } 338 if app.headerJarFile != nil { 339 entries.SetPath("LOCAL_SOONG_HEADER_JAR", app.headerJarFile) 340 } 341 if app.bundleFile != nil { 342 entries.SetPath("LOCAL_SOONG_BUNDLE", app.bundleFile) 343 } 344 if app.jacocoReportClassesFile != nil { 345 entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", app.jacocoReportClassesFile) 346 } 347 entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_DICT", app.dexer.proguardDictionary) 348 entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_USAGE_ZIP", app.dexer.proguardUsageZip) 349 350 if app.Name() == "framework-res" { 351 entries.SetString("LOCAL_MODULE_PATH", "$(TARGET_OUT_JAVA_LIBRARIES)") 352 // Make base_rules.mk not put framework-res in a subdirectory called 353 // framework_res. 354 entries.SetBoolIfTrue("LOCAL_NO_STANDARD_LIBRARIES", true) 355 } 356 357 filterRRO := func(filter overlayType) android.Paths { 358 var paths android.Paths 359 for _, d := range app.rroDirs { 360 if d.overlayType == filter { 361 paths = append(paths, d.path) 362 } 363 } 364 // Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make 365 // expects it in LOCAL_RESOURCE_DIRS order (high to low priority). 366 return android.ReversePaths(paths) 367 } 368 deviceRRODirs := filterRRO(device) 369 if len(deviceRRODirs) > 0 { 370 entries.AddStrings("LOCAL_SOONG_DEVICE_RRO_DIRS", deviceRRODirs.Strings()...) 371 } 372 productRRODirs := filterRRO(product) 373 if len(productRRODirs) > 0 { 374 entries.AddStrings("LOCAL_SOONG_PRODUCT_RRO_DIRS", productRRODirs.Strings()...) 375 } 376 377 entries.SetBoolIfTrue("LOCAL_EXPORT_PACKAGE_RESOURCES", Bool(app.appProperties.Export_package_resources)) 378 379 entries.SetPath("LOCAL_FULL_MANIFEST_FILE", app.manifestPath) 380 381 entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", app.Privileged()) 382 383 entries.SetString("LOCAL_CERTIFICATE", app.certificate.AndroidMkString()) 384 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", app.getOverriddenPackages()...) 385 386 if app.embeddedJniLibs { 387 jniSymbols := app.JNISymbolsInstalls(app.installPathForJNISymbols.String()) 388 entries.SetString("LOCAL_SOONG_JNI_LIBS_SYMBOLS", jniSymbols.String()) 389 } else { 390 for _, jniLib := range app.jniLibs { 391 entries.AddStrings("LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), jniLib.name) 392 } 393 } 394 395 if len(app.jniCoverageOutputs) > 0 { 396 entries.AddStrings("LOCAL_PREBUILT_COVERAGE_ARCHIVE", app.jniCoverageOutputs.Strings()...) 397 } 398 if len(app.dexpreopter.builtInstalled) > 0 { 399 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", app.dexpreopter.builtInstalled) 400 } 401 if app.dexpreopter.configPath != nil { 402 entries.SetPath("LOCAL_SOONG_DEXPREOPT_CONFIG", app.dexpreopter.configPath) 403 } 404 for _, extra := range app.extraOutputFiles { 405 install := app.onDeviceDir + "/" + extra.Base() 406 entries.AddStrings("LOCAL_SOONG_BUILT_INSTALLED", extra.String()+":"+install) 407 } 408 409 entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", app.linter.reports) 410 }, 411 }, 412 ExtraFooters: []android.AndroidMkExtraFootersFunc{ 413 func(w io.Writer, name, prefix, moduleDir string) { 414 if app.javaApiUsedByOutputFile.String() != "" { 415 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s/$(notdir %s))\n", 416 app.installApkName, app.javaApiUsedByOutputFile.String(), "java_apis_used_by_apex", app.javaApiUsedByOutputFile.String()) 417 } 418 }, 419 }}, 420 } 421} 422 423func (a *AndroidApp) getOverriddenPackages() []string { 424 var overridden []string 425 if len(a.overridableAppProperties.Overrides) > 0 { 426 overridden = append(overridden, a.overridableAppProperties.Overrides...) 427 } 428 // When APK name is overridden via PRODUCT_PACKAGE_NAME_OVERRIDES 429 // ensure that the original name is overridden. 430 if a.Stem() != a.installApkName { 431 overridden = append(overridden, a.Stem()) 432 } 433 return overridden 434} 435 436func (a *AndroidTest) AndroidMkEntries() []android.AndroidMkEntries { 437 entriesList := a.AndroidApp.AndroidMkEntries() 438 entries := &entriesList[0] 439 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 440 testSuiteComponent(entries, a.testProperties.Test_suites, Bool(a.testProperties.Per_testcase_directory)) 441 if a.testConfig != nil { 442 entries.SetPath("LOCAL_FULL_TEST_CONFIG", a.testConfig) 443 } 444 androidMkWriteExtraTestConfigs(a.extraTestConfigs, entries) 445 androidMkWriteTestData(a.data, entries) 446 entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", a.testProperties.Test_mainline_modules...) 447 }) 448 449 return entriesList 450} 451 452func (a *AndroidTestHelperApp) AndroidMkEntries() []android.AndroidMkEntries { 453 entriesList := a.AndroidApp.AndroidMkEntries() 454 entries := &entriesList[0] 455 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 456 testSuiteComponent(entries, a.appTestHelperAppProperties.Test_suites, Bool(a.appTestHelperAppProperties.Per_testcase_directory)) 457 // introduce a flag variable to control the generation of the .config file 458 entries.SetString("LOCAL_DISABLE_TEST_CONFIG", "true") 459 }) 460 461 return entriesList 462} 463 464func (a *AndroidLibrary) AndroidMkEntries() []android.AndroidMkEntries { 465 if a.hideApexVariantFromMake { 466 return []android.AndroidMkEntries{{ 467 Disabled: true, 468 }} 469 } 470 entriesList := a.Library.AndroidMkEntries() 471 entries := &entriesList[0] 472 473 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 474 if a.aarFile != nil { 475 entries.SetPath("LOCAL_SOONG_AAR", a.aarFile) 476 } 477 478 if a.Name() == "framework-res" { 479 entries.SetString("LOCAL_MODULE_PATH", "$(TARGET_OUT_JAVA_LIBRARIES)") 480 // Make base_rules.mk not put framework-res in a subdirectory called 481 // framework_res. 482 entries.SetBoolIfTrue("LOCAL_NO_STANDARD_LIBRARIES", true) 483 } 484 485 entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", a.exportPackage) 486 entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", a.extraAaptPackagesFile) 487 entries.SetPath("LOCAL_FULL_MANIFEST_FILE", a.mergedManifestFile) 488 entries.AddStrings("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", a.exportedProguardFlagFiles.Strings()...) 489 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true) 490 }) 491 492 return entriesList 493} 494 495func (jd *Javadoc) AndroidMkEntries() []android.AndroidMkEntries { 496 return []android.AndroidMkEntries{android.AndroidMkEntries{ 497 Class: "JAVA_LIBRARIES", 498 OutputFile: android.OptionalPathForPath(jd.stubsSrcJar), 499 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk", 500 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 501 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 502 if BoolDefault(jd.properties.Installable, true) { 503 entries.SetPath("LOCAL_DROIDDOC_DOC_ZIP", jd.docZip) 504 } 505 if jd.stubsSrcJar != nil { 506 entries.SetPath("LOCAL_DROIDDOC_STUBS_SRCJAR", jd.stubsSrcJar) 507 } 508 }, 509 }, 510 }} 511} 512 513func (ddoc *Droiddoc) AndroidMkEntries() []android.AndroidMkEntries { 514 return []android.AndroidMkEntries{android.AndroidMkEntries{ 515 Class: "JAVA_LIBRARIES", 516 OutputFile: android.OptionalPathForPath(ddoc.Javadoc.docZip), 517 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk", 518 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 519 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 520 if ddoc.Javadoc.docZip != nil { 521 entries.SetPath("LOCAL_DROIDDOC_DOC_ZIP", ddoc.Javadoc.docZip) 522 } 523 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !BoolDefault(ddoc.Javadoc.properties.Installable, true)) 524 }, 525 }, 526 }} 527} 528 529func (dstubs *Droidstubs) AndroidMkEntries() []android.AndroidMkEntries { 530 // If the stubsSrcJar is not generated (because generate_stubs is false) then 531 // use the api file as the output file to ensure the relevant phony targets 532 // are created in make if only the api txt file is being generated. This is 533 // needed because an invalid output file would prevent the make entries from 534 // being written. 535 // 536 // Note that dstubs.apiFile can be also be nil if WITHOUT_CHECKS_API is true. 537 // TODO(b/146727827): Revert when we do not need to generate stubs and API separately. 538 539 outputFile := android.OptionalPathForPath(dstubs.stubsSrcJar) 540 if !outputFile.Valid() { 541 outputFile = android.OptionalPathForPath(dstubs.apiFile) 542 } 543 return []android.AndroidMkEntries{android.AndroidMkEntries{ 544 Class: "JAVA_LIBRARIES", 545 OutputFile: outputFile, 546 Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk", 547 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 548 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 549 if dstubs.Javadoc.stubsSrcJar != nil { 550 entries.SetPath("LOCAL_DROIDDOC_STUBS_SRCJAR", dstubs.Javadoc.stubsSrcJar) 551 } 552 if dstubs.apiVersionsXml != nil { 553 entries.SetPath("LOCAL_DROIDDOC_API_VERSIONS_XML", dstubs.apiVersionsXml) 554 } 555 if dstubs.annotationsZip != nil { 556 entries.SetPath("LOCAL_DROIDDOC_ANNOTATIONS_ZIP", dstubs.annotationsZip) 557 } 558 if dstubs.metadataZip != nil { 559 entries.SetPath("LOCAL_DROIDDOC_METADATA_ZIP", dstubs.metadataZip) 560 } 561 }, 562 }, 563 ExtraFooters: []android.AndroidMkExtraFootersFunc{ 564 func(w io.Writer, name, prefix, moduleDir string) { 565 if dstubs.apiFile != nil { 566 fmt.Fprintf(w, ".PHONY: %s %s.txt\n", dstubs.Name(), dstubs.Name()) 567 fmt.Fprintf(w, "%s %s.txt: %s\n", dstubs.Name(), dstubs.Name(), dstubs.apiFile) 568 } 569 if dstubs.removedApiFile != nil { 570 fmt.Fprintf(w, ".PHONY: %s %s.txt\n", dstubs.Name(), dstubs.Name()) 571 fmt.Fprintf(w, "%s %s.txt: %s\n", dstubs.Name(), dstubs.Name(), dstubs.removedApiFile) 572 } 573 if dstubs.checkCurrentApiTimestamp != nil { 574 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api") 575 fmt.Fprintln(w, dstubs.Name()+"-check-current-api:", 576 dstubs.checkCurrentApiTimestamp.String()) 577 578 fmt.Fprintln(w, ".PHONY: checkapi") 579 fmt.Fprintln(w, "checkapi:", 580 dstubs.checkCurrentApiTimestamp.String()) 581 582 fmt.Fprintln(w, ".PHONY: droidcore") 583 fmt.Fprintln(w, "droidcore: checkapi") 584 } 585 if dstubs.updateCurrentApiTimestamp != nil { 586 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-update-current-api") 587 fmt.Fprintln(w, dstubs.Name()+"-update-current-api:", 588 dstubs.updateCurrentApiTimestamp.String()) 589 590 fmt.Fprintln(w, ".PHONY: update-api") 591 fmt.Fprintln(w, "update-api:", 592 dstubs.updateCurrentApiTimestamp.String()) 593 } 594 if dstubs.checkLastReleasedApiTimestamp != nil { 595 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-last-released-api") 596 fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:", 597 dstubs.checkLastReleasedApiTimestamp.String()) 598 599 fmt.Fprintln(w, ".PHONY: checkapi") 600 fmt.Fprintln(w, "checkapi:", 601 dstubs.checkLastReleasedApiTimestamp.String()) 602 603 fmt.Fprintln(w, ".PHONY: droidcore") 604 fmt.Fprintln(w, "droidcore: checkapi") 605 } 606 if dstubs.apiLintTimestamp != nil { 607 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-api-lint") 608 fmt.Fprintln(w, dstubs.Name()+"-api-lint:", 609 dstubs.apiLintTimestamp.String()) 610 611 fmt.Fprintln(w, ".PHONY: checkapi") 612 fmt.Fprintln(w, "checkapi:", 613 dstubs.Name()+"-api-lint") 614 615 fmt.Fprintln(w, ".PHONY: droidcore") 616 fmt.Fprintln(w, "droidcore: checkapi") 617 618 if dstubs.apiLintReport != nil { 619 fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", dstubs.Name()+"-api-lint", 620 dstubs.apiLintReport.String(), "apilint/"+dstubs.Name()+"-lint-report.txt") 621 } 622 } 623 if dstubs.checkNullabilityWarningsTimestamp != nil { 624 fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-nullability-warnings") 625 fmt.Fprintln(w, dstubs.Name()+"-check-nullability-warnings:", 626 dstubs.checkNullabilityWarningsTimestamp.String()) 627 628 fmt.Fprintln(w, ".PHONY:", "droidcore") 629 fmt.Fprintln(w, "droidcore: ", dstubs.Name()+"-check-nullability-warnings") 630 } 631 }, 632 }, 633 }} 634} 635 636func (a *AndroidAppImport) AndroidMkEntries() []android.AndroidMkEntries { 637 if a.hideApexVariantFromMake { 638 // The non-platform variant is placed inside APEX. No reason to 639 // make it available to Make. 640 return nil 641 } 642 return []android.AndroidMkEntries{android.AndroidMkEntries{ 643 Class: "APPS", 644 OutputFile: android.OptionalPathForPath(a.outputFile), 645 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk", 646 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 647 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 648 entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", a.Privileged()) 649 entries.SetString("LOCAL_CERTIFICATE", a.certificate.AndroidMkString()) 650 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", a.properties.Overrides...) 651 if len(a.dexpreopter.builtInstalled) > 0 { 652 entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", a.dexpreopter.builtInstalled) 653 } 654 entries.AddStrings("LOCAL_INSTALLED_MODULE_STEM", a.installPath.Rel()) 655 if Bool(a.properties.Export_package_resources) { 656 entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", a.outputFile) 657 } 658 }, 659 }, 660 }} 661} 662 663func (a *AndroidTestImport) AndroidMkEntries() []android.AndroidMkEntries { 664 entriesList := a.AndroidAppImport.AndroidMkEntries() 665 entries := &entriesList[0] 666 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 667 testSuiteComponent(entries, a.testProperties.Test_suites, Bool(a.testProperties.Per_testcase_directory)) 668 androidMkWriteTestData(a.data, entries) 669 }) 670 return entriesList 671} 672 673func androidMkWriteTestData(data android.Paths, entries *android.AndroidMkEntries) { 674 var testFiles []string 675 for _, d := range data { 676 testFiles = append(testFiles, d.String()+":"+d.Rel()) 677 } 678 entries.AddStrings("LOCAL_COMPATIBILITY_SUPPORT_FILES", testFiles...) 679} 680 681func (r *RuntimeResourceOverlay) AndroidMkEntries() []android.AndroidMkEntries { 682 return []android.AndroidMkEntries{android.AndroidMkEntries{ 683 Class: "ETC", 684 OutputFile: android.OptionalPathForPath(r.outputFile), 685 Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk", 686 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 687 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 688 entries.SetString("LOCAL_CERTIFICATE", r.certificate.AndroidMkString()) 689 entries.SetPath("LOCAL_MODULE_PATH", r.installDir) 690 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", r.properties.Overrides...) 691 }, 692 }, 693 }} 694} 695 696func (apkSet *AndroidAppSet) AndroidMkEntries() []android.AndroidMkEntries { 697 return []android.AndroidMkEntries{ 698 android.AndroidMkEntries{ 699 Class: "APPS", 700 OutputFile: android.OptionalPathForPath(apkSet.primaryOutput), 701 Include: "$(BUILD_SYSTEM)/soong_android_app_set.mk", 702 ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 703 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 704 entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", apkSet.Privileged()) 705 entries.SetPath("LOCAL_APK_SET_INSTALL_FILE", apkSet.PackedAdditionalOutputs()) 706 entries.SetPath("LOCAL_APKCERTS_FILE", apkSet.apkcertsFile) 707 entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", apkSet.properties.Overrides...) 708 }, 709 }, 710 }, 711 } 712} 713