androidmk.go 28 KB

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