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. There should be: 44 // 1. Exactly One "android-base.config" as common requirements. 45 // 2. Zero or more file with names that does NOT start with "android-base-" as extra common requirements. 46 // 3. Zero or more "android-base-foo.config" for requirements on condition CONFIG_FOO=y. 47 // (deprecated; use Meta to express conditional requirements instead.) 48 Srcs []string 49 50 // metadata XML file that contains minlts and complex conditional requirements. 51 Meta *string 52 53 // list of source files to replace Srcs on debuggable builds. See docs for Srcs. 54 Debuggable_srcs []string 55} 56 57type KernelConfigRule struct { 58 android.ModuleBase 59 properties KernelConfigProperties 60 61 outputPath android.WritablePath 62} 63 64func init() { 65 pctx.HostBinToolVariable("assembleVintfCmd", "assemble_vintf") 66 pctx.HostBinToolVariable("kconfigXmlFixupCmd", "kconfig_xml_fixup") 67 android.RegisterModuleType("kernel_config", kernelConfigFactory) 68} 69 70func kernelConfigFactory() android.Module { 71 g := &KernelConfigRule{} 72 g.AddProperties(&g.properties) 73 android.InitAndroidModule(g) 74 return g 75} 76 77func (g *KernelConfigRule) OutputPath() android.Path { 78 return g.outputPath 79} 80 81func (g *KernelConfigRule) realSrcs(ctx android.BaseModuleContext) []string { 82 if ctx.Config().Debuggable() && len(g.properties.Debuggable_srcs) > 0 { 83 return g.properties.Debuggable_srcs 84 } else { 85 return g.properties.Srcs 86 } 87} 88 89func (g *KernelConfigRule) DepsMutator(ctx android.BottomUpMutatorContext) { 90 android.ExtractSourcesDeps(ctx, g.realSrcs(ctx)) 91 android.ExtractSourceDeps(ctx, g.properties.Meta) 92} 93 94func (g *KernelConfigRule) GenerateAndroidBuildActions(ctx android.ModuleContext) { 95 g.outputPath = android.PathForModuleOut(ctx, "matrix_" + g.Name() + ".xml") 96 genVersion := android.PathForModuleGen(ctx, "version.txt") 97 genConditionals := android.PathForModuleGen(ctx, "conditional.xml") 98 inputMeta := android.PathForModuleSrc(ctx, proptools.String(g.properties.Meta)) 99 100 if proptools.String(g.properties.Meta) == "" { 101 ctx.PropertyErrorf("kernel_config", "Missing meta field") 102 } 103 104 ctx.Build(pctx, android.BuildParams{ 105 Rule: kconfigXmlFixupRule, 106 Description: "Fixup kernel config meta", 107 Input: inputMeta, 108 Output: genConditionals, 109 ImplicitOutput: genVersion, 110 Args: map[string]string{ 111 "outputVersion": genVersion.String(), 112 }, 113 }) 114 115 var kernelArg string 116 inputConfigs := android.PathsForModuleSrc(ctx, g.realSrcs(ctx)) 117 implicitInputs := append(inputConfigs, genVersion) 118 if len(inputConfigs) > 0 { 119 kernelArg = "--kernel=$$(cat " + genVersion.String() + "):" + 120 strings.Join(inputConfigs.Strings(), ":") 121 } 122 123 ctx.Build(pctx, android.BuildParams{ 124 Rule: assembleVintfRule, 125 Description: "Framework Compatibility Matrix kernel fragment", 126 Input: genConditionals, 127 Implicits: implicitInputs, 128 Output: g.outputPath, 129 Args: map[string]string{ 130 "flags": kernelArg, 131 }, 132 }) 133 134} 135