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