androidmk.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2017 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 python
  15. import (
  16. "path/filepath"
  17. "strings"
  18. "android/soong/android"
  19. )
  20. type subAndroidMkProvider interface {
  21. AndroidMk(*Module, *android.AndroidMkEntries)
  22. }
  23. func (p *Module) subAndroidMk(entries *android.AndroidMkEntries, obj interface{}) {
  24. if p.subAndroidMkOnce == nil {
  25. p.subAndroidMkOnce = make(map[subAndroidMkProvider]bool)
  26. }
  27. if androidmk, ok := obj.(subAndroidMkProvider); ok {
  28. if !p.subAndroidMkOnce[androidmk] {
  29. p.subAndroidMkOnce[androidmk] = true
  30. androidmk.AndroidMk(p, entries)
  31. }
  32. }
  33. }
  34. func (p *Module) AndroidMkEntries() []android.AndroidMkEntries {
  35. entries := android.AndroidMkEntries{OutputFile: p.installSource}
  36. p.subAndroidMk(&entries, p.installer)
  37. return []android.AndroidMkEntries{entries}
  38. }
  39. func (p *binaryDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntries) {
  40. entries.Class = "EXECUTABLES"
  41. entries.ExtraEntries = append(entries.ExtraEntries,
  42. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  43. entries.AddCompatibilityTestSuites(p.binaryProperties.Test_suites...)
  44. })
  45. base.subAndroidMk(entries, p.pythonInstaller)
  46. }
  47. func (p *testDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntries) {
  48. entries.Class = "NATIVE_TESTS"
  49. entries.ExtraEntries = append(entries.ExtraEntries,
  50. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  51. entries.AddCompatibilityTestSuites(p.binaryDecorator.binaryProperties.Test_suites...)
  52. if p.testConfig != nil {
  53. entries.SetString("LOCAL_FULL_TEST_CONFIG", p.testConfig.String())
  54. }
  55. entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(p.binaryProperties.Auto_gen_config, true))
  56. entries.AddStrings("LOCAL_TEST_DATA", android.AndroidMkDataPaths(p.data)...)
  57. entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(p.testProperties.Test_options.Unit_test))
  58. })
  59. base.subAndroidMk(entries, p.binaryDecorator.pythonInstaller)
  60. }
  61. func (installer *pythonInstaller) AndroidMk(base *Module, entries *android.AndroidMkEntries) {
  62. entries.Required = append(entries.Required, "libc++")
  63. entries.ExtraEntries = append(entries.ExtraEntries,
  64. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  65. path, file := filepath.Split(installer.path.String())
  66. stem := strings.TrimSuffix(file, filepath.Ext(file))
  67. entries.SetString("LOCAL_MODULE_SUFFIX", filepath.Ext(file))
  68. entries.SetString("LOCAL_MODULE_PATH", path)
  69. entries.SetString("LOCAL_MODULE_STEM", stem)
  70. entries.AddStrings("LOCAL_SHARED_LIBRARIES", installer.androidMkSharedLibs...)
  71. entries.SetBool("LOCAL_CHECK_ELF_FILES", false)
  72. })
  73. }