metadata.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2023 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package apex
  17. import (
  18. "encoding/json"
  19. "github.com/google/blueprint"
  20. "android/soong/android"
  21. )
  22. var (
  23. mtctx = android.NewPackageContext("android/soong/multitree_apex")
  24. )
  25. func init() {
  26. RegisterModulesSingleton(android.InitRegistrationContext)
  27. }
  28. func RegisterModulesSingleton(ctx android.RegistrationContext) {
  29. ctx.RegisterSingletonType("apex_multitree_singleton", multitreeAnalysisSingletonFactory)
  30. }
  31. var PrepareForTestWithApexMultitreeSingleton = android.FixtureRegisterWithContext(RegisterModulesSingleton)
  32. func multitreeAnalysisSingletonFactory() android.Singleton {
  33. return &multitreeAnalysisSingleton{}
  34. }
  35. type multitreeAnalysisSingleton struct {
  36. multitreeApexMetadataPath android.OutputPath
  37. }
  38. type ApexMultitreeMetadataEntry struct {
  39. // The name of the apex.
  40. Name string
  41. // TODO: Add other properties as needed.
  42. }
  43. type ApexMultitreeMetadata struct {
  44. // Information about the installable apexes.
  45. Apexes map[string]ApexMultitreeMetadataEntry
  46. }
  47. func (p *multitreeAnalysisSingleton) GenerateBuildActions(context android.SingletonContext) {
  48. data := ApexMultitreeMetadata{
  49. Apexes: make(map[string]ApexMultitreeMetadataEntry, 0),
  50. }
  51. context.VisitAllModules(func(module android.Module) {
  52. // If this module is not being installed, ignore it.
  53. if !module.Enabled() || module.IsSkipInstall() {
  54. return
  55. }
  56. // Actual apexes provide ApexBundleInfoProvider.
  57. if _, ok := context.ModuleProvider(module, ApexBundleInfoProvider).(ApexBundleInfo); !ok {
  58. return
  59. }
  60. bundle, ok := module.(*apexBundle)
  61. if ok && !bundle.testApex && !bundle.vndkApex && bundle.primaryApexType {
  62. name := module.Name()
  63. entry := ApexMultitreeMetadataEntry{
  64. Name: name,
  65. }
  66. data.Apexes[name] = entry
  67. }
  68. })
  69. p.multitreeApexMetadataPath = android.PathForOutput(context, "multitree_apex_metadata.json")
  70. jsonStr, err := json.Marshal(data)
  71. if err != nil {
  72. context.Errorf(err.Error())
  73. }
  74. android.WriteFileRule(context, p.multitreeApexMetadataPath, string(jsonStr))
  75. // This seems cleaner, but doesn't emit the phony rule in testing.
  76. // context.Phony("multitree_apex_metadata", p.multitreeApexMetadataPath)
  77. context.Build(mtctx, android.BuildParams{
  78. Rule: blueprint.Phony,
  79. Description: "phony rule for multitree_apex_metadata",
  80. Inputs: []android.Path{p.multitreeApexMetadataPath},
  81. Output: android.PathForPhony(context, "multitree_apex_metadata"),
  82. })
  83. }