1// Copyright 2025 Google Inc. All rights reserved. 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 15package aconfig 16 17import ( 18 "android/soong/android" 19 "path" 20 21 "github.com/google/blueprint" 22 "github.com/google/blueprint/proptools" 23) 24 25func AllAconfigDeclarationsExtensionFactory() android.Module { 26 module := &allAconfigDeclarationsExtension{} 27 module.AddProperties(&module.properties) 28 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) 29 return module 30} 31 32type allAconfigDeclarationsExtensionProperties struct { 33 // all_aconfig_declarations module that this module extends. Defaults to 34 // all_aconfig_declarations. 35 Base *string 36 37 // Directory where the dist artifact should be placed in. 38 Dist_dir *string 39 40 ApiSurfaceContributorProperties 41} 42 43type allAconfigDeclarationsExtension struct { 44 android.ModuleBase 45 46 properties allAconfigDeclarationsExtensionProperties 47 48 finalizedFlags android.ModuleOutPath 49} 50 51type allAconfigDeclarationsDependencyTagStruct struct { 52 blueprint.BaseDependencyTag 53} 54 55var allAconfigDeclarationsDependencyTag allAconfigDeclarationsDependencyTagStruct 56 57func (ext *allAconfigDeclarationsExtension) DepsMutator(ctx android.BottomUpMutatorContext) { 58 ctx.AddDependency(ctx.Module(), allAconfigDeclarationsDependencyTag, proptools.StringDefault(ext.properties.Base, "all_aconfig_declarations")) 59} 60 61func (ext *allAconfigDeclarationsExtension) GenerateAndroidBuildActions(ctx android.ModuleContext) { 62 63 var parsedFlagsFile android.Path 64 ctx.VisitDirectDepsProxyWithTag(allAconfigDeclarationsDependencyTag, func(proxy android.ModuleProxy) { 65 if info, ok := android.OtherModuleProvider(ctx, proxy, allAconfigDeclarationsInfoProvider); ok { 66 parsedFlagsFile = info.parsedFlagsFile 67 } else { 68 ctx.PropertyErrorf("base", "base must provide allAconfigDeclarationsInfo") 69 } 70 }) 71 72 ext.finalizedFlags = android.PathForModuleOut(ctx, "finalized-flags.txt") 73 74 GenerateFinalizedFlagsForApiSurface(ctx, 75 ext.finalizedFlags, 76 parsedFlagsFile, 77 ext.properties.ApiSurfaceContributorProperties, 78 ) 79 80 ctx.Phony(ctx.ModuleName(), ext.finalizedFlags) 81 82 ctx.DistForGoalWithFilename("sdk", ext.finalizedFlags, path.Join(proptools.String(ext.properties.Dist_dir), "finalized-flags.txt")) 83 84 // This module must not set any provider or call `ctx.SetOutputFiles`! 85 // This module is only used to depend on the singleton module all_aconfig_declarations and 86 // generate the custom finalized-flags.txt file in dist builds, and should not be depended 87 // by other modules. 88} 89