blob: 0eeb14ffc9049d83c72d47c212928da025a4aad4 [file] [log] [blame]
Joe Onorato981c9262023-06-21 15:16:23 -07001// 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
15package aconfig
16
17import (
18 "android/soong/android"
19 "android/soong/java"
20 "fmt"
21 "github.com/google/blueprint"
22)
23
24type declarationsTagType struct {
25 blueprint.BaseDependencyTag
26}
27
28var declarationsTag = declarationsTagType{}
29
30type JavaAconfigDeclarationsLibraryProperties struct {
31 // name of the aconfig_declarations module to generate a library for
32 Aconfig_declarations string
33}
34
35type JavaAconfigDeclarationsLibraryCallbacks struct {
36 properties JavaAconfigDeclarationsLibraryProperties
37}
38
39func JavaDeclarationsLibraryFactory() android.Module {
40 callbacks := &JavaAconfigDeclarationsLibraryCallbacks{}
41 return java.GeneratedJavaLibraryModuleFactory("java_aconfig_library", callbacks, &callbacks.properties)
42}
43
44func (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
54func (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{
64 Rule: srcJarRule,
65 Input: declarations.IntermediatePath,
66 Output: srcJarPath,
67 Description: "aconfig.srcjar",
68 })
69
70 return srcJarPath
71}