• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2018 The Android Open Source Project
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 configs
16
17import (
18	"strings"
19
20	"github.com/google/blueprint"
21	"github.com/google/blueprint/proptools"
22
23	"android/soong/android"
24)
25
26var (
27	pctx = android.NewPackageContext("android/soong/kernel/configs")
28
29	kconfigXmlFixupRule = pctx.AndroidStaticRule("kconfig_xml_fixup", blueprint.RuleParams{
30		Command:     `${kconfigXmlFixupCmd} --input ${in} --output-version ${outputVersion} --output-matrix ${out}`,
31		CommandDeps:  []string{"${kconfigXmlFixupCmd}"},
32		Description: "kconfig_xml_fixup ${in}",
33	}, "outputVersion")
34
35	assembleVintfRule = pctx.AndroidStaticRule("assemble_vintf", blueprint.RuleParams{
36		Command:     `${assembleVintfCmd} ${flags} -i ${in} -o ${out}`,
37		CommandDeps:  []string{"${assembleVintfCmd}"},
38		Description: "assemble_vintf -i ${in}",
39	}, "flags")
40)
41
42type KernelConfigProperties struct {
43	// list of source files that should be named "android-base.config" for common requirements
44	// and "android-base-foo.config" for requirements on condition CONFIG_FOO=y.
45	Srcs []string
46
47	// metadata XML file that contains minlts and complex conditional requirements.
48	Meta *string
49}
50
51type KernelConfigRule struct {
52	android.ModuleBase
53	properties KernelConfigProperties
54
55	outputPath android.WritablePath
56}
57
58func init() {
59	pctx.HostBinToolVariable("assembleVintfCmd", "assemble_vintf")
60	pctx.HostBinToolVariable("kconfigXmlFixupCmd", "kconfig_xml_fixup")
61	android.RegisterModuleType("kernel_config", kernelConfigFactory)
62}
63
64func kernelConfigFactory() android.Module {
65	g := &KernelConfigRule{}
66	g.AddProperties(&g.properties)
67	android.InitAndroidModule(g)
68	return g
69}
70
71func (g *KernelConfigRule) OutputPath() android.Path {
72	return g.outputPath
73}
74
75func (g *KernelConfigRule) DepsMutator(ctx android.BottomUpMutatorContext) {
76	android.ExtractSourcesDeps(ctx, g.properties.Srcs)
77	android.ExtractSourceDeps(ctx, g.properties.Meta)
78}
79
80func (g *KernelConfigRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
81	g.outputPath = android.PathForModuleOut(ctx, "matrix.xml")
82	genVersion := android.PathForModuleGen(ctx, "version.txt")
83	genConditionals := android.PathForModuleGen(ctx, "conditional.xml")
84	inputMeta := android.PathForModuleSrc(ctx, proptools.String(g.properties.Meta))
85
86	if proptools.String(g.properties.Meta) == "" {
87		ctx.PropertyErrorf("kernel_config", "Missing meta field")
88	}
89
90	ctx.Build(pctx, android.BuildParams{
91		Rule:           kconfigXmlFixupRule,
92		Description:    "Fixup kernel config meta",
93		Input:          inputMeta,
94		Output:         genConditionals,
95		ImplicitOutput: genVersion,
96		Args: map[string]string{
97			"outputVersion": genVersion.String(),
98		},
99	})
100
101	var kernelArg string
102	inputConfigs := android.PathsForModuleSrc(ctx, g.properties.Srcs)
103	implicitInputs := append(inputConfigs, genVersion)
104	if len(inputConfigs) > 0 {
105		kernelArg = "--kernel=$$(cat " + genVersion.String() + "):" +
106			strings.Join(inputConfigs.Strings(), ":")
107	}
108
109	ctx.Build(pctx, android.BuildParams{
110		Rule:        assembleVintfRule,
111		Description: "Framework Compatibility Matrix kernel fragment",
112		Input:       genConditionals,
113		Implicits:   implicitInputs,
114		Output:      g.outputPath,
115		Args: map[string]string{
116			"flags": kernelArg,
117		},
118	})
119
120}
121