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