Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 1 | // Copyright 2023 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 | |
| 15 | package aconfig |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/java" |
| 20 | "fmt" |
| 21 | "github.com/google/blueprint" |
| 22 | ) |
| 23 | |
| 24 | type declarationsTagType struct { |
| 25 | blueprint.BaseDependencyTag |
| 26 | } |
| 27 | |
| 28 | var declarationsTag = declarationsTagType{} |
| 29 | |
| 30 | type JavaAconfigDeclarationsLibraryProperties struct { |
| 31 | // name of the aconfig_declarations module to generate a library for |
| 32 | Aconfig_declarations string |
| 33 | } |
| 34 | |
| 35 | type JavaAconfigDeclarationsLibraryCallbacks struct { |
| 36 | properties JavaAconfigDeclarationsLibraryProperties |
| 37 | } |
| 38 | |
| 39 | func JavaDeclarationsLibraryFactory() android.Module { |
| 40 | callbacks := &JavaAconfigDeclarationsLibraryCallbacks{} |
| 41 | return java.GeneratedJavaLibraryModuleFactory("java_aconfig_library", callbacks, &callbacks.properties) |
| 42 | } |
| 43 | |
| 44 | func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) DepsMutator(module *java.GeneratedJavaLibraryModule, ctx android.BottomUpMutatorContext) { |
| 45 | declarations := callbacks.properties.Aconfig_declarations |
| 46 | if len(declarations) == 0 { |
| 47 | // TODO: Add test for this case |
| 48 | ctx.PropertyErrorf("aconfig_declarations", "aconfig_declarations property required") |
| 49 | } else { |
| 50 | ctx.AddDependency(ctx.Module(), declarationsTag, declarations) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) GenerateSourceJarBuildActions(ctx android.ModuleContext) android.Path { |
| 55 | // Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag |
| 56 | declarationsModules := ctx.GetDirectDepsWithTag(declarationsTag) |
| 57 | if len(declarationsModules) != 1 { |
| 58 | panic(fmt.Errorf("Exactly one aconfig_declarations property required")) |
| 59 | } |
| 60 | declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData) |
| 61 | |
| 62 | srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar") |
| 63 | ctx.Build(pctx, android.BuildParams{ |
Joe Onorato | 37f900c | 2023-07-18 16:58:16 -0700 | [diff] [blame^] | 64 | Rule: javaRule, |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 65 | Input: declarations.IntermediatePath, |
| 66 | Output: srcJarPath, |
| 67 | Description: "aconfig.srcjar", |
| 68 | }) |
| 69 | |
| 70 | return srcJarPath |
| 71 | } |