blob: 04180bf2bfd2b8df5741c9c55d8a0d3a3747cbef [file] [log] [blame]
Inseob Kim58c802f2024-06-11 10:59:00 +09001// Copyright 2024 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 android
16
17import "github.com/google/blueprint/proptools"
18
19func init() {
20 ctx := InitRegistrationContext
21 ctx.RegisterModuleType("product_config", productConfigFactory)
22}
23
24type productConfigModule struct {
25 ModuleBase
26}
27
28func (p *productConfigModule) GenerateAndroidBuildActions(ctx ModuleContext) {
29 if ctx.ModuleName() != "product_config" || ctx.ModuleDir() != "build/soong" {
30 ctx.ModuleErrorf("There can only be one product_config module in build/soong")
31 return
32 }
33 outputFilePath := PathForModuleOut(ctx, p.Name()+".json").OutputPath
34
35 // DeviceProduct can be null so calling ctx.Config().DeviceProduct() may cause null dereference
36 targetProduct := proptools.String(ctx.Config().config.productVariables.DeviceProduct)
37 if targetProduct != "" {
38 targetProduct += "."
39 }
Qing Shen713c5422024-08-23 04:09:18 +000040
41 coverageSuffix := ctx.Config().CoverageSuffix()
42 soongVariablesPath := PathForOutput(ctx, "soong."+targetProduct+coverageSuffix+"variables")
43 extraVariablesPath := PathForOutput(ctx, "soong."+targetProduct+coverageSuffix+"extra.variables")
Inseob Kim58c802f2024-06-11 10:59:00 +090044
45 rule := NewRuleBuilder(pctx, ctx)
46 rule.Command().BuiltTool("merge_json").
47 Output(outputFilePath).
48 Input(soongVariablesPath).
49 Input(extraVariablesPath).
50 rule.Build("product_config.json", "building product_config.json")
51
52 ctx.SetOutputFiles(Paths{outputFilePath}, "")
53}
54
55// product_config module exports product variables and extra variables as a JSON file.
56func productConfigFactory() Module {
57 module := &productConfigModule{}
58 InitAndroidModule(module)
59 return module
60}