Fix strip_prefix flags to strip install paths.
Bug: 235331488 Test: m droid dist Change-Id: I3cd2af5d90e46a4c983728bc9b2d941d6ffda229 Merged-in: I3cd2af5d90e46a4c983728bc9b2d941d6ffda229
This commit is contained in:
@@ -15,31 +15,97 @@
|
||||
package android
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// BuildNoticeTextOutputFromLicenseMetadata writes out a notice text file based on the module's
|
||||
// generated license metadata file.
|
||||
func BuildNoticeTextOutputFromLicenseMetadata(ctx ModuleContext, outputFile WritablePath) {
|
||||
depsFile := outputFile.ReplaceExtension(ctx, strings.TrimPrefix(outputFile.Ext()+".d", "."))
|
||||
rule := NewRuleBuilder(pctx, ctx)
|
||||
rule.Command().
|
||||
BuiltTool("textnotice").
|
||||
FlagWithOutput("-o ", outputFile).
|
||||
FlagWithDepFile("-d ", depsFile).
|
||||
Input(ctx.Module().base().licenseMetadataFile)
|
||||
rule.Build("text_notice", "container notice file")
|
||||
func modulesOutputDirs(ctx BuilderContext, modules ...Module) []string {
|
||||
dirs := make([]string, 0, len(modules))
|
||||
for _, module := range modules {
|
||||
paths, err := outputFilesForModule(ctx, module, "")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, path := range paths {
|
||||
if path != nil {
|
||||
dirs = append(dirs, filepath.Dir(path.String()))
|
||||
}
|
||||
}
|
||||
}
|
||||
return SortedUniqueStrings(dirs)
|
||||
}
|
||||
|
||||
// BuildNoticeHtmlOutputFromLicenseMetadata writes out a notice text file based on the module's
|
||||
// generated license metadata file.
|
||||
func BuildNoticeHtmlOutputFromLicenseMetadata(ctx ModuleContext, outputFile WritablePath) {
|
||||
func modulesLicenseMetadata(ctx BuilderContext, modules ...Module) Paths {
|
||||
result := make(Paths, 0, len(modules))
|
||||
for _, module := range modules {
|
||||
if mf := module.base().licenseMetadataFile; mf != nil {
|
||||
result = append(result, mf)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// buildNoticeOutputFromLicenseMetadata writes out a notice file.
|
||||
func buildNoticeOutputFromLicenseMetadata(
|
||||
ctx BuilderContext, tool, ruleName string, outputFile WritablePath,
|
||||
libraryName string, stripPrefix []string, modules ...Module) {
|
||||
depsFile := outputFile.ReplaceExtension(ctx, strings.TrimPrefix(outputFile.Ext()+".d", "."))
|
||||
rule := NewRuleBuilder(pctx, ctx)
|
||||
rule.Command().
|
||||
BuiltTool("htmlnotice").
|
||||
if len(modules) == 0 {
|
||||
if mctx, ok := ctx.(ModuleContext); ok {
|
||||
modules = []Module{mctx.Module()}
|
||||
} else {
|
||||
panic(fmt.Errorf("%s %q needs a module to generate the notice for", ruleName, libraryName))
|
||||
}
|
||||
}
|
||||
if libraryName == "" {
|
||||
libraryName = modules[0].Name()
|
||||
}
|
||||
cmd := rule.Command().
|
||||
BuiltTool(tool).
|
||||
FlagWithOutput("-o ", outputFile).
|
||||
FlagWithDepFile("-d ", depsFile).
|
||||
Input(ctx.Module().base().licenseMetadataFile)
|
||||
rule.Build("html_notice", "container notice file")
|
||||
FlagWithDepFile("-d ", depsFile)
|
||||
if len(stripPrefix) > 0 {
|
||||
cmd = cmd.FlagForEachArg("--strip_prefix ", stripPrefix)
|
||||
}
|
||||
outputs := modulesOutputDirs(ctx, modules...)
|
||||
if len(outputs) > 0 {
|
||||
cmd = cmd.FlagForEachArg("--strip_prefix ", outputs)
|
||||
}
|
||||
if libraryName != "" {
|
||||
cmd = cmd.FlagWithArg("--product ", libraryName)
|
||||
}
|
||||
cmd = cmd.Inputs(modulesLicenseMetadata(ctx, modules...))
|
||||
rule.Build(ruleName, "container notice file")
|
||||
}
|
||||
|
||||
// BuildNoticeTextOutputFromLicenseMetadata writes out a notice text file based
|
||||
// on the license metadata files for the input `modules` defaulting to the
|
||||
// current context module if none given.
|
||||
func BuildNoticeTextOutputFromLicenseMetadata(
|
||||
ctx BuilderContext, outputFile WritablePath, ruleName, libraryName string,
|
||||
stripPrefix []string, modules ...Module) {
|
||||
buildNoticeOutputFromLicenseMetadata(ctx, "textnotice", "text_notice_"+ruleName,
|
||||
outputFile, libraryName, stripPrefix, modules...)
|
||||
}
|
||||
|
||||
// BuildNoticeHtmlOutputFromLicenseMetadata writes out a notice text file based
|
||||
// on the license metadata files for the input `modules` defaulting to the
|
||||
// current context module if none given.
|
||||
func BuildNoticeHtmlOutputFromLicenseMetadata(
|
||||
ctx BuilderContext, outputFile WritablePath, ruleName, libraryName string,
|
||||
stripPrefix []string, modules ...Module) {
|
||||
buildNoticeOutputFromLicenseMetadata(ctx, "htmlnotice", "html_notice_"+ruleName,
|
||||
outputFile, libraryName, stripPrefix, modules...)
|
||||
}
|
||||
|
||||
// BuildNoticeXmlOutputFromLicenseMetadata writes out a notice text file based
|
||||
// on the license metadata files for the input `modules` defaulting to the
|
||||
// current context module if none given.
|
||||
func BuildNoticeXmlOutputFromLicenseMetadata(
|
||||
ctx BuilderContext, outputFile WritablePath, ruleName, libraryName string,
|
||||
stripPrefix []string, modules ...Module) {
|
||||
buildNoticeOutputFromLicenseMetadata(ctx, "xmlnotice", "xml_notice_"+ruleName,
|
||||
outputFile, libraryName, stripPrefix, modules...)
|
||||
}
|
||||
|
@@ -107,6 +107,7 @@ func (s *sdkRepoHost) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
|
||||
func (s *sdkRepoHost) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
dir := android.PathForModuleOut(ctx, "zip")
|
||||
outputZipFile := dir.Join(ctx, "output.zip")
|
||||
builder := android.NewRuleBuilder(pctx, ctx).
|
||||
Sbox(dir, android.PathForModuleOut(ctx, "out.sbox.textproto")).
|
||||
SandboxInputs()
|
||||
@@ -123,7 +124,12 @@ func (s *sdkRepoHost) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
s.CopySpecsToDir(ctx, builder, packageSpecs, dir)
|
||||
|
||||
noticeFile := android.PathForModuleOut(ctx, "NOTICES.txt")
|
||||
android.BuildNoticeTextOutputFromLicenseMetadata(ctx, noticeFile)
|
||||
android.BuildNoticeTextOutputFromLicenseMetadata(
|
||||
ctx, noticeFile, "", "",
|
||||
[]string{
|
||||
android.PathForModuleInstall(ctx, "sdk-repo").String() + "/",
|
||||
outputZipFile.String(),
|
||||
})
|
||||
builder.Command().Text("cp").
|
||||
Input(noticeFile).
|
||||
Text(filepath.Join(dir.String(), "NOTICE.txt"))
|
||||
@@ -209,7 +215,6 @@ func (s *sdkRepoHost) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
}
|
||||
|
||||
// Zip up our temporary directory as the sdk-repo
|
||||
outputZipFile := dir.Join(ctx, "output.zip")
|
||||
builder.Command().
|
||||
BuiltTool("soong_zip").
|
||||
FlagWithOutput("-o ", outputZipFile).
|
||||
|
@@ -618,7 +618,12 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
|
||||
|
||||
// Create a NOTICE file, and embed it as an asset file in the APEX.
|
||||
a.htmlGzNotice = android.PathForModuleOut(ctx, "NOTICE.html.gz")
|
||||
android.BuildNoticeHtmlOutputFromLicenseMetadata(ctx, a.htmlGzNotice)
|
||||
android.BuildNoticeHtmlOutputFromLicenseMetadata(
|
||||
ctx, a.htmlGzNotice, "", "",
|
||||
[]string{
|
||||
android.PathForModuleInstall(ctx).String() + "/",
|
||||
android.PathForModuleInPartitionInstall(ctx, "apex").String() + "/",
|
||||
})
|
||||
noticeAssetPath := android.PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz")
|
||||
builder := android.NewRuleBuilder(pctx, ctx)
|
||||
builder.Command().Text("cp").
|
||||
|
30
java/app.go
30
java/app.go
@@ -587,18 +587,6 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
}
|
||||
a.onDeviceDir = android.InstallPathToOnDevicePath(ctx, a.installDir)
|
||||
|
||||
if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") {
|
||||
noticeFile := android.PathForModuleOut(ctx, "NOTICE.html.gz")
|
||||
android.BuildNoticeHtmlOutputFromLicenseMetadata(ctx, noticeFile)
|
||||
noticeAssetPath := android.PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz")
|
||||
builder := android.NewRuleBuilder(pctx, ctx)
|
||||
builder.Command().Text("cp").
|
||||
Input(noticeFile).
|
||||
Output(noticeAssetPath)
|
||||
builder.Build("notice_dir", "Building notice dir")
|
||||
a.aapt.noticeFile = android.OptionalPathForPath(noticeAssetPath)
|
||||
}
|
||||
|
||||
a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
|
||||
|
||||
// Process all building blocks, from AAPT to certificates.
|
||||
@@ -675,6 +663,24 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile)
|
||||
}
|
||||
|
||||
if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") {
|
||||
noticeFile := android.PathForModuleOut(ctx, "NOTICE.html.gz")
|
||||
android.BuildNoticeHtmlOutputFromLicenseMetadata(
|
||||
ctx, noticeFile, "", "",
|
||||
[]string{
|
||||
a.installDir.String() + "/",
|
||||
android.PathForModuleInstall(ctx).String() + "/",
|
||||
a.outputFile.String(),
|
||||
})
|
||||
noticeAssetPath := android.PathForModuleOut(ctx, "NOTICE", "NOTICE.html.gz")
|
||||
builder := android.NewRuleBuilder(pctx, ctx)
|
||||
builder.Command().Text("cp").
|
||||
Input(noticeFile).
|
||||
Output(noticeAssetPath)
|
||||
builder.Build("notice_dir", "Building notice dir")
|
||||
a.aapt.noticeFile = android.OptionalPathForPath(noticeAssetPath)
|
||||
}
|
||||
|
||||
for _, split := range a.aapt.splits {
|
||||
// Sign the split APKs
|
||||
packageFile := android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk")
|
||||
|
Reference in New Issue
Block a user