androidmk.go 28 KB

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