stub_library.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2020 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. "sort"
  17. "strings"
  18. "android/soong/android"
  19. )
  20. func init() {
  21. // Use singleton type to gather all generated soong modules.
  22. android.RegisterParallelSingletonType("stublibraries", stubLibrariesSingleton)
  23. }
  24. type stubLibraries struct {
  25. stubLibraryMap map[string]bool
  26. apiListCoverageXmlPaths []string
  27. }
  28. // Check if the module defines stub, or itself is stub
  29. func IsStubTarget(m *Module) bool {
  30. return m.IsStubs() || m.HasStubsVariants()
  31. }
  32. // Get target file name to be installed from this module
  33. func getInstalledFileName(m *Module) string {
  34. for _, ps := range m.PackagingSpecs() {
  35. if name := ps.FileName(); name != "" {
  36. return name
  37. }
  38. }
  39. return ""
  40. }
  41. func (s *stubLibraries) GenerateBuildActions(ctx android.SingletonContext) {
  42. // Visit all generated soong modules and store stub library file names.
  43. ctx.VisitAllModules(func(module android.Module) {
  44. if m, ok := module.(*Module); ok {
  45. if IsStubTarget(m) {
  46. if name := getInstalledFileName(m); name != "" {
  47. s.stubLibraryMap[name] = true
  48. }
  49. }
  50. if m.library != nil {
  51. if p := m.library.getAPIListCoverageXMLPath().String(); p != "" {
  52. s.apiListCoverageXmlPaths = append(s.apiListCoverageXmlPaths, p)
  53. }
  54. }
  55. }
  56. })
  57. }
  58. func stubLibrariesSingleton() android.Singleton {
  59. return &stubLibraries{
  60. stubLibraryMap: make(map[string]bool),
  61. }
  62. }
  63. func (s *stubLibraries) MakeVars(ctx android.MakeVarsContext) {
  64. // Convert stub library file names into Makefile variable.
  65. ctx.Strict("STUB_LIBRARIES", strings.Join(android.SortedKeys(s.stubLibraryMap), " "))
  66. // Export the list of API XML files to Make.
  67. sort.Strings(s.apiListCoverageXmlPaths)
  68. ctx.Strict("SOONG_CC_API_XML", strings.Join(s.apiListCoverageXmlPaths, " "))
  69. }