androidmk.go 29 KB

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