diff options
author | 2025-02-12 10:51:25 -0800 | |
---|---|---|
committer | 2025-02-12 10:51:25 -0800 | |
commit | 68cf83767472acb312b6252b5c8f4404dd3d581c (patch) | |
tree | d43fd51e2e7322ec97b421aefc73ae3107bbe40a /aconfig | |
parent | e6ed8ddf2c85c65332844868aab06c9a738377a3 (diff) | |
parent | e21c64436391ad3f9626f247e08a35c0cff46a3e (diff) |
Merge "Introduce all_aconfig_declarations_extension module type" into main am: 080e810c9f am: e21c644363
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/3473459
Change-Id: Ieb5fbb0638bb2f934ffc3ff737b1af7407f28994
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'aconfig')
-rw-r--r-- | aconfig/Android.bp | 2 | ||||
-rw-r--r-- | aconfig/all_aconfig_declarations.go | 40 | ||||
-rw-r--r-- | aconfig/all_aconfig_declarations_extension.go | 90 | ||||
-rw-r--r-- | aconfig/all_aconfig_declarations_extension_test.go | 50 | ||||
-rw-r--r-- | aconfig/init.go | 1 |
5 files changed, 172 insertions, 11 deletions
diff --git a/aconfig/Android.bp b/aconfig/Android.bp index 6daa63c55..3de11873b 100644 --- a/aconfig/Android.bp +++ b/aconfig/Android.bp @@ -17,6 +17,7 @@ bootstrap_go_package { "aconfig_values.go", "aconfig_value_set.go", "all_aconfig_declarations.go", + "all_aconfig_declarations_extension.go", "exported_java_aconfig_library.go", "init.go", "testing.go", @@ -25,6 +26,7 @@ bootstrap_go_package { "aconfig_declarations_test.go", "aconfig_values_test.go", "aconfig_value_set_test.go", + "all_aconfig_declarations_extension_test.go", ], pluginFor: ["soong_build"], } diff --git a/aconfig/all_aconfig_declarations.go b/aconfig/all_aconfig_declarations.go index ec200997e..b17820ea5 100644 --- a/aconfig/all_aconfig_declarations.go +++ b/aconfig/all_aconfig_declarations.go @@ -20,6 +20,7 @@ import ( "android/soong/android" + "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) @@ -37,12 +38,18 @@ func AllAconfigDeclarationsFactory() android.SingletonModule { return module } +type allAconfigDeclarationsInfo struct { + parsedFlagsFile android.Path +} + +var allAconfigDeclarationsInfoProvider = blueprint.NewProvider[allAconfigDeclarationsInfo]() + type allAconfigReleaseDeclarationsSingleton struct { intermediateBinaryProtoPath android.OutputPath intermediateTextProtoPath android.OutputPath } -type allAconfigReleaseDeclarationsProperties struct { +type ApiSurfaceContributorProperties struct { Api_signature_files proptools.Configurable[[]string] `android:"arch_variant,path"` Finalized_flags_file string `android:"arch_variant,path"` } @@ -51,7 +58,9 @@ type allAconfigDeclarationsSingleton struct { android.SingletonModuleBase releaseMap map[string]allAconfigReleaseDeclarationsSingleton - properties allAconfigReleaseDeclarationsProperties + properties ApiSurfaceContributorProperties + + finalizedFlags android.OutputPath } func (this *allAconfigDeclarationsSingleton) sortedConfigNames() []string { @@ -63,29 +72,38 @@ func (this *allAconfigDeclarationsSingleton) sortedConfigNames() []string { return names } -func (this *allAconfigDeclarationsSingleton) GenerateAndroidBuildActions(ctx android.ModuleContext) { +func GenerateFinalizedFlagsForApiSurface(ctx android.ModuleContext, outputPath android.WritablePath, + parsedFlagsFile android.Path, apiSurface ApiSurfaceContributorProperties) { + apiSignatureFiles := android.Paths{} - for _, apiSignatureFile := range this.properties.Api_signature_files.GetOrDefault(ctx, nil) { + for _, apiSignatureFile := range apiSurface.Api_signature_files.GetOrDefault(ctx, nil) { if path := android.PathForModuleSrc(ctx, apiSignatureFile); path != nil { apiSignatureFiles = append(apiSignatureFiles, path) } } - finalizedFlagsFile := android.PathForModuleSrc(ctx, this.properties.Finalized_flags_file) - parsedFlagsFile := android.PathForIntermediates(ctx, "all_aconfig_declarations.pb") - - output := android.PathForIntermediates(ctx, "finalized-flags.txt") + finalizedFlagsFile := android.PathForModuleSrc(ctx, apiSurface.Finalized_flags_file) ctx.Build(pctx, android.BuildParams{ Rule: RecordFinalizedFlagsRule, Inputs: append(apiSignatureFiles, finalizedFlagsFile, parsedFlagsFile), - Output: output, + Output: outputPath, Args: map[string]string{ "api_signature_files": android.JoinPathsWithPrefix(apiSignatureFiles, "--api-signature-file "), "finalized_flags_file": "--finalized-flags-file " + finalizedFlagsFile.String(), "parsed_flags_file": "--parsed-flags-file " + parsedFlagsFile.String(), }, }) - ctx.Phony("all_aconfig_declarations", output) +} + +func (this *allAconfigDeclarationsSingleton) GenerateAndroidBuildActions(ctx android.ModuleContext) { + parsedFlagsFile := android.PathForIntermediates(ctx, "all_aconfig_declarations.pb") + this.finalizedFlags = android.PathForIntermediates(ctx, "finalized-flags.txt") + GenerateFinalizedFlagsForApiSurface(ctx, this.finalizedFlags, parsedFlagsFile, this.properties) + ctx.Phony("all_aconfig_declarations", this.finalizedFlags) + + android.SetProvider(ctx, allAconfigDeclarationsInfoProvider, allAconfigDeclarationsInfo{ + parsedFlagsFile: parsedFlagsFile, + }) } func (this *allAconfigDeclarationsSingleton) GenerateSingletonBuildActions(ctx android.SingletonContext) { @@ -154,5 +172,5 @@ func (this *allAconfigDeclarationsSingleton) MakeVars(ctx android.MakeVarsContex ctx.DistForGoalWithFilename(goal, this.releaseMap[rcName].intermediateTextProtoPath, assembleFileName(rcName, "flags.textproto")) } } - ctx.DistForGoalWithFilename("sdk", android.PathForIntermediates(ctx, "finalized-flags.txt"), "finalized-flags.txt") + ctx.DistForGoalWithFilename("sdk", this.finalizedFlags, "finalized-flags.txt") } diff --git a/aconfig/all_aconfig_declarations_extension.go b/aconfig/all_aconfig_declarations_extension.go new file mode 100644 index 000000000..44992cd2a --- /dev/null +++ b/aconfig/all_aconfig_declarations_extension.go @@ -0,0 +1,90 @@ +// Copyright 2025 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package aconfig + +import ( + "android/soong/android" + "path" + + "github.com/google/blueprint" + "github.com/google/blueprint/proptools" +) + +func AllAconfigDeclarationsExtensionFactory() android.Module { + module := &allAconfigDeclarationsExtension{} + module.AddProperties(&module.properties) + android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) + return module +} + +type allAconfigDeclarationsExtensionProperties struct { + // all_aconfig_declarations module that this module extends. Defaults to + // all_aconfig_declarations. + Base *string + + // Directory where the dist artifact should be placed in. + Dist_dir *string + + ApiSurfaceContributorProperties +} + +type allAconfigDeclarationsExtension struct { + android.ModuleBase + + properties allAconfigDeclarationsExtensionProperties + + finalizedFlags android.ModuleOutPath +} + +type allAconfigDeclarationsDependencyTagStruct struct { + blueprint.BaseDependencyTag +} + +var allAconfigDeclarationsDependencyTag allAconfigDeclarationsDependencyTagStruct + +func (ext *allAconfigDeclarationsExtension) DepsMutator(ctx android.BottomUpMutatorContext) { + ctx.AddDependency(ctx.Module(), allAconfigDeclarationsDependencyTag, proptools.StringDefault(ext.properties.Base, "all_aconfig_declarations")) +} + +func (ext *allAconfigDeclarationsExtension) GenerateAndroidBuildActions(ctx android.ModuleContext) { + + var parsedFlagsFile android.Path + ctx.VisitDirectDepsProxyWithTag(allAconfigDeclarationsDependencyTag, func(proxy android.ModuleProxy) { + if info, ok := android.OtherModuleProvider(ctx, proxy, allAconfigDeclarationsInfoProvider); ok { + parsedFlagsFile = info.parsedFlagsFile + } else { + ctx.PropertyErrorf("base", "base must provide allAconfigDeclarationsInfo") + } + }) + + ext.finalizedFlags = android.PathForModuleOut(ctx, "finalized-flags.txt") + + GenerateFinalizedFlagsForApiSurface(ctx, + ext.finalizedFlags, + parsedFlagsFile, + ext.properties.ApiSurfaceContributorProperties, + ) + + ctx.Phony(ctx.ModuleName(), ext.finalizedFlags) + + // This module must not set any provider or call `ctx.SetOutputFiles`! + // This module is only used to depend on the singleton module all_aconfig_declarations and + // generate the custom finalized-flags.txt file in dist builds, and should not be depended + // by other modules. +} + +func (ext *allAconfigDeclarationsExtension) MakeVars(ctx android.MakeVarsContext) { + ctx.DistForGoalWithFilename("sdk", ext.finalizedFlags, path.Join(proptools.String(ext.properties.Dist_dir), "finalized-flags.txt")) +} diff --git a/aconfig/all_aconfig_declarations_extension_test.go b/aconfig/all_aconfig_declarations_extension_test.go new file mode 100644 index 000000000..120709693 --- /dev/null +++ b/aconfig/all_aconfig_declarations_extension_test.go @@ -0,0 +1,50 @@ +// Copyright 2025 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package aconfig + +import ( + "strings" + "testing" + + "android/soong/android" +) + +func TestAllAconfigDeclarationsExtension(t *testing.T) { + result := android.GroupFixturePreparers( + PrepareForTestWithAconfigBuildComponents, + android.FixtureMergeMockFs( + android.MockFS{ + "a.txt": nil, + "flags.txt": nil, + }, + ), + ).RunTestWithBp(t, ` + all_aconfig_declarations { + name: "all_aconfig_declarations", + } + + all_aconfig_declarations_extension { + name: "custom_aconfig_declarations", + base: "all_aconfig_declarations", + api_signature_files: [ + "a.txt", + ], + finalized_flags_file: "flags.txt", + } + `) + + finalizedFlags := result.ModuleForTests("custom_aconfig_declarations", "").Output("finalized-flags.txt") + android.AssertStringContainsEquals(t, "must depend on all_aconfig_declarations", strings.Join(finalizedFlags.Inputs.Strings(), " "), "all_aconfig_declarations.pb", true) +} diff --git a/aconfig/init.go b/aconfig/init.go index 3dcec5cd8..210aec3b9 100644 --- a/aconfig/init.go +++ b/aconfig/init.go @@ -131,4 +131,5 @@ func RegisterBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory) ctx.RegisterSingletonModuleType("all_aconfig_declarations", AllAconfigDeclarationsFactory) ctx.RegisterParallelSingletonType("exported_java_aconfig_library", ExportedJavaDeclarationsLibraryFactory) + ctx.RegisterModuleType("all_aconfig_declarations_extension", AllAconfigDeclarationsExtensionFactory) } |