Wei Li | faf198a | 2024-09-19 19:53:41 +0000 | [diff] [blame^] | 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 | |
| 15 | package compliance |
| 16 | |
| 17 | import ( |
| 18 | "path/filepath" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | "github.com/google/blueprint" |
| 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | RegisterNoticeXmlBuildComponents(android.InitRegistrationContext) |
| 26 | } |
| 27 | |
| 28 | var PrepareForTestWithNoticeXmlBuildComponents = android.GroupFixturePreparers( |
| 29 | android.FixtureRegisterWithContext(RegisterNoticeXmlBuildComponents), |
| 30 | ) |
| 31 | |
| 32 | var PrepareForTestWithNoticeXml = android.GroupFixturePreparers( |
| 33 | PrepareForTestWithNoticeXmlBuildComponents, |
| 34 | ) |
| 35 | |
| 36 | func RegisterNoticeXmlBuildComponents(ctx android.RegistrationContext) { |
| 37 | ctx.RegisterModuleType("notice_xml", NoticeXmlFactory) |
| 38 | } |
| 39 | |
| 40 | var ( |
| 41 | pctx = android.NewPackageContext("android/soong/compliance") |
| 42 | |
| 43 | genNoticeXml = pctx.HostBinToolVariable("genNoticeXml", "gen_notice_xml") |
| 44 | |
| 45 | // Command to generate NOTICE.xml.gz for a partition |
| 46 | genNoticeXmlRule = pctx.AndroidStaticRule("genNoticeXmlRule", blueprint.RuleParams{ |
| 47 | Command: "rm -rf $out && " + |
| 48 | "${genNoticeXml} --output_file ${out} --metadata ${in} --partition ${partition} --product_out ${productOut} --soong_out ${soongOut}", |
| 49 | CommandDeps: []string{"${genNoticeXml}"}, |
| 50 | }, "partition", "productOut", "soongOut") |
| 51 | ) |
| 52 | |
| 53 | func NoticeXmlFactory() android.Module { |
| 54 | m := &NoticeXmlModule{} |
| 55 | m.AddProperties(&m.props) |
| 56 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibFirst) |
| 57 | return m |
| 58 | } |
| 59 | |
| 60 | type NoticeXmlModule struct { |
| 61 | android.ModuleBase |
| 62 | |
| 63 | props noticeXmlProperties |
| 64 | |
| 65 | outputFile android.OutputPath |
| 66 | installPath android.InstallPath |
| 67 | } |
| 68 | |
| 69 | type noticeXmlProperties struct { |
| 70 | Partition_name string |
| 71 | } |
| 72 | |
| 73 | func (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 | if android.Bool(ctx.Config().ProductVariables().UseSoongSystemImage) { |
| 90 | nx.installPath = android.PathForModuleInPartitionInstall(ctx, nx.props.Partition_name, "etc") |
| 91 | ctx.InstallFile(nx.installPath, "NOTICE.xml.gz", nx.outputFile) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | func (nx *NoticeXmlModule) AndroidMkEntries() []android.AndroidMkEntries { |
| 96 | return []android.AndroidMkEntries{{ |
| 97 | Class: "ETC", |
| 98 | OutputFile: android.OptionalPathForPath(nx.outputFile), |
| 99 | }} |
| 100 | } |