androidmk.go 29 KB

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