hiddenapi_monolithic.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (C) 2021 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 java
  15. import (
  16. "android/soong/android"
  17. "github.com/google/blueprint"
  18. )
  19. // MonolithicHiddenAPIInfo contains information needed/provided by the hidden API generation of the
  20. // monolithic hidden API files.
  21. //
  22. // Each list of paths includes all the equivalent paths from each of the bootclasspath_fragment
  23. // modules that contribute to the platform-bootclasspath.
  24. type MonolithicHiddenAPIInfo struct {
  25. // FlagsFilesByCategory maps from the flag file category to the paths containing information for
  26. // that category.
  27. FlagsFilesByCategory FlagFilesByCategory
  28. // The paths to the generated annotation-flags.csv files.
  29. AnnotationFlagsPaths android.Paths
  30. // The paths to the generated metadata.csv files.
  31. MetadataPaths android.Paths
  32. // The paths to the generated index.csv files.
  33. IndexPaths android.Paths
  34. // The subsets of the monolithic hiddenapi-stubs-flags.txt file that are provided by each
  35. // bootclasspath_fragment modules.
  36. StubFlagSubsets SignatureCsvSubsets
  37. // The subsets of the monolithic hiddenapi-flags.csv file that are provided by each
  38. // bootclasspath_fragment modules.
  39. FlagSubsets SignatureCsvSubsets
  40. // The classes jars from the libraries on the platform bootclasspath.
  41. ClassesJars android.Paths
  42. }
  43. // newMonolithicHiddenAPIInfo creates a new MonolithicHiddenAPIInfo from the flagFilesByCategory
  44. // plus information provided by each of the fragments.
  45. func newMonolithicHiddenAPIInfo(ctx android.ModuleContext, flagFilesByCategory FlagFilesByCategory, classpathElements ClasspathElements) MonolithicHiddenAPIInfo {
  46. monolithicInfo := MonolithicHiddenAPIInfo{}
  47. monolithicInfo.FlagsFilesByCategory = flagFilesByCategory
  48. // Merge all the information from the classpathElements. The fragments form a DAG so it is possible that
  49. // this will introduce duplicates so they will be resolved after processing all the classpathElements.
  50. for _, element := range classpathElements {
  51. switch e := element.(type) {
  52. case *ClasspathLibraryElement:
  53. classesJars := retrieveClassesJarsFromModule(e.Module())
  54. monolithicInfo.ClassesJars = append(monolithicInfo.ClassesJars, classesJars...)
  55. case *ClasspathFragmentElement:
  56. fragment := e.Module()
  57. if ctx.OtherModuleHasProvider(fragment, HiddenAPIInfoProvider) {
  58. info := ctx.OtherModuleProvider(fragment, HiddenAPIInfoProvider).(HiddenAPIInfo)
  59. monolithicInfo.append(&info)
  60. } else {
  61. ctx.ModuleErrorf("%s does not provide hidden API information", fragment)
  62. }
  63. }
  64. }
  65. return monolithicInfo
  66. }
  67. // append appends all the files from the supplied info to the corresponding files in this struct.
  68. func (i *MonolithicHiddenAPIInfo) append(other *HiddenAPIInfo) {
  69. i.FlagsFilesByCategory.append(other.FlagFilesByCategory)
  70. i.AnnotationFlagsPaths = append(i.AnnotationFlagsPaths, other.AnnotationFlagsPath)
  71. i.MetadataPaths = append(i.MetadataPaths, other.MetadataPath)
  72. i.IndexPaths = append(i.IndexPaths, other.IndexPath)
  73. i.StubFlagSubsets = append(i.StubFlagSubsets, other.StubFlagSubset())
  74. i.FlagSubsets = append(i.FlagSubsets, other.FlagSubset())
  75. }
  76. var MonolithicHiddenAPIInfoProvider = blueprint.NewProvider(MonolithicHiddenAPIInfo{})