blob: 20b29a7c4ac326167d6a7af4a59b5a58265469d3 [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 }
40 soongVariablesPath := PathForOutput(ctx, "soong."+targetProduct+"variables")
41 extraVariablesPath := PathForOutput(ctx, "soong."+targetProduct+"extra.variables")
42
43 rule := NewRuleBuilder(pctx, ctx)
44 rule.Command().BuiltTool("merge_json").
45 Output(outputFilePath).
46 Input(soongVariablesPath).
47 Input(extraVariablesPath).
48 rule.Build("product_config.json", "building product_config.json")
49
50 ctx.SetOutputFiles(Paths{outputFilePath}, "")
51}
52
53// product_config module exports product variables and extra variables as a JSON file.
54func productConfigFactory() Module {
55 module := &productConfigModule{}
56 InitAndroidModule(module)
57 return module
58}