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
This commit is contained in:
Bob Badour
2020-02-18 20:21:55 -08:00
parent 004d717158
commit a75b057e17
8 changed files with 56 additions and 28 deletions

View File

@@ -236,8 +236,8 @@ func (a *AndroidMkEntries) fillInEntries(config Config, bpPath string, mod bluep
} }
} }
if amod.noticeFile.Valid() { if len(amod.noticeFiles) > 0 {
a.SetString("LOCAL_NOTICE_FILE", amod.noticeFile.String()) a.SetString("LOCAL_NOTICE_FILE", strings.Join(amod.noticeFiles.Strings(), " "))
} }
if host { if host {

View File

@@ -218,7 +218,7 @@ type Module interface {
ExportedToMake() bool ExportedToMake() bool
InitRc() Paths InitRc() Paths
VintfFragments() Paths VintfFragments() Paths
NoticeFile() OptionalPath NoticeFiles() Paths
AddProperties(props ...interface{}) AddProperties(props ...interface{})
GetProperties() []interface{} GetProperties() []interface{}
@@ -645,7 +645,7 @@ type ModuleBase struct {
noAddressSanitizer bool noAddressSanitizer bool
installFiles Paths installFiles Paths
checkbuildFiles Paths checkbuildFiles Paths
noticeFile OptionalPath noticeFiles Paths
// Used by buildTargetSingleton to create checkbuild and per-directory build targets // Used by buildTargetSingleton to create checkbuild and per-directory build targets
// Only set on the final variant of each module // Only set on the final variant of each module
@@ -904,8 +904,8 @@ func (m *ModuleBase) Owner() string {
return String(m.commonProperties.Owner) return String(m.commonProperties.Owner)
} }
func (m *ModuleBase) NoticeFile() OptionalPath { func (m *ModuleBase) NoticeFiles() Paths {
return m.noticeFile return m.noticeFiles
} }
func (m *ModuleBase) setImageVariation(variant string) { 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 != "" { if module := SrcIsModule(notice); module != "" {
m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice") optPath = ctx.ExpandOptionalSource(&notice, "notice")
} else { } else if notice != "" {
noticePath := filepath.Join(ctx.ModuleDir(), 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) m.module.GenerateAndroidBuildActions(ctx)

View File

@@ -120,8 +120,8 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo
fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " ")) fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
} }
if fi.module != nil && fi.module.NoticeFile().Valid() { if fi.module != nil && len(fi.module.NoticeFiles()) > 0 {
fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", fi.module.NoticeFile().Path().String()) fmt.Fprintln(w, "LOCAL_NOTICE_FILE :=", strings.Join(fi.module.NoticeFiles().Strings(), " "))
} }
} else { } else {
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated) fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", pathWhenActivated)

View File

@@ -215,15 +215,15 @@ func (a *apexBundle) buildNoticeFiles(ctx android.ModuleContext, apexFileName st
noticeFiles := []android.Path{} noticeFiles := []android.Path{}
for _, f := range a.filesInfo { for _, f := range a.filesInfo {
if f.module != nil { if f.module != nil {
notice := f.module.NoticeFile() notices := f.module.NoticeFiles()
if notice.Valid() { if len(notices) > 0 {
noticeFiles = append(noticeFiles, notice.Path()) noticeFiles = append(noticeFiles, notices...)
} }
} }
} }
// append the notice file specified in the apex module itself // append the notice file specified in the apex module itself
if a.NoticeFile().Valid() { if len(a.NoticeFiles()) > 0 {
noticeFiles = append(noticeFiles, a.NoticeFile().Path()) noticeFiles = append(noticeFiles, a.NoticeFiles()...)
} }
if len(noticeFiles) == 0 { if len(noticeFiles) == 0 {

View File

@@ -117,6 +117,17 @@ func copyFile(ctx android.SingletonContext, path android.Path, out string) andro
return outPath 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 { func writeStringToFile(ctx android.SingletonContext, content, out string) android.OutputPath {
outPath := android.PathForOutput(ctx, out) outPath := android.PathForOutput(ctx, out)
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{

View File

@@ -661,14 +661,14 @@ func (c *vendorSnapshotSingleton) GenerateBuildActions(ctx android.SingletonCont
headers = append(headers, exportedHeaders(ctx, l)...) headers = append(headers, exportedHeaders(ctx, l)...)
} }
if m.NoticeFile().Valid() { if len(m.NoticeFiles()) > 0 {
noticeName := ctx.ModuleName(m) + ".txt" noticeName := ctx.ModuleName(m) + ".txt"
noticeOut := filepath.Join(noticeDir, noticeName) noticeOut := filepath.Join(noticeDir, noticeName)
// skip already copied notice file // skip already copied notice file
if !installedNotices[noticeOut] { if !installedNotices[noticeOut] {
installedNotices[noticeOut] = true installedNotices[noticeOut] = true
snapshotOutputs = append(snapshotOutputs, copyFile( snapshotOutputs = append(snapshotOutputs, combineNotices(
ctx, m.NoticeFile().Path(), noticeOut)) ctx, m.NoticeFiles(), noticeOut))
} }
} }
}) })

View File

@@ -644,13 +644,13 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex
moduleNames[stem] = ctx.ModuleName(m) moduleNames[stem] = ctx.ModuleName(m)
modulePaths[stem] = ctx.ModuleDir(m) modulePaths[stem] = ctx.ModuleDir(m)
if m.NoticeFile().Valid() { if len(m.NoticeFiles()) > 0 {
noticeName := stem + ".txt" noticeName := stem + ".txt"
// skip already copied notice file // skip already copied notice file
if _, ok := noticeBuilt[noticeName]; !ok { if _, ok := noticeBuilt[noticeName]; !ok {
noticeBuilt[noticeName] = true noticeBuilt[noticeName] = true
snapshotOutputs = append(snapshotOutputs, copyFile( snapshotOutputs = append(snapshotOutputs, combineNotices(
ctx, m.NoticeFile().Path(), filepath.Join(noticeDir, noticeName))) ctx, m.NoticeFiles(), filepath.Join(noticeDir, noticeName)))
} }
} }

View File

@@ -390,16 +390,20 @@ func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext) {
return false return false
} }
path := child.(android.Module).NoticeFile() paths := child.(android.Module).NoticeFiles()
if path.Valid() { if len(paths) > 0 {
noticePathSet[path.Path()] = true for _, path := range paths {
noticePathSet[path] = true
}
} }
return true return true
}) })
// If the app has one, add it too. // If the app has one, add it too.
if a.NoticeFile().Valid() { if len(a.NoticeFiles()) > 0 {
noticePathSet[a.NoticeFile().Path()] = true for _, path := range a.NoticeFiles() {
noticePathSet[path] = true
}
} }
if len(noticePathSet) == 0 { if len(noticePathSet) == 0 {