support_libraries.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2018 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 java
  15. import (
  16. "sort"
  17. "strings"
  18. "android/soong/android"
  19. )
  20. func init() {
  21. android.RegisterMakeVarsProvider(pctx, supportLibrariesMakeVarsProvider)
  22. }
  23. func supportLibrariesMakeVarsProvider(ctx android.MakeVarsContext) {
  24. var supportAars, supportJars []string
  25. ctx.VisitAllModules(func(module android.Module) {
  26. dir := ctx.ModuleDir(module)
  27. switch {
  28. case strings.HasPrefix(dir, "prebuilts/sdk/current/extras"),
  29. dir == "prebuilts/sdk/current/androidx",
  30. dir == "prebuilts/sdk/current/car",
  31. dir == "prebuilts/sdk/current/optional",
  32. dir == "prebuilts/sdk/current/support":
  33. // Support library
  34. default:
  35. // Not a support library
  36. return
  37. }
  38. name := ctx.ModuleName(module)
  39. if strings.HasSuffix(name, "-nodeps") {
  40. return
  41. }
  42. switch module.(type) {
  43. case *AndroidLibrary, *AARImport:
  44. supportAars = append(supportAars, name)
  45. case *Library, *Import:
  46. supportJars = append(supportJars, name)
  47. }
  48. })
  49. sort.Strings(supportAars)
  50. sort.Strings(supportJars)
  51. ctx.Strict("SUPPORT_LIBRARIES_AARS", strings.Join(supportAars, " "))
  52. ctx.Strict("SUPPORT_LIBRARIES_JARS", strings.Join(supportJars, " "))
  53. }