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
15package aconfig
16
17import (
18	"android/soong/android"
19)
20
21func ExportedJavaDeclarationsLibraryFactory() android.Singleton {
22	return &exportedJavaDeclarationsLibrarySingleton{}
23}
24
25type exportedJavaDeclarationsLibrarySingleton struct {
26	intermediatePath android.OutputPath
27}
28
29func (this *exportedJavaDeclarationsLibrarySingleton) GenerateBuildActions(ctx android.SingletonContext) {
30	// Find all of the aconfig_declarations modules
31	var cacheFiles android.Paths
32	ctx.VisitAllModules(func(module android.Module) {
33		decl, ok := android.SingletonModuleProvider(ctx, module, android.AconfigDeclarationsProviderKey)
34		if !ok {
35			return
36		}
37		cacheFiles = append(cacheFiles, decl.IntermediateCacheOutputPath)
38	})
39
40	// Generate build action for aconfig
41	this.intermediatePath = android.PathForIntermediates(ctx, "exported_java_aconfig_library.jar")
42	ctx.Build(pctx, android.BuildParams{
43		Rule:        exportedJavaRule,
44		Inputs:      cacheFiles,
45		Output:      this.intermediatePath,
46		Description: "exported_java_aconfig_library",
47		Args: map[string]string{
48			"cache_files": android.JoinPathsWithPrefix(cacheFiles, " "),
49		},
50	})
51	ctx.Phony("exported_java_aconfig_library", this.intermediatePath)
52}
53
54func (this *exportedJavaDeclarationsLibrarySingleton) MakeVars(ctx android.MakeVarsContext) {
55	ctx.DistForGoalWithFilename("sdk", this.intermediatePath, "android-flags.jar")
56}
57