From 68c165c145034c38d99db01ffbbe560c162fe9ab Mon Sep 17 00:00:00 2001 From: Wei Li Date: Wed, 18 Sep 2024 23:44:52 +0000 Subject: [PATCH] Add new module type notice_xml which is used to define modules that generate NOTICE.xml.gz for partitions. Bug: 330949782 Bug: 338342381 Test: lunch aosp_cf_x86_64_phone-trunk_staging-eng && m, and check that system/etc/NOTICE.xml.gz have all the XML elements. Test: lunch aosp_cf_x86_64_phone_soong_system-trunk_staging-eng && m, and check that system/etc/NOTICE.xml.gz has root element only. Change-Id: I82e90bd9aa3dabc605acfe8da697ab1f7e7ecf9b --- compliance/Android.bp | 36 ++++++++++++++ compliance/notice.go | 100 ++++++++++++++++++++++++++++++++++++++ compliance/notice_test.go | 38 +++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 compliance/Android.bp create mode 100644 compliance/notice.go create mode 100644 compliance/notice_test.go diff --git a/compliance/Android.bp b/compliance/Android.bp new file mode 100644 index 000000000..cb08e97af --- /dev/null +++ b/compliance/Android.bp @@ -0,0 +1,36 @@ +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +bootstrap_go_package { + name: "soong-compliance", + pkgPath: "android/soong/compliance", + deps: [ + "soong-android", + ], + srcs: [ + "notice.go", + ], + testSrcs: [ + ], + pluginFor: ["soong_build"], +} + +notice_xml { + name: "notice_xml_system", + partition_name: "system", +} diff --git a/compliance/notice.go b/compliance/notice.go new file mode 100644 index 000000000..4fc83ab70 --- /dev/null +++ b/compliance/notice.go @@ -0,0 +1,100 @@ +// Copyright 2024 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package compliance + +import ( + "path/filepath" + + "android/soong/android" + "github.com/google/blueprint" +) + +func init() { + RegisterNoticeXmlBuildComponents(android.InitRegistrationContext) +} + +var PrepareForTestWithNoticeXmlBuildComponents = android.GroupFixturePreparers( + android.FixtureRegisterWithContext(RegisterNoticeXmlBuildComponents), +) + +var PrepareForTestWithNoticeXml = android.GroupFixturePreparers( + PrepareForTestWithNoticeXmlBuildComponents, +) + +func RegisterNoticeXmlBuildComponents(ctx android.RegistrationContext) { + ctx.RegisterModuleType("notice_xml", NoticeXmlFactory) +} + +var ( + pctx = android.NewPackageContext("android/soong/compliance") + + genNoticeXml = pctx.HostBinToolVariable("genNoticeXml", "gen_notice_xml") + + // Command to generate NOTICE.xml.gz for a partition + genNoticeXmlRule = pctx.AndroidStaticRule("genNoticeXmlRule", blueprint.RuleParams{ + Command: "rm -rf $out && " + + "${genNoticeXml} --output_file ${out} --metadata ${in} --partition ${partition} --product_out ${productOut} --soong_out ${soongOut}", + CommandDeps: []string{"${genNoticeXml}"}, + }, "partition", "productOut", "soongOut") +) + +func NoticeXmlFactory() android.Module { + m := &NoticeXmlModule{} + m.AddProperties(&m.props) + android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibFirst) + return m +} + +type NoticeXmlModule struct { + android.ModuleBase + + props noticeXmlProperties + + outputFile android.OutputPath + installPath android.InstallPath +} + +type noticeXmlProperties struct { + Partition_name string +} + +func (nx *NoticeXmlModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { + output := android.PathForModuleOut(ctx, "NOTICE.xml.gz") + metadataDb := android.PathForOutput(ctx, "compliance-metadata", ctx.Config().DeviceProduct(), "compliance-metadata.db") + ctx.Build(pctx, android.BuildParams{ + Rule: genNoticeXmlRule, + Input: metadataDb, + Output: output, + Args: map[string]string{ + "productOut": filepath.Join(ctx.Config().OutDir(), "target", "product", ctx.Config().DeviceName()), + "soongOut": ctx.Config().SoongOutDir(), + "partition": nx.props.Partition_name, + }, + }) + + nx.outputFile = output.OutputPath + + if android.Bool(ctx.Config().ProductVariables().UseSoongSystemImage) { + nx.installPath = android.PathForModuleInPartitionInstall(ctx, nx.props.Partition_name, "etc") + ctx.InstallFile(nx.installPath, "NOTICE.xml.gz", nx.outputFile) + } +} + +func (nx *NoticeXmlModule) AndroidMkEntries() []android.AndroidMkEntries { + return []android.AndroidMkEntries{{ + Class: "ETC", + OutputFile: android.OptionalPathForPath(nx.outputFile), + }} +} diff --git a/compliance/notice_test.go b/compliance/notice_test.go new file mode 100644 index 000000000..6187e5332 --- /dev/null +++ b/compliance/notice_test.go @@ -0,0 +1,38 @@ +// Copyright 2024 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package compliance + +import ( + "testing" + + "android/soong/android" +) + +var prepareForNoticeXmlTest = android.GroupFixturePreparers( + android.PrepareForTestWithArchMutator, + PrepareForTestWithNoticeXml, +) + +func TestPrebuiltEtcOutputFile(t *testing.T) { + result := prepareForNoticeXmlTest.RunTestWithBp(t, ` + notice_xml { + name: "notice_xml_system", + partition_name: "system", + } + `) + + m := result.Module("notice_xml_system", "android_arm64_armv8-a").(*NoticeXmlModule) + android.AssertStringEquals(t, "output file", "NOTICE.xml.gz", m.outputFile.Base()) +} \ No newline at end of file