Fix strip_prefix flags to strip install paths.

Bug: 235331488

Test: m droid dist

Change-Id: I3cd2af5d90e46a4c983728bc9b2d941d6ffda229
This commit is contained in:
Bob Badour 2022-06-08 15:59:35 -07:00
parent 0d364eead5
commit c6ec9fb849
5 changed files with 45 additions and 13 deletions

View file

@ -67,7 +67,12 @@ func (s *genNoticeBuildRules) GenerateBuildActions(ctx SingletonContext) {
if ctx.Failed() {
return
}
out(ctx, gm.output, ctx.ModuleName(gm), proptools.StringDefault(gm.properties.ArtifactName, defaultName), "", modules...)
out(ctx, gm.output, ctx.ModuleName(gm),
proptools.StringDefault(gm.properties.ArtifactName, defaultName),
[]string{
ctx.Config().OutDir() + "/",
ctx.Config().SoongOutDir() + "/",
}, modules...)
})
}

View file

@ -47,7 +47,9 @@ func modulesLicenseMetadata(ctx BuilderContext, modules ...Module) Paths {
}
// buildNoticeOutputFromLicenseMetadata writes out a notice file.
func buildNoticeOutputFromLicenseMetadata(ctx BuilderContext, tool, ruleName string, outputFile WritablePath, libraryName, stripPrefix string, modules ...Module) {
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)
if len(modules) == 0 {
@ -64,8 +66,8 @@ func buildNoticeOutputFromLicenseMetadata(ctx BuilderContext, tool, ruleName str
BuiltTool(tool).
FlagWithOutput("-o ", outputFile).
FlagWithDepFile("-d ", depsFile)
if stripPrefix != "" {
cmd = cmd.FlagWithArg("--strip_prefix ", stripPrefix)
if len(stripPrefix) > 0 {
cmd = cmd.FlagForEachArg("--strip_prefix ", stripPrefix)
}
outputs := modulesOutputDirs(ctx, modules...)
if len(outputs) > 0 {
@ -81,20 +83,29 @@ func buildNoticeOutputFromLicenseMetadata(ctx BuilderContext, tool, ruleName str
// 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, stripPrefix string, modules ...Module) {
buildNoticeOutputFromLicenseMetadata(ctx, "textnotice", "text_notice_"+ruleName, outputFile, libraryName, stripPrefix, modules...)
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, stripPrefix string, modules ...Module) {
buildNoticeOutputFromLicenseMetadata(ctx, "htmlnotice", "html_notice_"+ruleName, outputFile, libraryName, stripPrefix, modules...)
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, stripPrefix string, modules ...Module) {
buildNoticeOutputFromLicenseMetadata(ctx, "xmlnotice", "xml_notice_"+ruleName, outputFile, libraryName, stripPrefix, modules...)
func BuildNoticeXmlOutputFromLicenseMetadata(
ctx BuilderContext, outputFile WritablePath, ruleName, libraryName string,
stripPrefix []string, modules ...Module) {
buildNoticeOutputFromLicenseMetadata(ctx, "xmlnotice", "xml_notice_"+ruleName,
outputFile, libraryName, stripPrefix, modules...)
}

View file

@ -124,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, "", "", outputZipFile.String())
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"))

View file

@ -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, "", "", unsignedOutputFile.String())
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").

View file

@ -656,7 +656,13 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") {
noticeFile := android.PathForModuleOut(ctx, "NOTICE.html.gz")
android.BuildNoticeHtmlOutputFromLicenseMetadata(ctx, noticeFile, "", "", a.outputFile.String())
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").