blob: 0eb0efc95a01a1272663d819c4d89a40c09a1858 [file] [log] [blame]
Inseob Kim5eb7ee92022-04-27 10:30:34 +09001// Copyright 2022 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 multitree
16
17import (
18 "android/soong/android"
19 "encoding/json"
20)
21
22func init() {
LaMont Jones0c10e4d2023-05-16 00:58:37 +000023 android.RegisterParallelSingletonType("update-meta", UpdateMetaSingleton)
Inseob Kim5eb7ee92022-04-27 10:30:34 +090024}
25
26func UpdateMetaSingleton() android.Singleton {
27 return &updateMetaSingleton{}
28}
29
30type jsonImported struct {
31 FileGroups map[string][]string `json:",omitempty"`
32}
33
34type metadataJsonFlags struct {
35 Imported jsonImported `json:",omitempty"`
36 Exported map[string][]string `json:",omitempty"`
37}
38
39type updateMetaSingleton struct {
40 importedModules []string
41 generatedMetadataFile android.OutputPath
42}
43
44func (s *updateMetaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
45 metadata := metadataJsonFlags{
46 Imported: jsonImported{
47 FileGroups: make(map[string][]string),
48 },
49 Exported: make(map[string][]string),
50 }
51 ctx.VisitAllModules(func(module android.Module) {
52 if ifg, ok := module.(*importedFileGroup); ok {
53 metadata.Imported.FileGroups[ifg.BaseModuleName()] = ifg.properties.Imported
54 }
55 if e, ok := module.(ExportableModule); ok {
56 if e.IsExported() && e.Exportable() {
57 for tag, files := range e.TaggedOutputs() {
58 // TODO(b/219846705): refactor this to a dictionary
59 metadata.Exported[e.Name()+":"+tag] = append(metadata.Exported[e.Name()+":"+tag], files.Strings()...)
60 }
61 }
62 }
63 })
64 jsonStr, err := json.Marshal(metadata)
65 if err != nil {
66 ctx.Errorf(err.Error())
67 }
68 s.generatedMetadataFile = android.PathForOutput(ctx, "multitree", "metadata.json")
69 android.WriteFileRule(ctx, s.generatedMetadataFile, string(jsonStr))
70}
71
72func (s *updateMetaSingleton) MakeVars(ctx android.MakeVarsContext) {
73 ctx.Strict("MULTITREE_METADATA", s.generatedMetadataFile.String())
74}