Notice support for APEX

Notice file for an APEX is created by merging notice files for the
modules included in it (plus the notice file for the APEX itself if
specified).

Notice files having the same content are not duplicated; it is emitted
only once.

Bug: 128701495
Test: m (apex_test is amended)
Test: m and inspect $(PRODUCT_OUT)/obj/NOTICE.txt to check there are
license entries for /system/apex/*.apex files

Change-Id: I169d91038291a6c71615de97cf5b03174afab5d4
This commit is contained in:
Jiyong Park
2019-03-18 12:01:38 +09:00
parent 5a3f31b284
commit 52818fcde8
5 changed files with 123 additions and 5 deletions

View File

@@ -90,6 +90,12 @@ var (
CommandDeps: []string{"${zip2zip}"},
Description: "app bundle",
}, "abi")
apexMergeNoticeRule = pctx.StaticRule("apexMergeNoticeRule", blueprint.RuleParams{
Command: `${mergenotice} --output $out $inputs`,
CommandDeps: []string{"${mergenotice}"},
Description: "merge notice files into $out",
}, "inputs")
)
var imageApexSuffix = ".apex"
@@ -138,6 +144,8 @@ func init() {
pctx.HostBinToolVariable("zip2zip", "zip2zip")
pctx.HostBinToolVariable("zipalign", "zipalign")
pctx.SourcePathVariable("mergenotice", "build/soong/scripts/mergenotice.py")
android.RegisterModuleType("apex", apexBundleFactory)
android.RegisterModuleType("apex_test", testApexBundleFactory)
android.RegisterModuleType("apex_defaults", defaultsFactory)
@@ -394,6 +402,8 @@ type apexBundle struct {
container_certificate_file android.Path
container_private_key_file android.Path
mergedNoticeFile android.WritablePath
// list of files to be included in this apex
filesInfo []apexFile
@@ -814,6 +824,8 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.installDir = android.PathForModuleInstall(ctx, "apex")
a.filesInfo = filesInfo
a.buildNoticeFile(ctx)
if a.apexTypes.zip() {
a.buildUnflattenedApex(ctx, zipApex)
}
@@ -827,6 +839,37 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
}
func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext) {
noticeFiles := []android.Path{}
noticeFilesString := []string{}
for _, f := range a.filesInfo {
if f.module != nil {
notice := f.module.NoticeFile()
if notice.Valid() {
noticeFiles = append(noticeFiles, notice.Path())
noticeFilesString = append(noticeFilesString, notice.Path().String())
}
}
}
// append the notice file specified in the apex module itself
if a.NoticeFile().Valid() {
noticeFiles = append(noticeFiles, a.NoticeFile().Path())
noticeFilesString = append(noticeFilesString, a.NoticeFile().Path().String())
}
if len(noticeFiles) > 0 {
a.mergedNoticeFile = android.PathForModuleOut(ctx, "NOTICE")
ctx.Build(pctx, android.BuildParams{
Rule: apexMergeNoticeRule,
Inputs: noticeFiles,
Output: a.mergedNoticeFile,
Args: map[string]string{
"inputs": strings.Join(noticeFilesString, " "),
},
})
}
}
func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) {
cert := String(a.properties.Certificate)
if cert != "" && android.SrcIsModule(cert) == "" {
@@ -1078,6 +1121,10 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, name, moduleDir string, apex
if len(fi.symlinks) > 0 {
fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
}
if fi.module != nil && fi.module.NoticeFile().Valid() {
fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String())
}
} else {
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)
}
@@ -1168,6 +1215,9 @@ func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkD
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", String(a.properties.Key))
if a.installable() && a.mergedNoticeFile != nil {
fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", a.mergedNoticeFile.String())
}
if len(moduleNames) > 0 {
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(moduleNames, " "))
}