Copy cc_object output files to a name that matches the module

cc_object output files match the name of the module if there are any
postprocessing steps like partial linking or prefixing symbols.  If
there are no postprocessing steps the output file matches the name
of the source file with the extension changed to ".o".  Always copy
the object to an output file that matches the module name.

This relands I086bb0d14a3c02093515f55395aa7a11473f8040 with a fix
for modules that already have a .o suffix in the module name.

Bug: 242601708
Test: TestCcObjectOutputFile
Change-Id: I603d06f1c36f72913aec3e22bbd0857166e142b5
This commit is contained in:
Colin Cross
2022-09-09 15:11:16 -07:00
parent 9f6796ab17
commit fb44cd2e8e
2 changed files with 84 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ package cc
import (
"fmt"
"strings"
"android/soong/android"
"android/soong/bazel"
@@ -254,22 +255,31 @@ func (object *objectLinker) link(ctx ModuleContext,
var outputFile android.Path
builderFlags := flagsToBuilderFlags(flags)
outputName := ctx.ModuleName()
if !strings.HasSuffix(outputName, objectExtension) {
outputName += objectExtension
}
if len(objs.objFiles) == 1 && String(object.Properties.Linker_script) == "" {
outputFile = objs.objFiles[0]
if String(object.Properties.Prefix_symbols) != "" {
output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
transformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), outputFile,
builderFlags, output)
outputFile = output
}
} else {
output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
output := android.PathForModuleOut(ctx, outputName)
outputFile = output
if String(object.Properties.Prefix_symbols) != "" {
input := android.PathForModuleOut(ctx, "unprefixed", ctx.ModuleName()+objectExtension)
transformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), objs.objFiles[0],
builderFlags, output)
} else {
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: objs.objFiles[0],
Output: output,
})
}
} else {
output := android.PathForModuleOut(ctx, outputName)
outputFile = output
if String(object.Properties.Prefix_symbols) != "" {
input := android.PathForModuleOut(ctx, "unprefixed", outputName)
transformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), input,
builderFlags, output)
output = input