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 | |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 32 | // The paths to the generated annotation-flags.csv files. |
| 33 | AnnotationFlagsPaths android.Paths |
| 34 | |
| 35 | // The paths to the generated metadata.csv files. |
| 36 | MetadataPaths android.Paths |
| 37 | |
| 38 | // The paths to the generated index.csv files. |
| 39 | IndexPaths android.Paths |
| 40 | |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 41 | // The subsets of the monolithic hiddenapi-stubs-flags.txt file that are provided by each |
| 42 | // bootclasspath_fragment modules. |
| 43 | StubFlagSubsets SignatureCsvSubsets |
| 44 | |
| 45 | // The subsets of the monolithic hiddenapi-flags.csv file that are provided by each |
| 46 | // bootclasspath_fragment modules. |
| 47 | FlagSubsets SignatureCsvSubsets |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 48 | |
| 49 | // The classes jars from the libraries on the platform bootclasspath. |
| 50 | ClassesJars android.Paths |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // newMonolithicHiddenAPIInfo creates a new MonolithicHiddenAPIInfo from the flagFilesByCategory |
| 54 | // plus information provided by each of the fragments. |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 55 | func newMonolithicHiddenAPIInfo(ctx android.ModuleContext, flagFilesByCategory FlagFilesByCategory, classpathElements ClasspathElements) MonolithicHiddenAPIInfo { |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 56 | monolithicInfo := MonolithicHiddenAPIInfo{} |
| 57 | |
| 58 | monolithicInfo.FlagsFilesByCategory = flagFilesByCategory |
| 59 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 60 | // Merge all the information from the classpathElements. The fragments form a DAG so it is possible that |
| 61 | // this will introduce duplicates so they will be resolved after processing all the classpathElements. |
| 62 | for _, element := range classpathElements { |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 63 | switch e := element.(type) { |
| 64 | case *ClasspathLibraryElement: |
Paul Duffin | d6a072b | 2021-07-20 19:04:46 +0100 | [diff] [blame] | 65 | classesJars := retrieveClassesJarsFromModule(e.Module()) |
| 66 | monolithicInfo.ClassesJars = append(monolithicInfo.ClassesJars, classesJars...) |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 67 | |
| 68 | case *ClasspathFragmentElement: |
| 69 | fragment := e.Module() |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 70 | if info, ok := android.OtherModuleProvider(ctx, fragment, HiddenAPIInfoProvider); ok { |
Spandan Das | 38c64f6 | 2024-02-12 15:00:15 +0000 | [diff] [blame^] | 71 | monolithicInfo.append(ctx, fragment, &info) |
Paul Duffin | d6a072b | 2021-07-20 19:04:46 +0100 | [diff] [blame] | 72 | } else { |
| 73 | ctx.ModuleErrorf("%s does not provide hidden API information", fragment) |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 74 | } |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 78 | return monolithicInfo |
| 79 | } |
| 80 | |
| 81 | // append appends all the files from the supplied info to the corresponding files in this struct. |
Spandan Das | 38c64f6 | 2024-02-12 15:00:15 +0000 | [diff] [blame^] | 82 | func (i *MonolithicHiddenAPIInfo) append(ctx android.ModuleContext, otherModule android.Module, other *HiddenAPIInfo) { |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 83 | i.FlagsFilesByCategory.append(other.FlagFilesByCategory) |
Paul Duffin | ed12c13 | 2021-07-20 19:08:39 +0100 | [diff] [blame] | 84 | i.AnnotationFlagsPaths = append(i.AnnotationFlagsPaths, other.AnnotationFlagsPath) |
| 85 | i.MetadataPaths = append(i.MetadataPaths, other.MetadataPath) |
| 86 | i.IndexPaths = append(i.IndexPaths, other.IndexPath) |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 87 | |
Spandan Das | 38c64f6 | 2024-02-12 15:00:15 +0000 | [diff] [blame^] | 88 | apexInfo, ok := android.OtherModuleProvider(ctx, otherModule, android.ApexInfoProvider) |
| 89 | if !ok { |
| 90 | ctx.ModuleErrorf("Could not determine min_version_version of %s\n", otherModule.Name()) |
| 91 | return |
| 92 | } |
| 93 | if apexInfo.MinSdkVersion.LessThanOrEqualTo(android.ApiLevelR) { |
| 94 | // Restrict verify_overlaps to R and older modules. |
| 95 | // The runtime in S does not have the same restriction that |
| 96 | // requires the hiddenapi flags to be generated in a monolithic |
| 97 | // invocation. |
| 98 | i.StubFlagSubsets = append(i.StubFlagSubsets, other.StubFlagSubset()) |
| 99 | i.FlagSubsets = append(i.FlagSubsets, other.FlagSubset()) |
| 100 | } |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Colin Cross | bc7d76c | 2023-12-12 16:39:03 -0800 | [diff] [blame] | 103 | var MonolithicHiddenAPIInfoProvider = blueprint.NewProvider[MonolithicHiddenAPIInfo]() |