1*333d2b36SAndroid Build Coastguard Worker// Copyright (C) 2021 The Android Open Source Project 2*333d2b36SAndroid Build Coastguard Worker// 3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*333d2b36SAndroid Build Coastguard Worker// 7*333d2b36SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*333d2b36SAndroid Build Coastguard Worker// 9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*333d2b36SAndroid Build Coastguard Worker// limitations under the License. 14*333d2b36SAndroid Build Coastguard Worker 15*333d2b36SAndroid Build Coastguard Workerpackage java 16*333d2b36SAndroid Build Coastguard Worker 17*333d2b36SAndroid Build Coastguard Workerimport ( 18*333d2b36SAndroid Build Coastguard Worker "android/soong/android" 19*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint" 20*333d2b36SAndroid Build Coastguard Worker) 21*333d2b36SAndroid Build Coastguard Worker 22*333d2b36SAndroid Build Coastguard Worker// MonolithicHiddenAPIInfo contains information needed/provided by the hidden API generation of the 23*333d2b36SAndroid Build Coastguard Worker// monolithic hidden API files. 24*333d2b36SAndroid Build Coastguard Worker// 25*333d2b36SAndroid Build Coastguard Worker// Each list of paths includes all the equivalent paths from each of the bootclasspath_fragment 26*333d2b36SAndroid Build Coastguard Worker// modules that contribute to the platform-bootclasspath. 27*333d2b36SAndroid Build Coastguard Workertype MonolithicHiddenAPIInfo struct { 28*333d2b36SAndroid Build Coastguard Worker // FlagsFilesByCategory maps from the flag file category to the paths containing information for 29*333d2b36SAndroid Build Coastguard Worker // that category. 30*333d2b36SAndroid Build Coastguard Worker FlagsFilesByCategory FlagFilesByCategory 31*333d2b36SAndroid Build Coastguard Worker 32*333d2b36SAndroid Build Coastguard Worker // The paths to the generated annotation-flags.csv files. 33*333d2b36SAndroid Build Coastguard Worker AnnotationFlagsPaths android.Paths 34*333d2b36SAndroid Build Coastguard Worker 35*333d2b36SAndroid Build Coastguard Worker // The paths to the generated metadata.csv files. 36*333d2b36SAndroid Build Coastguard Worker MetadataPaths android.Paths 37*333d2b36SAndroid Build Coastguard Worker 38*333d2b36SAndroid Build Coastguard Worker // The paths to the generated index.csv files. 39*333d2b36SAndroid Build Coastguard Worker IndexPaths android.Paths 40*333d2b36SAndroid Build Coastguard Worker 41*333d2b36SAndroid Build Coastguard Worker // The subsets of the monolithic hiddenapi-stubs-flags.txt file that are provided by each 42*333d2b36SAndroid Build Coastguard Worker // bootclasspath_fragment modules. 43*333d2b36SAndroid Build Coastguard Worker StubFlagSubsets SignatureCsvSubsets 44*333d2b36SAndroid Build Coastguard Worker 45*333d2b36SAndroid Build Coastguard Worker // The subsets of the monolithic hiddenapi-flags.csv file that are provided by each 46*333d2b36SAndroid Build Coastguard Worker // bootclasspath_fragment modules. 47*333d2b36SAndroid Build Coastguard Worker FlagSubsets SignatureCsvSubsets 48*333d2b36SAndroid Build Coastguard Worker 49*333d2b36SAndroid Build Coastguard Worker // The classes jars from the libraries on the platform bootclasspath. 50*333d2b36SAndroid Build Coastguard Worker ClassesJars android.Paths 51*333d2b36SAndroid Build Coastguard Worker} 52*333d2b36SAndroid Build Coastguard Worker 53*333d2b36SAndroid Build Coastguard Worker// newMonolithicHiddenAPIInfo creates a new MonolithicHiddenAPIInfo from the flagFilesByCategory 54*333d2b36SAndroid Build Coastguard Worker// plus information provided by each of the fragments. 55*333d2b36SAndroid Build Coastguard Workerfunc newMonolithicHiddenAPIInfo(ctx android.ModuleContext, flagFilesByCategory FlagFilesByCategory, classpathElements ClasspathElements) MonolithicHiddenAPIInfo { 56*333d2b36SAndroid Build Coastguard Worker monolithicInfo := MonolithicHiddenAPIInfo{} 57*333d2b36SAndroid Build Coastguard Worker 58*333d2b36SAndroid Build Coastguard Worker monolithicInfo.FlagsFilesByCategory = flagFilesByCategory 59*333d2b36SAndroid Build Coastguard Worker 60*333d2b36SAndroid Build Coastguard Worker // Merge all the information from the classpathElements. The fragments form a DAG so it is possible that 61*333d2b36SAndroid Build Coastguard Worker // this will introduce duplicates so they will be resolved after processing all the classpathElements. 62*333d2b36SAndroid Build Coastguard Worker for _, element := range classpathElements { 63*333d2b36SAndroid Build Coastguard Worker switch e := element.(type) { 64*333d2b36SAndroid Build Coastguard Worker case *ClasspathLibraryElement: 65*333d2b36SAndroid Build Coastguard Worker classesJars := retrieveClassesJarsFromModule(e.Module()) 66*333d2b36SAndroid Build Coastguard Worker monolithicInfo.ClassesJars = append(monolithicInfo.ClassesJars, classesJars...) 67*333d2b36SAndroid Build Coastguard Worker 68*333d2b36SAndroid Build Coastguard Worker case *ClasspathFragmentElement: 69*333d2b36SAndroid Build Coastguard Worker fragment := e.Module() 70*333d2b36SAndroid Build Coastguard Worker if info, ok := android.OtherModuleProvider(ctx, fragment, HiddenAPIInfoProvider); ok { 71*333d2b36SAndroid Build Coastguard Worker monolithicInfo.append(ctx, fragment, &info) 72*333d2b36SAndroid Build Coastguard Worker } else { 73*333d2b36SAndroid Build Coastguard Worker ctx.ModuleErrorf("%s does not provide hidden API information", fragment) 74*333d2b36SAndroid Build Coastguard Worker } 75*333d2b36SAndroid Build Coastguard Worker } 76*333d2b36SAndroid Build Coastguard Worker } 77*333d2b36SAndroid Build Coastguard Worker 78*333d2b36SAndroid Build Coastguard Worker return monolithicInfo 79*333d2b36SAndroid Build Coastguard Worker} 80*333d2b36SAndroid Build Coastguard Worker 81*333d2b36SAndroid Build Coastguard Worker// append appends all the files from the supplied info to the corresponding files in this struct. 82*333d2b36SAndroid Build Coastguard Workerfunc (i *MonolithicHiddenAPIInfo) append(ctx android.ModuleContext, otherModule android.Module, other *HiddenAPIInfo) { 83*333d2b36SAndroid Build Coastguard Worker i.FlagsFilesByCategory.append(other.FlagFilesByCategory) 84*333d2b36SAndroid Build Coastguard Worker i.AnnotationFlagsPaths = append(i.AnnotationFlagsPaths, other.AnnotationFlagsPath) 85*333d2b36SAndroid Build Coastguard Worker i.MetadataPaths = append(i.MetadataPaths, other.MetadataPath) 86*333d2b36SAndroid Build Coastguard Worker i.IndexPaths = append(i.IndexPaths, other.IndexPath) 87*333d2b36SAndroid Build Coastguard Worker 88*333d2b36SAndroid Build Coastguard Worker apexInfo, ok := android.OtherModuleProvider(ctx, otherModule, android.ApexInfoProvider) 89*333d2b36SAndroid Build Coastguard Worker if !ok { 90*333d2b36SAndroid Build Coastguard Worker ctx.ModuleErrorf("Could not determine min_version_version of %s\n", otherModule.Name()) 91*333d2b36SAndroid Build Coastguard Worker return 92*333d2b36SAndroid Build Coastguard Worker } 93*333d2b36SAndroid Build Coastguard Worker if apexInfo.MinSdkVersion.LessThanOrEqualTo(android.ApiLevelR) { 94*333d2b36SAndroid Build Coastguard Worker // Restrict verify_overlaps to R and older modules. 95*333d2b36SAndroid Build Coastguard Worker // The runtime in S does not have the same restriction that 96*333d2b36SAndroid Build Coastguard Worker // requires the hiddenapi flags to be generated in a monolithic 97*333d2b36SAndroid Build Coastguard Worker // invocation. 98*333d2b36SAndroid Build Coastguard Worker i.StubFlagSubsets = append(i.StubFlagSubsets, other.StubFlagSubset()) 99*333d2b36SAndroid Build Coastguard Worker i.FlagSubsets = append(i.FlagSubsets, other.FlagSubset()) 100*333d2b36SAndroid Build Coastguard Worker } 101*333d2b36SAndroid Build Coastguard Worker} 102*333d2b36SAndroid Build Coastguard Worker 103*333d2b36SAndroid Build Coastguard Workervar MonolithicHiddenAPIInfoProvider = blueprint.NewProvider[MonolithicHiddenAPIInfo]() 104