From a75b057e17b89c1db8cdf3f8ec1a9dd42b82bd56 Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Tue, 18 Feb 2020 20:21:55 -0800 Subject: [PATCH] Unless overridden include LICENSE files in notices. As a second step to removing the go/android3p instructions to copy or to link NOTICE to LICENSE, include LICENSE files in the notices, which will allow deleting all of the copied/linked NOTICE files. The change causes a few additions to the system image notice files. Test: manually built and compared before and after notices Change-Id: Ia7bc58e2eba7bed5e63934881b5298201a93bc3e --- android/androidmk.go | 4 ++-- android/module.go | 29 +++++++++++++++++++++-------- apex/androidmk.go | 4 ++-- apex/builder.go | 10 +++++----- cc/snapshot_utils.go | 11 +++++++++++ cc/vendor_snapshot.go | 6 +++--- cc/vndk.go | 6 +++--- java/app.go | 14 +++++++++----- 8 files changed, 56 insertions(+), 28 deletions(-) diff --git a/android/androidmk.go b/android/androidmk.go index dbf3aa884..a8153ccdc 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -236,8 +236,8 @@ func (a *AndroidMkEntries) fillInEntries(config Config, bpPath string, mod bluep } } - if amod.noticeFile.Valid() { - a.SetString("LOCAL_NOTICE_FILE", amod.noticeFile.String()) + if len(amod.noticeFiles) > 0 { + a.SetString("LOCAL_NOTICE_FILE", strings.Join(amod.noticeFiles.Strings(), " ")) } if host { diff --git a/android/module.go b/android/module.go index fd3fec333..0598ca484 100644 --- a/android/module.go +++ b/android/module.go @@ -218,7 +218,7 @@ type Module interface { ExportedToMake() bool InitRc() Paths VintfFragments() Paths - NoticeFile() OptionalPath + NoticeFiles() Paths AddProperties(props ...interface{}) GetProperties() []interface{} @@ -645,7 +645,7 @@ type ModuleBase struct { noAddressSanitizer bool installFiles Paths checkbuildFiles Paths - noticeFile OptionalPath + noticeFiles Paths // Used by buildTargetSingleton to create checkbuild and per-directory build targets // Only set on the final variant of each module @@ -904,8 +904,8 @@ func (m *ModuleBase) Owner() string { return String(m.commonProperties.Owner) } -func (m *ModuleBase) NoticeFile() OptionalPath { - return m.noticeFile +func (m *ModuleBase) NoticeFiles() Paths { + return m.noticeFiles } func (m *ModuleBase) setImageVariation(variant string) { @@ -1151,12 +1151,25 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) } }) - notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE") + m.noticeFiles = make([]Path, 0) + optPath := OptionalPath{} + notice := proptools.StringDefault(m.commonProperties.Notice, "") if module := SrcIsModule(notice); module != "" { - m.noticeFile = ctx.ExpandOptionalSource(¬ice, "notice") - } else { + optPath = ctx.ExpandOptionalSource(¬ice, "notice") + } else if notice != "" { noticePath := filepath.Join(ctx.ModuleDir(), notice) - m.noticeFile = ExistentPathForSource(ctx, noticePath) + optPath = ExistentPathForSource(ctx, noticePath) + } + if optPath.Valid() { + m.noticeFiles = append(m.noticeFiles, optPath.Path()) + } else { + for _, notice = range []string{"LICENSE", "LICENCE", "NOTICE"} { + noticePath := filepath.Join(ctx.ModuleDir(), notice) + optPath = ExistentPathForSource(ctx, noticePath) + if optPath.Valid() { + m.noticeFiles = append(m.noticeFiles, optPath.Path()) + } + } } m.module.GenerateAndroidBuildActions(ctx) diff --git a/apex/androidmk.go b/apex/androidmk.go index 0abec0d93..da8254ab8 100644 --- a/apex/androidmk.go +++ b/apex/androidmk.go @@ -120,8 +120,8 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo 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()) + if fi.module != nil && len(fi.module.NoticeFiles()) > 0 { + fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(fi.module.NoticeFiles().Strings(), " ")) } } else { fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated) diff --git a/apex/builder.go b/apex/builder.go index 88c7098e6..b9736d395 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -215,15 +215,15 @@ func (a *apexBundle) buildNoticeFiles(ctx android.ModuleContext, apexFileName st noticeFiles := []android.Path{} for _, f := range a.filesInfo { if f.module != nil { - notice := f.module.NoticeFile() - if notice.Valid() { - noticeFiles = append(noticeFiles, notice.Path()) + notices := f.module.NoticeFiles() + if len(notices) > 0 { + noticeFiles = append(noticeFiles, notices...) } } } // append the notice file specified in the apex module itself - if a.NoticeFile().Valid() { - noticeFiles = append(noticeFiles, a.NoticeFile().Path()) + if len(a.NoticeFiles()) > 0 { + noticeFiles = append(noticeFiles, a.NoticeFiles()...) } if len(noticeFiles) == 0 { diff --git a/cc/snapshot_utils.go b/cc/snapshot_utils.go index 8f48f869b..73388ceb6 100644 --- a/cc/snapshot_utils.go +++ b/cc/snapshot_utils.go @@ -117,6 +117,17 @@ func copyFile(ctx android.SingletonContext, path android.Path, out string) andro return outPath } +func combineNotices(ctx android.SingletonContext, paths android.Paths, out string) android.OutputPath { + outPath := android.PathForOutput(ctx, out) + ctx.Build(pctx, android.BuildParams{ + Rule: android.Cat, + Inputs: paths, + Output: outPath, + Description: "combine notices for " + out, + }) + return outPath +} + func writeStringToFile(ctx android.SingletonContext, content, out string) android.OutputPath { outPath := android.PathForOutput(ctx, out) ctx.Build(pctx, android.BuildParams{ diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index aed79186f..20762a8f2 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -661,14 +661,14 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont headers = append(headers, exportedHeaders(ctx, l)...) } - if m.NoticeFile().Valid() { + if len(m.NoticeFiles()) > 0 { noticeName := ctx.ModuleName(m) + ".txt" noticeOut := filepath.Join(noticeDir, noticeName) // skip already copied notice file if !installedNotices[noticeOut] { installedNotices[noticeOut] = true - snapshotOutputs = append(snapshotOutputs, copyFile( - ctx, m.NoticeFile().Path(), noticeOut)) + snapshotOutputs = append(snapshotOutputs, combineNotices( + ctx, m.NoticeFiles(), noticeOut)) } } }) diff --git a/cc/vndk.go b/cc/vndk.go index 4578a7d13..d0492fc4f 100644 --- a/cc/vndk.go +++ b/cc/vndk.go @@ -644,13 +644,13 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex moduleNames[stem] = ctx.ModuleName(m) modulePaths[stem] = ctx.ModuleDir(m) - if m.NoticeFile().Valid() { + if len(m.NoticeFiles()) > 0 { noticeName := stem + ".txt" // skip already copied notice file if _, ok := noticeBuilt[noticeName]; !ok { noticeBuilt[noticeName] = true - snapshotOutputs = append(snapshotOutputs, copyFile( - ctx, m.NoticeFile().Path(), filepath.Join(noticeDir, noticeName))) + snapshotOutputs = append(snapshotOutputs, combineNotices( + ctx, m.NoticeFiles(), filepath.Join(noticeDir, noticeName))) } } diff --git a/java/app.go b/java/app.go index bcf08a775..8d32ababf 100755 --- a/java/app.go +++ b/java/app.go @@ -390,16 +390,20 @@ func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext) { return false } - path := child.(android.Module).NoticeFile() - if path.Valid() { - noticePathSet[path.Path()] = true + paths := child.(android.Module).NoticeFiles() + if len(paths) > 0 { + for _, path := range paths { + noticePathSet[path] = true + } } return true }) // If the app has one, add it too. - if a.NoticeFile().Valid() { - noticePathSet[a.NoticeFile().Path()] = true + if len(a.NoticeFiles()) > 0 { + for _, path := range a.NoticeFiles() { + noticePathSet[path] = true + } } if len(noticePathSet) == 0 {