androidmk.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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 cc
  15. import (
  16. "github.com/google/blueprint/proptools"
  17. "fmt"
  18. "io"
  19. "path/filepath"
  20. "strings"
  21. "android/soong/android"
  22. "android/soong/multitree"
  23. )
  24. var (
  25. NativeBridgeSuffix = ".native_bridge"
  26. ProductSuffix = ".product"
  27. VendorSuffix = ".vendor"
  28. RamdiskSuffix = ".ramdisk"
  29. VendorRamdiskSuffix = ".vendor_ramdisk"
  30. RecoverySuffix = ".recovery"
  31. sdkSuffix = ".sdk"
  32. )
  33. type AndroidMkContext interface {
  34. BaseModuleName() string
  35. Target() android.Target
  36. subAndroidMk(*android.AndroidMkEntries, interface{})
  37. Arch() android.Arch
  38. Os() android.OsType
  39. Host() bool
  40. UseVndk() bool
  41. VndkVersion() string
  42. static() bool
  43. InRamdisk() bool
  44. InVendorRamdisk() bool
  45. InRecovery() bool
  46. NotInPlatform() bool
  47. }
  48. type subAndroidMkProvider interface {
  49. AndroidMkEntries(AndroidMkContext, *android.AndroidMkEntries)
  50. }
  51. func (c *Module) subAndroidMk(entries *android.AndroidMkEntries, obj interface{}) {
  52. if c.subAndroidMkOnce == nil {
  53. c.subAndroidMkOnce = make(map[subAndroidMkProvider]bool)
  54. }
  55. if androidmk, ok := obj.(subAndroidMkProvider); ok {
  56. if !c.subAndroidMkOnce[androidmk] {
  57. c.subAndroidMkOnce[androidmk] = true
  58. androidmk.AndroidMkEntries(c, entries)
  59. }
  60. }
  61. }
  62. func (c *Module) AndroidMkEntries() []android.AndroidMkEntries {
  63. if c.hideApexVariantFromMake || c.Properties.HideFromMake {
  64. return []android.AndroidMkEntries{{
  65. Disabled: true,
  66. }}
  67. }
  68. entries := android.AndroidMkEntries{
  69. OutputFile: c.outputFile,
  70. // TODO(jiyong): add the APEXes providing shared libs to the required
  71. // modules Currently, adding c.Properties.ApexesProvidingSharedLibs is
  72. // causing multiple ART APEXes (com.android.art and com.android.art.debug)
  73. // to be installed. And this is breaking some older devices (like marlin)
  74. // where system.img is small.
  75. Required: c.Properties.AndroidMkRuntimeLibs,
  76. Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk",
  77. ExtraEntries: []android.AndroidMkExtraEntriesFunc{
  78. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  79. if len(c.Properties.Logtags) > 0 {
  80. entries.AddStrings("LOCAL_LOGTAGS_FILES", c.Properties.Logtags...)
  81. }
  82. // Note: Pass the exact value of AndroidMkSystemSharedLibs to the Make
  83. // world, even if it is an empty list. In the Make world,
  84. // LOCAL_SYSTEM_SHARED_LIBRARIES defaults to "none", which is expanded
  85. // to the default list of system shared libs by the build system.
  86. // Soong computes the exact list of system shared libs, so we have to
  87. // override the default value when the list of libs is actually empty.
  88. entries.SetString("LOCAL_SYSTEM_SHARED_LIBRARIES", strings.Join(c.Properties.AndroidMkSystemSharedLibs, " "))
  89. if len(c.Properties.AndroidMkSharedLibs) > 0 {
  90. entries.AddStrings("LOCAL_SHARED_LIBRARIES", c.Properties.AndroidMkSharedLibs...)
  91. }
  92. if len(c.Properties.AndroidMkStaticLibs) > 0 {
  93. entries.AddStrings("LOCAL_STATIC_LIBRARIES", c.Properties.AndroidMkStaticLibs...)
  94. }
  95. if len(c.Properties.AndroidMkWholeStaticLibs) > 0 {
  96. entries.AddStrings("LOCAL_WHOLE_STATIC_LIBRARIES", c.Properties.AndroidMkWholeStaticLibs...)
  97. }
  98. if len(c.Properties.AndroidMkHeaderLibs) > 0 {
  99. entries.AddStrings("LOCAL_HEADER_LIBRARIES", c.Properties.AndroidMkHeaderLibs...)
  100. }
  101. if len(c.Properties.AndroidMkRuntimeLibs) > 0 {
  102. entries.AddStrings("LOCAL_RUNTIME_LIBRARIES", c.Properties.AndroidMkRuntimeLibs...)
  103. }
  104. entries.SetString("LOCAL_SOONG_LINK_TYPE", c.makeLinkType)
  105. if c.UseVndk() {
  106. entries.SetBool("LOCAL_USE_VNDK", true)
  107. if c.IsVndk() && !c.static() {
  108. entries.SetString("LOCAL_SOONG_VNDK_VERSION", c.VndkVersion())
  109. // VNDK libraries available to vendor are not installed because
  110. // they are packaged in VNDK APEX and installed by APEX packages (apex/apex.go)
  111. if !c.IsVndkExt() {
  112. entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
  113. }
  114. }
  115. }
  116. if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
  117. // Make the SDK variant uninstallable so that there are not two rules to install
  118. // to the same location.
  119. entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
  120. // Add the unsuffixed name to SOONG_SDK_VARIANT_MODULES so that Make can rewrite
  121. // dependencies to the .sdk suffix when building a module that uses the SDK.
  122. entries.SetString("SOONG_SDK_VARIANT_MODULES",
  123. "$(SOONG_SDK_VARIANT_MODULES) $(patsubst %.sdk,%,$(LOCAL_MODULE))")
  124. }
  125. },
  126. },
  127. ExtraFooters: []android.AndroidMkExtraFootersFunc{
  128. func(w io.Writer, name, prefix, moduleDir string) {
  129. if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake &&
  130. c.CcLibraryInterface() && c.Shared() {
  131. // Using the SDK variant as a JNI library needs a copy of the .so that
  132. // is not named .sdk.so so that it can be packaged into the APK with
  133. // the right name.
  134. fmt.Fprintln(w, "$(eval $(call copy-one-file,",
  135. "$(LOCAL_BUILT_MODULE),",
  136. "$(patsubst %.sdk.so,%.so,$(LOCAL_BUILT_MODULE))))")
  137. }
  138. },
  139. },
  140. }
  141. for _, feature := range c.features {
  142. c.subAndroidMk(&entries, feature)
  143. }
  144. c.subAndroidMk(&entries, c.compiler)
  145. c.subAndroidMk(&entries, c.linker)
  146. if c.sanitize != nil {
  147. c.subAndroidMk(&entries, c.sanitize)
  148. }
  149. c.subAndroidMk(&entries, c.installer)
  150. entries.SubName += c.Properties.SubName
  151. return []android.AndroidMkEntries{entries}
  152. }
  153. func androidMkWriteExtraTestConfigs(extraTestConfigs android.Paths, entries *android.AndroidMkEntries) {
  154. if len(extraTestConfigs) > 0 {
  155. entries.ExtraEntries = append(entries.ExtraEntries,
  156. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  157. entries.AddStrings("LOCAL_EXTRA_FULL_TEST_CONFIGS", extraTestConfigs.Strings()...)
  158. })
  159. }
  160. }
  161. func AndroidMkWriteTestData(data []android.DataPath, entries *android.AndroidMkEntries) {
  162. testFiles := android.AndroidMkDataPaths(data)
  163. if len(testFiles) > 0 {
  164. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  165. entries.AddStrings("LOCAL_TEST_DATA", testFiles...)
  166. })
  167. }
  168. }
  169. func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string {
  170. if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
  171. var result []string
  172. for _, override := range overrides {
  173. result = append(result, override+NativeBridgeSuffix)
  174. }
  175. return result
  176. }
  177. return overrides
  178. }
  179. func (library *libraryDecorator) androidMkWriteExportedFlags(entries *android.AndroidMkEntries) {
  180. var exportedFlags []string
  181. var includeDirs android.Paths
  182. var systemIncludeDirs android.Paths
  183. var exportedDeps android.Paths
  184. if library.flagExporterInfo != nil {
  185. exportedFlags = library.flagExporterInfo.Flags
  186. includeDirs = library.flagExporterInfo.IncludeDirs
  187. systemIncludeDirs = library.flagExporterInfo.SystemIncludeDirs
  188. exportedDeps = library.flagExporterInfo.Deps
  189. } else {
  190. exportedFlags = library.flagExporter.flags
  191. includeDirs = library.flagExporter.dirs
  192. systemIncludeDirs = library.flagExporter.systemDirs
  193. exportedDeps = library.flagExporter.deps
  194. }
  195. for _, dir := range includeDirs {
  196. exportedFlags = append(exportedFlags, "-I"+dir.String())
  197. }
  198. for _, dir := range systemIncludeDirs {
  199. exportedFlags = append(exportedFlags, "-isystem "+dir.String())
  200. }
  201. if len(exportedFlags) > 0 {
  202. entries.AddStrings("LOCAL_EXPORT_CFLAGS", exportedFlags...)
  203. }
  204. if len(exportedDeps) > 0 {
  205. entries.AddStrings("LOCAL_EXPORT_C_INCLUDE_DEPS", exportedDeps.Strings()...)
  206. }
  207. }
  208. func (library *libraryDecorator) androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries *android.AndroidMkEntries) {
  209. if !library.static() {
  210. entries.AddPaths("LOCAL_ADDITIONAL_DEPENDENCIES", library.sAbiDiff)
  211. }
  212. }
  213. // TODO(ccross): remove this once apex/androidmk.go is converted to AndroidMkEntries
  214. func (library *libraryDecorator) androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
  215. if !library.static() {
  216. fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES +=", strings.Join(library.sAbiDiff.Strings(), " "))
  217. }
  218. }
  219. func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  220. if library.static() {
  221. entries.Class = "STATIC_LIBRARIES"
  222. } else if library.shared() {
  223. entries.Class = "SHARED_LIBRARIES"
  224. entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  225. entries.SetString("LOCAL_SOONG_TOC", library.toc().String())
  226. if !library.buildStubs() && library.unstrippedOutputFile != nil {
  227. entries.SetString("LOCAL_SOONG_UNSTRIPPED_BINARY", library.unstrippedOutputFile.String())
  228. }
  229. if len(library.Properties.Overrides) > 0 {
  230. entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, library.Properties.Overrides), " "))
  231. }
  232. if len(library.postInstallCmds) > 0 {
  233. entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(library.postInstallCmds, "&& "))
  234. }
  235. })
  236. } else if library.header() {
  237. entries.Class = "HEADER_LIBRARIES"
  238. }
  239. if library.distFile != nil {
  240. entries.DistFiles = android.MakeDefaultDistFiles(library.distFile)
  241. }
  242. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  243. library.androidMkWriteExportedFlags(entries)
  244. library.androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries)
  245. if entries.OutputFile.Valid() {
  246. _, _, ext := android.SplitFileExt(entries.OutputFile.Path().Base())
  247. entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
  248. }
  249. if library.coverageOutputFile.Valid() {
  250. entries.SetString("LOCAL_PREBUILT_COVERAGE_ARCHIVE", library.coverageOutputFile.String())
  251. }
  252. if library.useCoreVariant {
  253. entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
  254. entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
  255. entries.SetBool("LOCAL_VNDK_DEPEND_ON_CORE_VARIANT", true)
  256. }
  257. if library.checkSameCoreVariant {
  258. entries.SetBool("LOCAL_CHECK_SAME_VNDK_VARIANTS", true)
  259. }
  260. })
  261. if library.shared() && !library.buildStubs() {
  262. ctx.subAndroidMk(entries, library.baseInstaller)
  263. } else {
  264. if library.buildStubs() && library.stubsVersion() != "" {
  265. entries.SubName = "." + library.stubsVersion()
  266. }
  267. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  268. // library.makeUninstallable() depends on this to bypass HideFromMake() for
  269. // static libraries.
  270. entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
  271. if library.buildStubs() {
  272. entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
  273. }
  274. })
  275. }
  276. // If a library providing a stub is included in an APEX, the private APIs of the library
  277. // is accessible only inside the APEX. From outside of the APEX, clients can only use the
  278. // public APIs via the stub. To enforce this, the (latest version of the) stub gets the
  279. // name of the library. The impl library instead gets the `.bootstrap` suffix to so that
  280. // they can be exceptionally used directly when APEXes are not available (e.g. during the
  281. // very early stage in the boot process).
  282. if len(library.Properties.Stubs.Versions) > 0 && !ctx.Host() && ctx.NotInPlatform() &&
  283. !ctx.InRamdisk() && !ctx.InVendorRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() && !ctx.static() {
  284. if library.buildStubs() && library.isLatestStubVersion() {
  285. entries.SubName = ""
  286. }
  287. if !library.buildStubs() {
  288. entries.SubName = ".bootstrap"
  289. }
  290. }
  291. }
  292. func (object *objectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  293. entries.Class = "STATIC_LIBRARIES"
  294. entries.ExtraFooters = append(entries.ExtraFooters,
  295. func(w io.Writer, name, prefix, moduleDir string) {
  296. out := entries.OutputFile.Path()
  297. varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, entries.SubName)
  298. fmt.Fprintf(w, "\n%s := %s\n", varname, out.String())
  299. fmt.Fprintln(w, ".KATI_READONLY: "+varname)
  300. })
  301. }
  302. func (test *testDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  303. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  304. if len(test.InstallerProperties.Test_suites) > 0 {
  305. entries.AddCompatibilityTestSuites(test.InstallerProperties.Test_suites...)
  306. }
  307. })
  308. }
  309. func (binary *binaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  310. ctx.subAndroidMk(entries, binary.baseInstaller)
  311. entries.Class = "EXECUTABLES"
  312. entries.DistFiles = binary.distFiles
  313. entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  314. entries.SetString("LOCAL_SOONG_UNSTRIPPED_BINARY", binary.unstrippedOutputFile.String())
  315. if len(binary.symlinks) > 0 {
  316. entries.AddStrings("LOCAL_MODULE_SYMLINKS", binary.symlinks...)
  317. }
  318. if binary.coverageOutputFile.Valid() {
  319. entries.SetString("LOCAL_PREBUILT_COVERAGE_ARCHIVE", binary.coverageOutputFile.String())
  320. }
  321. if len(binary.Properties.Overrides) > 0 {
  322. entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, binary.Properties.Overrides), " "))
  323. }
  324. if len(binary.postInstallCmds) > 0 {
  325. entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(binary.postInstallCmds, "&& "))
  326. }
  327. })
  328. }
  329. func (benchmark *benchmarkDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  330. ctx.subAndroidMk(entries, benchmark.binaryDecorator)
  331. entries.Class = "NATIVE_TESTS"
  332. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  333. if len(benchmark.Properties.Test_suites) > 0 {
  334. entries.AddCompatibilityTestSuites(benchmark.Properties.Test_suites...)
  335. }
  336. if benchmark.testConfig != nil {
  337. entries.SetString("LOCAL_FULL_TEST_CONFIG", benchmark.testConfig.String())
  338. }
  339. entries.SetBool("LOCAL_NATIVE_BENCHMARK", true)
  340. if !BoolDefault(benchmark.Properties.Auto_gen_config, true) {
  341. entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
  342. }
  343. })
  344. dataPaths := []android.DataPath{}
  345. for _, srcPath := range benchmark.data {
  346. dataPaths = append(dataPaths, android.DataPath{SrcPath: srcPath})
  347. }
  348. AndroidMkWriteTestData(dataPaths, entries)
  349. }
  350. func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  351. ctx.subAndroidMk(entries, test.binaryDecorator)
  352. ctx.subAndroidMk(entries, test.testDecorator)
  353. entries.Class = "NATIVE_TESTS"
  354. if Bool(test.Properties.Test_per_src) {
  355. entries.SubName = "_" + String(test.binaryDecorator.Properties.Stem)
  356. }
  357. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  358. if test.testConfig != nil {
  359. entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String())
  360. }
  361. if !BoolDefault(test.Properties.Auto_gen_config, true) {
  362. entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
  363. }
  364. entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", test.Properties.Test_mainline_modules...)
  365. entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(test.Properties.Per_testcase_directory))
  366. if len(test.Properties.Data_bins) > 0 {
  367. entries.AddStrings("LOCAL_TEST_DATA_BINS", test.Properties.Data_bins...)
  368. }
  369. test.Properties.Test_options.CommonTestOptions.SetAndroidMkEntries(entries)
  370. })
  371. AndroidMkWriteTestData(test.data, entries)
  372. androidMkWriteExtraTestConfigs(test.extraTestConfigs, entries)
  373. }
  374. func (fuzz *fuzzBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  375. ctx.subAndroidMk(entries, fuzz.binaryDecorator)
  376. var fuzzFiles []string
  377. for _, d := range fuzz.fuzzPackagedModule.Corpus {
  378. fuzzFiles = append(fuzzFiles,
  379. filepath.Dir(fuzz.fuzzPackagedModule.CorpusIntermediateDir.String())+":corpus/"+d.Base())
  380. }
  381. for _, d := range fuzz.fuzzPackagedModule.Data {
  382. fuzzFiles = append(fuzzFiles,
  383. filepath.Dir(fuzz.fuzzPackagedModule.DataIntermediateDir.String())+":data/"+d.Rel())
  384. }
  385. if fuzz.fuzzPackagedModule.Dictionary != nil {
  386. fuzzFiles = append(fuzzFiles,
  387. filepath.Dir(fuzz.fuzzPackagedModule.Dictionary.String())+":"+fuzz.fuzzPackagedModule.Dictionary.Base())
  388. }
  389. if fuzz.fuzzPackagedModule.Config != nil {
  390. fuzzFiles = append(fuzzFiles,
  391. filepath.Dir(fuzz.fuzzPackagedModule.Config.String())+":config.json")
  392. }
  393. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  394. entries.SetBool("LOCAL_IS_FUZZ_TARGET", true)
  395. if len(fuzzFiles) > 0 {
  396. entries.AddStrings("LOCAL_TEST_DATA", fuzzFiles...)
  397. }
  398. if fuzz.installedSharedDeps != nil {
  399. entries.AddStrings("LOCAL_FUZZ_INSTALLED_SHARED_DEPS", fuzz.installedSharedDeps...)
  400. }
  401. })
  402. }
  403. func (test *testLibrary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  404. ctx.subAndroidMk(entries, test.libraryDecorator)
  405. ctx.subAndroidMk(entries, test.testDecorator)
  406. }
  407. func (installer *baseInstaller) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  408. if installer.path == (android.InstallPath{}) {
  409. return
  410. }
  411. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  412. path, file := filepath.Split(installer.path.String())
  413. stem, suffix, _ := android.SplitFileExt(file)
  414. entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
  415. entries.SetString("LOCAL_MODULE_PATH", path)
  416. entries.SetString("LOCAL_MODULE_STEM", stem)
  417. })
  418. }
  419. func (c *stubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  420. entries.SubName = ndkLibrarySuffix + "." + c.apiLevel.String()
  421. entries.Class = "SHARED_LIBRARIES"
  422. if !c.buildStubs() {
  423. entries.Disabled = true
  424. return
  425. }
  426. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  427. path, file := filepath.Split(c.installPath.String())
  428. stem, suffix, _ := android.SplitFileExt(file)
  429. entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
  430. entries.SetString("LOCAL_MODULE_PATH", path)
  431. entries.SetString("LOCAL_MODULE_STEM", stem)
  432. entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
  433. if c.parsedCoverageXmlPath.String() != "" {
  434. entries.SetString("SOONG_NDK_API_XML", "$(SOONG_NDK_API_XML) "+c.parsedCoverageXmlPath.String())
  435. }
  436. })
  437. }
  438. func (c *vndkPrebuiltLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  439. entries.Class = "SHARED_LIBRARIES"
  440. entries.SubName = c.androidMkSuffix
  441. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  442. c.libraryDecorator.androidMkWriteExportedFlags(entries)
  443. // Specifying stem is to pass check_elf_files when vendor modules link against vndk prebuilt.
  444. // We can't use install path because VNDKs are not installed. Instead, Srcs is directly used.
  445. _, file := filepath.Split(c.properties.Srcs[0])
  446. stem, suffix, ext := android.SplitFileExt(file)
  447. entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
  448. entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
  449. entries.SetString("LOCAL_MODULE_STEM", stem)
  450. if c.tocFile.Valid() {
  451. entries.SetString("LOCAL_SOONG_TOC", c.tocFile.String())
  452. }
  453. // VNDK libraries available to vendor are not installed because
  454. // they are packaged in VNDK APEX and installed by APEX packages (apex/apex.go)
  455. entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
  456. })
  457. }
  458. func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  459. // Each vendor snapshot is exported to androidMk only when BOARD_VNDK_VERSION != current
  460. // and the version of the prebuilt is same as BOARD_VNDK_VERSION.
  461. if c.shared() {
  462. entries.Class = "SHARED_LIBRARIES"
  463. } else if c.static() {
  464. entries.Class = "STATIC_LIBRARIES"
  465. } else if c.header() {
  466. entries.Class = "HEADER_LIBRARIES"
  467. }
  468. entries.SubName = ""
  469. if c.isSanitizerEnabled(cfi) {
  470. entries.SubName += ".cfi"
  471. } else if c.isSanitizerEnabled(Hwasan) {
  472. entries.SubName += ".hwasan"
  473. }
  474. entries.SubName += c.baseProperties.Androidmk_suffix
  475. entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  476. c.libraryDecorator.androidMkWriteExportedFlags(entries)
  477. if c.shared() || c.static() {
  478. src := c.path.String()
  479. // For static libraries which aren't installed, directly use Src to extract filename.
  480. // This is safe: generated snapshot modules have a real path as Src, not a module
  481. if c.static() {
  482. src = proptools.String(c.properties.Src)
  483. }
  484. path, file := filepath.Split(src)
  485. stem, suffix, ext := android.SplitFileExt(file)
  486. entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
  487. entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
  488. entries.SetString("LOCAL_MODULE_STEM", stem)
  489. if c.shared() {
  490. entries.SetString("LOCAL_MODULE_PATH", path)
  491. }
  492. if c.tocFile.Valid() {
  493. entries.SetString("LOCAL_SOONG_TOC", c.tocFile.String())
  494. }
  495. if c.shared() && len(c.Properties.Overrides) > 0 {
  496. entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, c.Properties.Overrides), " "))
  497. }
  498. }
  499. if !c.shared() { // static or header
  500. entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
  501. }
  502. })
  503. }
  504. func (c *snapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  505. entries.Class = "EXECUTABLES"
  506. entries.SubName = c.baseProperties.Androidmk_suffix
  507. }
  508. func (c *snapshotObjectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  509. entries.Class = "STATIC_LIBRARIES"
  510. entries.SubName = c.baseProperties.Androidmk_suffix
  511. entries.ExtraFooters = append(entries.ExtraFooters,
  512. func(w io.Writer, name, prefix, moduleDir string) {
  513. out := entries.OutputFile.Path()
  514. varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, entries.SubName)
  515. fmt.Fprintf(w, "\n%s := %s\n", varname, out.String())
  516. fmt.Fprintln(w, ".KATI_READONLY: "+varname)
  517. })
  518. }
  519. func (c *ndkPrebuiltStlLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  520. entries.Class = "SHARED_LIBRARIES"
  521. }
  522. func (p *prebuiltLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  523. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  524. if p.properties.Check_elf_files != nil {
  525. entries.SetBool("LOCAL_CHECK_ELF_FILES", *p.properties.Check_elf_files)
  526. } else {
  527. // soong_cc_rust_prebuilt.mk does not include check_elf_file.mk by default
  528. // because cc_library_shared and cc_binary use soong_cc_rust_prebuilt.mk as well.
  529. // In order to turn on prebuilt ABI checker, set `LOCAL_CHECK_ELF_FILES` to
  530. // true if `p.properties.Check_elf_files` is not specified.
  531. entries.SetBool("LOCAL_CHECK_ELF_FILES", true)
  532. }
  533. })
  534. }
  535. func (p *prebuiltLibraryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  536. ctx.subAndroidMk(entries, p.libraryDecorator)
  537. if p.shared() {
  538. ctx.subAndroidMk(entries, &p.prebuiltLinker)
  539. androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries)
  540. }
  541. }
  542. func (p *prebuiltBinaryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  543. ctx.subAndroidMk(entries, p.binaryDecorator)
  544. ctx.subAndroidMk(entries, &p.prebuiltLinker)
  545. androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries)
  546. }
  547. func (a *apiLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  548. entries.Class = "SHARED_LIBRARIES"
  549. entries.SubName += multitree.GetApiImportSuffix()
  550. entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  551. a.libraryDecorator.androidMkWriteExportedFlags(entries)
  552. src := *a.properties.Src
  553. path, file := filepath.Split(src)
  554. stem, suffix, ext := android.SplitFileExt(file)
  555. entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
  556. entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
  557. entries.SetString("LOCAL_MODULE_STEM", stem)
  558. entries.SetString("LOCAL_MODULE_PATH", path)
  559. entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
  560. entries.SetString("LOCAL_SOONG_TOC", a.toc().String())
  561. })
  562. }
  563. func (a *apiHeadersDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  564. entries.Class = "HEADER_LIBRARIES"
  565. entries.SubName += multitree.GetApiImportSuffix()
  566. entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  567. a.libraryDecorator.androidMkWriteExportedFlags(entries)
  568. entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
  569. })
  570. }
  571. func androidMkWriteAllowUndefinedSymbols(linker *baseLinker, entries *android.AndroidMkEntries) {
  572. allow := linker.Properties.Allow_undefined_symbols
  573. if allow != nil {
  574. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  575. entries.SetBool("LOCAL_ALLOW_UNDEFINED_SYMBOLS", *allow)
  576. })
  577. }
  578. }