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
diff --git a/cc/object.go b/cc/object.go
index 65a11e0..1a96b72 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -16,6 +16,7 @@
import (
"fmt"
+ "strings"
"android/soong/android"
"android/soong/bazel"
@@ -254,22 +255,31 @@
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