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 output := android.PathForModuleOut(ctx, "NOTICE.xml.gz") 75 metadataDb := android.PathForOutput(ctx, "compliance-metadata", ctx.Config().DeviceProduct(), "compliance-metadata.db") 76 ctx.Build(pctx, android.BuildParams{ 77 Rule: genNoticeXmlRule, 78 Input: metadataDb, 79 Output: output, 80 Args: map[string]string{ 81 "productOut": filepath.Join(ctx.Config().OutDir(), "target", "product", ctx.Config().DeviceName()), 82 "soongOut": ctx.Config().SoongOutDir(), 83 "partition": nx.props.Partition_name, 84 }, 85 }) 86 87 nx.outputFile = output.OutputPath 88 89 installPath := android.PathForModuleInPartitionInstall(ctx, nx.props.Partition_name, "etc") 90 ctx.PackageFile(installPath, "NOTICE.xml.gz", nx.outputFile) 91} 92 93func (nx *NoticeXmlModule) AndroidMkEntries() []android.AndroidMkEntries { 94 return []android.AndroidMkEntries{{ 95 Class: "ETC", 96 OutputFile: android.OptionalPathForPath(nx.outputFile), 97 }} 98} 99