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