Merge "Add a new property trim_extension for gensrcs" into main am: 512b52f759
am: c2a1c063b4
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/3048196 Change-Id: I9e102cd990273efe3836b9c3df6d044716df2996 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -277,6 +277,7 @@ type WritablePath interface {
|
||||
|
||||
type genPathProvider interface {
|
||||
genPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleGenPath
|
||||
genPathWithExtAndTrimExt(ctx ModuleOutPathContext, subdir, ext string, trimExt string) ModuleGenPath
|
||||
}
|
||||
type objPathProvider interface {
|
||||
objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath
|
||||
@@ -295,6 +296,16 @@ func GenPathWithExt(ctx ModuleOutPathContext, subdir string, p Path, ext string)
|
||||
return PathForModuleGen(ctx)
|
||||
}
|
||||
|
||||
// GenPathWithExtAndTrimExt derives a new file path in ctx's generated sources directory
|
||||
// from the current path, but with the new extension and trim the suffix.
|
||||
func GenPathWithExtAndTrimExt(ctx ModuleOutPathContext, subdir string, p Path, ext string, trimExt string) ModuleGenPath {
|
||||
if path, ok := p.(genPathProvider); ok {
|
||||
return path.genPathWithExtAndTrimExt(ctx, subdir, ext, trimExt)
|
||||
}
|
||||
ReportPathErrorf(ctx, "Tried to create generated file from unsupported path: %s(%s)", reflect.TypeOf(p).Name(), p)
|
||||
return PathForModuleGen(ctx)
|
||||
}
|
||||
|
||||
// ObjPathWithExt derives a new file path in ctx's object directory from the
|
||||
// current path, but with the new extension.
|
||||
func ObjPathWithExt(ctx ModuleOutPathContext, subdir string, p Path, ext string) ModuleObjPath {
|
||||
@@ -1507,6 +1518,17 @@ func (p SourcePath) genPathWithExt(ctx ModuleOutPathContext, subdir, ext string)
|
||||
return PathForModuleGen(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
||||
}
|
||||
|
||||
func (p SourcePath) genPathWithExtAndTrimExt(ctx ModuleOutPathContext, subdir, ext string, trimExt string) ModuleGenPath {
|
||||
// If Trim_extension being set, force append Output_extension without replace original extension.
|
||||
if trimExt != "" {
|
||||
if ext != "" {
|
||||
return PathForModuleGen(ctx, subdir, strings.TrimSuffix(p.path, trimExt)+"."+ext)
|
||||
}
|
||||
return PathForModuleGen(ctx, subdir, strings.TrimSuffix(p.path, trimExt))
|
||||
}
|
||||
return PathForModuleGen(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
||||
}
|
||||
|
||||
func (p SourcePath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath {
|
||||
return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
||||
}
|
||||
@@ -1594,6 +1616,17 @@ func (p ModuleGenPath) genPathWithExt(ctx ModuleOutPathContext, subdir, ext stri
|
||||
return PathForModuleGen(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
||||
}
|
||||
|
||||
func (p ModuleGenPath) genPathWithExtAndTrimExt(ctx ModuleOutPathContext, subdir, ext string, trimExt string) ModuleGenPath {
|
||||
// If Trim_extension being set, force append Output_extension without replace original extension.
|
||||
if trimExt != "" {
|
||||
if ext != "" {
|
||||
return PathForModuleGen(ctx, subdir, strings.TrimSuffix(p.path, trimExt)+"."+ext)
|
||||
}
|
||||
return PathForModuleGen(ctx, subdir, strings.TrimSuffix(p.path, trimExt))
|
||||
}
|
||||
return PathForModuleGen(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
||||
}
|
||||
|
||||
func (p ModuleGenPath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath {
|
||||
return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
||||
}
|
||||
|
Reference in New Issue
Block a user