androidmk.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // Copyright 2019 The Android Open Source Project
  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 rust
  15. import (
  16. "path/filepath"
  17. "android/soong/android"
  18. "android/soong/cc"
  19. )
  20. type AndroidMkContext interface {
  21. Name() string
  22. Target() android.Target
  23. SubAndroidMk(*android.AndroidMkEntries, interface{})
  24. }
  25. type SubAndroidMkProvider interface {
  26. AndroidMk(AndroidMkContext, *android.AndroidMkEntries)
  27. }
  28. func (mod *Module) SubAndroidMk(data *android.AndroidMkEntries, obj interface{}) {
  29. if mod.subAndroidMkOnce == nil {
  30. mod.subAndroidMkOnce = make(map[SubAndroidMkProvider]bool)
  31. }
  32. if androidmk, ok := obj.(SubAndroidMkProvider); ok {
  33. if !mod.subAndroidMkOnce[androidmk] {
  34. mod.subAndroidMkOnce[androidmk] = true
  35. androidmk.AndroidMk(mod, data)
  36. }
  37. }
  38. }
  39. func (mod *Module) AndroidMkEntries() []android.AndroidMkEntries {
  40. if mod.Properties.HideFromMake || mod.hideApexVariantFromMake {
  41. return []android.AndroidMkEntries{android.AndroidMkEntries{Disabled: true}}
  42. }
  43. ret := android.AndroidMkEntries{
  44. OutputFile: android.OptionalPathForPath(mod.UnstrippedOutputFile()),
  45. Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk",
  46. ExtraEntries: []android.AndroidMkExtraEntriesFunc{
  47. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  48. entries.AddStrings("LOCAL_RLIB_LIBRARIES", mod.Properties.AndroidMkRlibs...)
  49. entries.AddStrings("LOCAL_DYLIB_LIBRARIES", mod.Properties.AndroidMkDylibs...)
  50. entries.AddStrings("LOCAL_PROC_MACRO_LIBRARIES", mod.Properties.AndroidMkProcMacroLibs...)
  51. entries.AddStrings("LOCAL_SHARED_LIBRARIES", mod.Properties.AndroidMkSharedLibs...)
  52. entries.AddStrings("LOCAL_STATIC_LIBRARIES", mod.Properties.AndroidMkStaticLibs...)
  53. entries.AddStrings("LOCAL_SOONG_LINK_TYPE", mod.makeLinkType)
  54. if mod.UseVndk() {
  55. entries.SetBool("LOCAL_USE_VNDK", true)
  56. }
  57. },
  58. },
  59. }
  60. if mod.compiler != nil && !mod.compiler.Disabled() {
  61. mod.SubAndroidMk(&ret, mod.compiler)
  62. } else if mod.sourceProvider != nil {
  63. // If the compiler is disabled, this is a SourceProvider.
  64. mod.SubAndroidMk(&ret, mod.sourceProvider)
  65. }
  66. if mod.sanitize != nil {
  67. mod.SubAndroidMk(&ret, mod.sanitize)
  68. }
  69. ret.SubName += mod.Properties.RustSubName
  70. ret.SubName += mod.Properties.SubName
  71. return []android.AndroidMkEntries{ret}
  72. }
  73. func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
  74. ctx.SubAndroidMk(ret, binary.baseCompiler)
  75. if binary.distFile.Valid() {
  76. ret.DistFiles = android.MakeDefaultDistFiles(binary.distFile.Path())
  77. }
  78. ret.Class = "EXECUTABLES"
  79. }
  80. func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
  81. ctx.SubAndroidMk(ret, test.binaryDecorator)
  82. ret.Class = "NATIVE_TESTS"
  83. ret.ExtraEntries = append(ret.ExtraEntries,
  84. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  85. entries.AddCompatibilityTestSuites(test.Properties.Test_suites...)
  86. if test.testConfig != nil {
  87. entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String())
  88. }
  89. entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(test.Properties.Auto_gen_config, true))
  90. if test.Properties.Data_bins != nil {
  91. entries.AddStrings("LOCAL_TEST_DATA_BINS", test.Properties.Data_bins...)
  92. }
  93. test.Properties.Test_options.SetAndroidMkEntries(entries)
  94. })
  95. cc.AndroidMkWriteTestData(test.data, ret)
  96. }
  97. func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
  98. benchmark.binaryDecorator.AndroidMk(ctx, ret)
  99. ret.Class = "NATIVE_TESTS"
  100. ret.ExtraEntries = append(ret.ExtraEntries,
  101. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  102. entries.AddCompatibilityTestSuites(benchmark.Properties.Test_suites...)
  103. if benchmark.testConfig != nil {
  104. entries.SetString("LOCAL_FULL_TEST_CONFIG", benchmark.testConfig.String())
  105. }
  106. entries.SetBool("LOCAL_NATIVE_BENCHMARK", true)
  107. entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(benchmark.Properties.Auto_gen_config, true))
  108. })
  109. }
  110. func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
  111. ctx.SubAndroidMk(ret, library.baseCompiler)
  112. if library.rlib() {
  113. ret.Class = "RLIB_LIBRARIES"
  114. } else if library.dylib() {
  115. ret.Class = "DYLIB_LIBRARIES"
  116. } else if library.static() {
  117. ret.Class = "STATIC_LIBRARIES"
  118. } else if library.shared() {
  119. ret.Class = "SHARED_LIBRARIES"
  120. }
  121. if library.distFile.Valid() {
  122. ret.DistFiles = android.MakeDefaultDistFiles(library.distFile.Path())
  123. }
  124. ret.ExtraEntries = append(ret.ExtraEntries,
  125. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  126. if library.tocFile.Valid() {
  127. entries.SetString("LOCAL_SOONG_TOC", library.tocFile.String())
  128. }
  129. })
  130. }
  131. func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
  132. ctx.SubAndroidMk(ret, procMacro.baseCompiler)
  133. ret.Class = "PROC_MACRO_LIBRARIES"
  134. if procMacro.distFile.Valid() {
  135. ret.DistFiles = android.MakeDefaultDistFiles(procMacro.distFile.Path())
  136. }
  137. }
  138. func (sourceProvider *BaseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
  139. outFile := sourceProvider.OutputFiles[0]
  140. ret.Class = "ETC"
  141. ret.OutputFile = android.OptionalPathForPath(outFile)
  142. ret.SubName += sourceProvider.subName
  143. ret.ExtraEntries = append(ret.ExtraEntries,
  144. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  145. _, file := filepath.Split(outFile.String())
  146. stem, suffix, _ := android.SplitFileExt(file)
  147. entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
  148. entries.SetString("LOCAL_MODULE_STEM", stem)
  149. entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
  150. })
  151. }
  152. func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
  153. ctx.SubAndroidMk(ret, bindgen.BaseSourceProvider)
  154. }
  155. func (proto *protobufDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
  156. ctx.SubAndroidMk(ret, proto.BaseSourceProvider)
  157. }
  158. func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
  159. if compiler.path == (android.InstallPath{}) {
  160. return
  161. }
  162. if compiler.strippedOutputFile.Valid() {
  163. ret.OutputFile = compiler.strippedOutputFile
  164. }
  165. ret.ExtraEntries = append(ret.ExtraEntries,
  166. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  167. entries.SetPath("LOCAL_SOONG_UNSTRIPPED_BINARY", compiler.unstrippedOutputFile)
  168. path, file := filepath.Split(compiler.path.String())
  169. stem, suffix, _ := android.SplitFileExt(file)
  170. entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
  171. entries.SetString("LOCAL_MODULE_PATH", path)
  172. entries.SetString("LOCAL_MODULE_STEM", stem)
  173. })
  174. }
  175. func (fuzz *fuzzDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
  176. ctx.SubAndroidMk(entries, fuzz.binaryDecorator)
  177. var fuzzFiles []string
  178. for _, d := range fuzz.fuzzPackagedModule.Corpus {
  179. fuzzFiles = append(fuzzFiles,
  180. filepath.Dir(fuzz.fuzzPackagedModule.CorpusIntermediateDir.String())+":corpus/"+d.Base())
  181. }
  182. for _, d := range fuzz.fuzzPackagedModule.Data {
  183. fuzzFiles = append(fuzzFiles,
  184. filepath.Dir(fuzz.fuzzPackagedModule.DataIntermediateDir.String())+":data/"+d.Rel())
  185. }
  186. if fuzz.fuzzPackagedModule.Dictionary != nil {
  187. fuzzFiles = append(fuzzFiles,
  188. filepath.Dir(fuzz.fuzzPackagedModule.Dictionary.String())+":"+fuzz.fuzzPackagedModule.Dictionary.Base())
  189. }
  190. if fuzz.fuzzPackagedModule.Config != nil {
  191. fuzzFiles = append(fuzzFiles,
  192. filepath.Dir(fuzz.fuzzPackagedModule.Config.String())+":config.json")
  193. }
  194. entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext,
  195. entries *android.AndroidMkEntries) {
  196. entries.SetBool("LOCAL_IS_FUZZ_TARGET", true)
  197. if len(fuzzFiles) > 0 {
  198. entries.AddStrings("LOCAL_TEST_DATA", fuzzFiles...)
  199. }
  200. })
  201. }