androidmk.go 30 KB

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