sysprop.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (C) 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 cc
  15. // This file contains a map to redirect dependencies towards sysprop_library.
  16. // As sysprop_library has to support both Java and C++, sysprop_library internally
  17. // generates cc_library and java_library. For example, the following sysprop_library
  18. //
  19. // sysprop_library {
  20. // name: "foo",
  21. // }
  22. //
  23. // will internally generate with prefix "lib"
  24. //
  25. // cc_library {
  26. // name: "libfoo",
  27. // }
  28. //
  29. // When a cc module links against "foo", build system will redirect the
  30. // dependency to "libfoo". To do that, SyspropMutator gathers all sysprop_library,
  31. // records their cc implementation library names to a map. The map will be used in
  32. // cc.Module.DepsMutator.
  33. import (
  34. "sync"
  35. "android/soong/android"
  36. )
  37. type syspropLibraryInterface interface {
  38. BaseModuleName() string
  39. CcImplementationModuleName() string
  40. }
  41. var (
  42. syspropImplLibrariesKey = android.NewOnceKey("syspropImplLibirares")
  43. syspropImplLibrariesLock sync.Mutex
  44. )
  45. func syspropImplLibraries(config android.Config) map[string]string {
  46. return config.Once(syspropImplLibrariesKey, func() interface{} {
  47. return make(map[string]string)
  48. }).(map[string]string)
  49. }
  50. // gather list of sysprop libraries
  51. func SyspropMutator(mctx android.BottomUpMutatorContext) {
  52. if m, ok := mctx.Module().(syspropLibraryInterface); ok {
  53. syspropImplLibraries := syspropImplLibraries(mctx.Config())
  54. syspropImplLibrariesLock.Lock()
  55. defer syspropImplLibrariesLock.Unlock()
  56. // BaseModuleName is the name of sysprop_library
  57. // CcImplementationModuleName is the name of cc_library generated by sysprop_library
  58. syspropImplLibraries[m.BaseModuleName()] = m.CcImplementationModuleName()
  59. }
  60. }