1// 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 compliance 16 17import ( 18 "path/filepath" 19 20 "android/soong/android" 21 22 "github.com/google/blueprint" 23) 24 25func init() { 26 RegisterNoticeXmlBuildComponents(android.InitRegistrationContext) 27} 28 29var PrepareForTestWithNoticeXmlBuildComponents = android.GroupFixturePreparers( 30 android.FixtureRegisterWithContext(RegisterNoticeXmlBuildComponents), 31) 32 33var PrepareForTestWithNoticeXml = android.GroupFixturePreparers( 34 PrepareForTestWithNoticeXmlBuildComponents, 35) 36 37func RegisterNoticeXmlBuildComponents(ctx android.RegistrationContext) { 38 ctx.RegisterModuleType("notice_xml", NoticeXmlFactory) 39} 40 41var ( 42 pctx = android.NewPackageContext("android/soong/compliance") 43 44 genNoticeXml = pctx.HostBinToolVariable("genNoticeXml", "gen_notice_xml") 45 46 // Command to generate NOTICE.xml.gz for a partition 47 genNoticeXmlRule = pctx.AndroidStaticRule("genNoticeXmlRule", blueprint.RuleParams{ 48 Command: "rm -rf $out && " + 49 "${genNoticeXml} --output_file ${out} --metadata ${in} --partition ${partition} --product_out ${productOut} --soong_out ${soongOut}", 50 CommandDeps: []string{"${genNoticeXml}"}, 51 }, "partition", "productOut", "soongOut") 52) 53 54func NoticeXmlFactory() android.Module { 55 m := &NoticeXmlModule{} 56 m.AddProperties(&m.props) 57 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibFirst) 58 return m 59} 60 61type NoticeXmlModule struct { 62 android.ModuleBase 63 64 props noticeXmlProperties 65 66 outputFile android.OutputPath 67} 68 69type noticeXmlProperties struct { 70 Partition_name string 71} 72 73func (nx *NoticeXmlModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { 74 prodVars := ctx.Config().ProductVariables() 75 buildFingerprintFile := android.PathForArbitraryOutput(ctx, "target", "product", android.String(prodVars.DeviceName), "build_fingerprint.txt") 76 implicits := []android.Path{buildFingerprintFile} 77 78 output := android.PathForModuleOut(ctx, "NOTICE.xml.gz") 79 metadataDb := android.PathForOutput(ctx, "compliance-metadata", ctx.Config().DeviceProduct(), "compliance-metadata.db") 80 ctx.Build(pctx, android.BuildParams{ 81 Rule: genNoticeXmlRule, 82 Input: metadataDb, 83 Implicits: implicits, 84 Output: output, 85 Args: map[string]string{ 86 "productOut": filepath.Join(ctx.Config().OutDir(), "target", "product", ctx.Config().DeviceName()), 87 "soongOut": ctx.Config().SoongOutDir(), 88 "partition": nx.props.Partition_name, 89 }, 90 }) 91 92 nx.outputFile = output.OutputPath 93 94 if android.Bool(ctx.Config().ProductVariables().UseSoongNoticeXML) { 95 installPath := android.PathForModuleInPartitionInstall(ctx, nx.props.Partition_name, "etc") 96 ctx.InstallFile(installPath, "NOTICE.xml.gz", nx.outputFile) 97 } 98} 99 100func (nx *NoticeXmlModule) AndroidMkEntries() []android.AndroidMkEntries { 101 return []android.AndroidMkEntries{{ 102 Class: "ETC", 103 OutputFile: android.OptionalPathForPath(nx.outputFile), 104 }} 105} 106