Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame^] | 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "github.com/google/blueprint" |
| 20 | ) |
| 21 | |
| 22 | // MonolithicHiddenAPIInfo contains information needed/provided by the hidden API generation of the |
| 23 | // monolithic hidden API files. |
| 24 | // |
| 25 | // Each list of paths includes all the equivalent paths from each of the bootclasspath_fragment |
| 26 | // modules that contribute to the platform-bootclasspath. |
| 27 | type MonolithicHiddenAPIInfo struct { |
| 28 | // FlagsFilesByCategory maps from the flag file category to the paths containing information for |
| 29 | // that category. |
| 30 | FlagsFilesByCategory FlagFilesByCategory |
| 31 | |
| 32 | // The paths to the generated stub-flags.csv files. |
| 33 | StubFlagsPaths android.Paths |
| 34 | |
| 35 | // The paths to the generated annotation-flags.csv files. |
| 36 | AnnotationFlagsPaths android.Paths |
| 37 | |
| 38 | // The paths to the generated metadata.csv files. |
| 39 | MetadataPaths android.Paths |
| 40 | |
| 41 | // The paths to the generated index.csv files. |
| 42 | IndexPaths android.Paths |
| 43 | |
| 44 | // The paths to the generated all-flags.csv files. |
| 45 | AllFlagsPaths android.Paths |
| 46 | } |
| 47 | |
| 48 | // newMonolithicHiddenAPIInfo creates a new MonolithicHiddenAPIInfo from the flagFilesByCategory |
| 49 | // plus information provided by each of the fragments. |
| 50 | func newMonolithicHiddenAPIInfo(ctx android.ModuleContext, flagFilesByCategory FlagFilesByCategory, fragments []android.Module) MonolithicHiddenAPIInfo { |
| 51 | monolithicInfo := MonolithicHiddenAPIInfo{} |
| 52 | |
| 53 | monolithicInfo.FlagsFilesByCategory = flagFilesByCategory |
| 54 | |
| 55 | // Merge all the information from the fragments. The fragments form a DAG so it is possible that |
| 56 | // this will introduce duplicates so they will be resolved after processing all the fragments. |
| 57 | for _, fragment := range fragments { |
| 58 | if ctx.OtherModuleHasProvider(fragment, hiddenAPIFlagFileInfoProvider) { |
| 59 | info := ctx.OtherModuleProvider(fragment, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo) |
| 60 | monolithicInfo.append(&info) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Dedup paths. |
| 65 | monolithicInfo.dedup() |
| 66 | |
| 67 | return monolithicInfo |
| 68 | } |
| 69 | |
| 70 | // append appends all the files from the supplied info to the corresponding files in this struct. |
| 71 | func (i *MonolithicHiddenAPIInfo) append(other *hiddenAPIFlagFileInfo) { |
| 72 | i.FlagsFilesByCategory.append(other.FlagFilesByCategory) |
| 73 | i.StubFlagsPaths = append(i.StubFlagsPaths, other.StubFlagsPaths...) |
| 74 | i.AnnotationFlagsPaths = append(i.AnnotationFlagsPaths, other.AnnotationFlagsPaths...) |
| 75 | i.MetadataPaths = append(i.MetadataPaths, other.MetadataPaths...) |
| 76 | i.IndexPaths = append(i.IndexPaths, other.IndexPaths...) |
| 77 | i.AllFlagsPaths = append(i.AllFlagsPaths, other.AllFlagsPaths...) |
| 78 | } |
| 79 | |
| 80 | // dedup removes duplicates in all the paths, while maintaining the order in which they were |
| 81 | // appended. |
| 82 | func (i *MonolithicHiddenAPIInfo) dedup() { |
| 83 | i.FlagsFilesByCategory.dedup() |
| 84 | i.StubFlagsPaths = android.FirstUniquePaths(i.StubFlagsPaths) |
| 85 | i.AnnotationFlagsPaths = android.FirstUniquePaths(i.AnnotationFlagsPaths) |
| 86 | i.MetadataPaths = android.FirstUniquePaths(i.MetadataPaths) |
| 87 | i.IndexPaths = android.FirstUniquePaths(i.IndexPaths) |
| 88 | i.AllFlagsPaths = android.FirstUniquePaths(i.AllFlagsPaths) |
| 89 | } |
| 90 | |
| 91 | var monolithicHiddenAPIInfoProvider = blueprint.NewProvider(MonolithicHiddenAPIInfo{}) |