Loading android/notices.go +29 −14 Original line number Diff line number Diff line Loading @@ -27,6 +27,13 @@ func init() { pctx.HostBinToolVariable("minigzip", "minigzip") } type NoticeOutputs struct { Merged OptionalPath TxtOutput OptionalPath HtmlOutput OptionalPath HtmlGzOutput OptionalPath } var ( mergeNoticesRule = pctx.AndroidStaticRule("mergeNoticesRule", blueprint.RuleParams{ Command: `${merge_notices} --output $out $in`, Loading @@ -35,13 +42,13 @@ var ( }) generateNoticeRule = pctx.AndroidStaticRule("generateNoticeRule", blueprint.RuleParams{ Command: `rm -rf $tmpDir $$(dirname $out) && ` + `mkdir -p $tmpDir $$(dirname $out) && ` + `${generate_notice} --text-output $tmpDir/NOTICE.txt --html-output $tmpDir/NOTICE.html -t "$title" -s $inputDir && ` + `${minigzip} -c $tmpDir/NOTICE.html > $out`, Command: `rm -rf $$(dirname $txtOut) $$(dirname htmlOut) $$(dirname $out) && ` + `mkdir -p $$(dirname $txtOut) $$(dirname htmlOut) $$(dirname $out) && ` + `${generate_notice} --text-output $txtOut --html-output $htmlOut -t "$title" -s $inputDir && ` + `${minigzip} -c $htmlOut > $out`, CommandDeps: []string{"${generate_notice}", "${minigzip}"}, Description: "produce notice file $out", }, "tmpDir", "title", "inputDir") }, "txtOut", "htmlOut", "title", "inputDir") ) func MergeNotices(ctx ModuleContext, mergedNotice WritablePath, noticePaths []Path) { Loading @@ -54,7 +61,7 @@ func MergeNotices(ctx ModuleContext, mergedNotice WritablePath, noticePaths []Pa } func BuildNoticeOutput(ctx ModuleContext, installPath OutputPath, installFilename string, noticePaths []Path) ModuleOutPath { noticePaths []Path) NoticeOutputs { // Merge all NOTICE files into one. // TODO(jungjw): We should just produce a well-formatted NOTICE.html file in a single pass. // Loading @@ -68,20 +75,28 @@ func BuildNoticeOutput(ctx ModuleContext, installPath OutputPath, installFilenam MergeNotices(ctx, mergedNotice, noticePaths) // Transform the merged NOTICE file into a gzipped HTML file. noticeOutput := PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz") tmpDir := PathForModuleOut(ctx, "NOTICE_tmp") txtOuptut := PathForModuleOut(ctx, "NOTICE_txt", "NOTICE.txt") htmlOutput := PathForModuleOut(ctx, "NOTICE_html", "NOTICE.html") htmlGzOutput := PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz") title := "Notices for " + ctx.ModuleName() ctx.Build(pctx, BuildParams{ Rule: generateNoticeRule, Description: "generate notice output", Input: mergedNotice, Output: noticeOutput, Output: htmlGzOutput, ImplicitOutputs: WritablePaths{txtOuptut, htmlOutput}, Args: map[string]string{ "tmpDir": tmpDir.String(), "txtOut": txtOuptut.String(), "htmlOut": htmlOutput.String(), "title": title, "inputDir": PathForModuleOut(ctx, "NOTICE_FILES/src").String(), }, }) return noticeOutput return NoticeOutputs{ Merged: OptionalPathForPath(mergedNotice), TxtOutput: OptionalPathForPath(txtOuptut), HtmlOutput: OptionalPathForPath(htmlOutput), HtmlGzOutput: OptionalPathForPath(htmlGzOutput), } } apex/apex.go +1 −2 Original line number Diff line number Diff line Loading @@ -905,8 +905,7 @@ func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName str return android.OptionalPath{} } return android.OptionalPathForPath( android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles))) return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput } func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) { Loading java/androidmk.go +12 −0 Original line number Diff line number Diff line Loading @@ -327,6 +327,18 @@ func (app *AndroidApp) AndroidMk() android.AndroidMkData { install := "$(LOCAL_MODULE_PATH)/" + strings.TrimSuffix(app.installApkName, ".apk") + split.suffix + ".apk" fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED +=", split.path.String()+":"+install) } if app.noticeOutputs.Merged.Valid() { fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", app.installApkName, app.noticeOutputs.Merged.String(), app.installApkName+"_NOTICE") } if app.noticeOutputs.TxtOutput.Valid() { fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", app.installApkName, app.noticeOutputs.TxtOutput.String(), app.installApkName+"_NOTICE.txt") } if app.noticeOutputs.HtmlOutput.Valid() { fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", app.installApkName, app.noticeOutputs.HtmlOutput.String(), app.installApkName+"_NOTICE.html") } }, }, } Loading java/app.go +9 −9 Original line number Diff line number Diff line Loading @@ -141,6 +141,8 @@ type AndroidApp struct { installApkName string additionalAaptFlags []string noticeOutputs android.NoticeOutputs } func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths { Loading Loading @@ -357,11 +359,7 @@ func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext return jniJarFile } func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext, installDir android.OutputPath) android.OptionalPath { if !Bool(a.appProperties.Embed_notices) && !ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") { return android.OptionalPath{} } func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext, installDir android.OutputPath) { // Collect NOTICE files from all dependencies. seenModules := make(map[android.Module]bool) noticePathSet := make(map[android.Path]bool) Loading Loading @@ -391,7 +389,7 @@ func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext, installDir an } if len(noticePathSet) == 0 { return android.OptionalPath{} return } var noticePaths []android.Path for path := range noticePathSet { Loading @@ -400,9 +398,8 @@ func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext, installDir an sort.Slice(noticePaths, func(i, j int) bool { return noticePaths[i].String() < noticePaths[j].String() }) noticeFile := android.BuildNoticeOutput(ctx, installDir, a.installApkName+".apk", noticePaths) return android.OptionalPathForPath(noticeFile) a.noticeOutputs = android.BuildNoticeOutput(ctx, installDir, a.installApkName+".apk", noticePaths) } // Reads and prepends a main cert from the default cert dir if it hasn't been set already, i.e. it Loading Loading @@ -455,7 +452,10 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { installDir = android.PathForModuleInstall(ctx, "app", a.installApkName) } a.aapt.noticeFile = a.noticeBuildActions(ctx, installDir) a.noticeBuildActions(ctx, installDir) if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") { a.aapt.noticeFile = a.noticeOutputs.HtmlGzOutput } // Process all building blocks, from AAPT to certificates. a.aaptBuildActions(ctx) Loading java/app_test.go +10 −6 Original line number Diff line number Diff line Loading @@ -1479,16 +1479,20 @@ func TestEmbedNotice(t *testing.T) { // bar has NOTICE files to process, but embed_notices is not set. bar := ctx.ModuleForTests("bar", "android_common") mergeNotices = bar.MaybeRule("mergeNoticesRule") if mergeNotices.Rule != nil { t.Errorf("mergeNotices shouldn't have run for bar") res = bar.Output("package-res.apk") aapt2Flags = res.Args["flags"] e = "-A " + buildDir + "/.intermediates/bar/android_common/NOTICE" if strings.Contains(aapt2Flags, e) { t.Errorf("bar shouldn't have the asset dir flag for NOTICE: %q", e) } // baz's embed_notice is true, but it doesn't have any NOTICE files. baz := ctx.ModuleForTests("baz", "android_common") mergeNotices = baz.MaybeRule("mergeNoticesRule") if mergeNotices.Rule != nil { t.Errorf("mergeNotices shouldn't have run for baz") res = baz.Output("package-res.apk") aapt2Flags = res.Args["flags"] e = "-A " + buildDir + "/.intermediates/baz/android_common/NOTICE" if strings.Contains(aapt2Flags, e) { t.Errorf("baz shouldn't have the asset dir flag for NOTICE: %q", e) } } Loading Loading
android/notices.go +29 −14 Original line number Diff line number Diff line Loading @@ -27,6 +27,13 @@ func init() { pctx.HostBinToolVariable("minigzip", "minigzip") } type NoticeOutputs struct { Merged OptionalPath TxtOutput OptionalPath HtmlOutput OptionalPath HtmlGzOutput OptionalPath } var ( mergeNoticesRule = pctx.AndroidStaticRule("mergeNoticesRule", blueprint.RuleParams{ Command: `${merge_notices} --output $out $in`, Loading @@ -35,13 +42,13 @@ var ( }) generateNoticeRule = pctx.AndroidStaticRule("generateNoticeRule", blueprint.RuleParams{ Command: `rm -rf $tmpDir $$(dirname $out) && ` + `mkdir -p $tmpDir $$(dirname $out) && ` + `${generate_notice} --text-output $tmpDir/NOTICE.txt --html-output $tmpDir/NOTICE.html -t "$title" -s $inputDir && ` + `${minigzip} -c $tmpDir/NOTICE.html > $out`, Command: `rm -rf $$(dirname $txtOut) $$(dirname htmlOut) $$(dirname $out) && ` + `mkdir -p $$(dirname $txtOut) $$(dirname htmlOut) $$(dirname $out) && ` + `${generate_notice} --text-output $txtOut --html-output $htmlOut -t "$title" -s $inputDir && ` + `${minigzip} -c $htmlOut > $out`, CommandDeps: []string{"${generate_notice}", "${minigzip}"}, Description: "produce notice file $out", }, "tmpDir", "title", "inputDir") }, "txtOut", "htmlOut", "title", "inputDir") ) func MergeNotices(ctx ModuleContext, mergedNotice WritablePath, noticePaths []Path) { Loading @@ -54,7 +61,7 @@ func MergeNotices(ctx ModuleContext, mergedNotice WritablePath, noticePaths []Pa } func BuildNoticeOutput(ctx ModuleContext, installPath OutputPath, installFilename string, noticePaths []Path) ModuleOutPath { noticePaths []Path) NoticeOutputs { // Merge all NOTICE files into one. // TODO(jungjw): We should just produce a well-formatted NOTICE.html file in a single pass. // Loading @@ -68,20 +75,28 @@ func BuildNoticeOutput(ctx ModuleContext, installPath OutputPath, installFilenam MergeNotices(ctx, mergedNotice, noticePaths) // Transform the merged NOTICE file into a gzipped HTML file. noticeOutput := PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz") tmpDir := PathForModuleOut(ctx, "NOTICE_tmp") txtOuptut := PathForModuleOut(ctx, "NOTICE_txt", "NOTICE.txt") htmlOutput := PathForModuleOut(ctx, "NOTICE_html", "NOTICE.html") htmlGzOutput := PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz") title := "Notices for " + ctx.ModuleName() ctx.Build(pctx, BuildParams{ Rule: generateNoticeRule, Description: "generate notice output", Input: mergedNotice, Output: noticeOutput, Output: htmlGzOutput, ImplicitOutputs: WritablePaths{txtOuptut, htmlOutput}, Args: map[string]string{ "tmpDir": tmpDir.String(), "txtOut": txtOuptut.String(), "htmlOut": htmlOutput.String(), "title": title, "inputDir": PathForModuleOut(ctx, "NOTICE_FILES/src").String(), }, }) return noticeOutput return NoticeOutputs{ Merged: OptionalPathForPath(mergedNotice), TxtOutput: OptionalPathForPath(txtOuptut), HtmlOutput: OptionalPathForPath(htmlOutput), HtmlGzOutput: OptionalPathForPath(htmlGzOutput), } }
apex/apex.go +1 −2 Original line number Diff line number Diff line Loading @@ -905,8 +905,7 @@ func (a *apexBundle) buildNoticeFile(ctx android.ModuleContext, apexFileName str return android.OptionalPath{} } return android.OptionalPathForPath( android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles))) return android.BuildNoticeOutput(ctx, a.installDir, apexFileName, android.FirstUniquePaths(noticeFiles)).HtmlGzOutput } func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, apexType apexPackaging) { Loading
java/androidmk.go +12 −0 Original line number Diff line number Diff line Loading @@ -327,6 +327,18 @@ func (app *AndroidApp) AndroidMk() android.AndroidMkData { install := "$(LOCAL_MODULE_PATH)/" + strings.TrimSuffix(app.installApkName, ".apk") + split.suffix + ".apk" fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED +=", split.path.String()+":"+install) } if app.noticeOutputs.Merged.Valid() { fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", app.installApkName, app.noticeOutputs.Merged.String(), app.installApkName+"_NOTICE") } if app.noticeOutputs.TxtOutput.Valid() { fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", app.installApkName, app.noticeOutputs.TxtOutput.String(), app.installApkName+"_NOTICE.txt") } if app.noticeOutputs.HtmlOutput.Valid() { fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", app.installApkName, app.noticeOutputs.HtmlOutput.String(), app.installApkName+"_NOTICE.html") } }, }, } Loading
java/app.go +9 −9 Original line number Diff line number Diff line Loading @@ -141,6 +141,8 @@ type AndroidApp struct { installApkName string additionalAaptFlags []string noticeOutputs android.NoticeOutputs } func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths { Loading Loading @@ -357,11 +359,7 @@ func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext return jniJarFile } func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext, installDir android.OutputPath) android.OptionalPath { if !Bool(a.appProperties.Embed_notices) && !ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") { return android.OptionalPath{} } func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext, installDir android.OutputPath) { // Collect NOTICE files from all dependencies. seenModules := make(map[android.Module]bool) noticePathSet := make(map[android.Path]bool) Loading Loading @@ -391,7 +389,7 @@ func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext, installDir an } if len(noticePathSet) == 0 { return android.OptionalPath{} return } var noticePaths []android.Path for path := range noticePathSet { Loading @@ -400,9 +398,8 @@ func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext, installDir an sort.Slice(noticePaths, func(i, j int) bool { return noticePaths[i].String() < noticePaths[j].String() }) noticeFile := android.BuildNoticeOutput(ctx, installDir, a.installApkName+".apk", noticePaths) return android.OptionalPathForPath(noticeFile) a.noticeOutputs = android.BuildNoticeOutput(ctx, installDir, a.installApkName+".apk", noticePaths) } // Reads and prepends a main cert from the default cert dir if it hasn't been set already, i.e. it Loading Loading @@ -455,7 +452,10 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { installDir = android.PathForModuleInstall(ctx, "app", a.installApkName) } a.aapt.noticeFile = a.noticeBuildActions(ctx, installDir) a.noticeBuildActions(ctx, installDir) if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") { a.aapt.noticeFile = a.noticeOutputs.HtmlGzOutput } // Process all building blocks, from AAPT to certificates. a.aaptBuildActions(ctx) Loading
java/app_test.go +10 −6 Original line number Diff line number Diff line Loading @@ -1479,16 +1479,20 @@ func TestEmbedNotice(t *testing.T) { // bar has NOTICE files to process, but embed_notices is not set. bar := ctx.ModuleForTests("bar", "android_common") mergeNotices = bar.MaybeRule("mergeNoticesRule") if mergeNotices.Rule != nil { t.Errorf("mergeNotices shouldn't have run for bar") res = bar.Output("package-res.apk") aapt2Flags = res.Args["flags"] e = "-A " + buildDir + "/.intermediates/bar/android_common/NOTICE" if strings.Contains(aapt2Flags, e) { t.Errorf("bar shouldn't have the asset dir flag for NOTICE: %q", e) } // baz's embed_notice is true, but it doesn't have any NOTICE files. baz := ctx.ModuleForTests("baz", "android_common") mergeNotices = baz.MaybeRule("mergeNoticesRule") if mergeNotices.Rule != nil { t.Errorf("mergeNotices shouldn't have run for baz") res = baz.Output("package-res.apk") aapt2Flags = res.Args["flags"] e = "-A " + buildDir + "/.intermediates/baz/android_common/NOTICE" if strings.Contains(aapt2Flags, e) { t.Errorf("baz shouldn't have the asset dir flag for NOTICE: %q", e) } } Loading