summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2022-09-09 15:11:16 -0700
committer Colin Cross <ccross@android.com> 2022-09-16 10:34:09 -0700
commitfb44cd2e8e4d7b99f816ce18b1f9bdad8f0274c6 (patch)
tree572162b2890e21596b606e91a6219f2e62af5aa2
parent9f6796ab174a41e53b332eadf560310515bab9a6 (diff)
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
-rw-r--r--cc/object.go22
-rw-r--r--cc/object_test.go63
2 files changed, 79 insertions, 6 deletions
diff --git a/cc/object.go b/cc/object.go
index 65a11e005..1a96b7205 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -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]
+ output := android.PathForModuleOut(ctx, outputName)
+ outputFile = output
if String(object.Properties.Prefix_symbols) != "" {
- output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
- transformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), outputFile,
+ transformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), objs.objFiles[0],
builderFlags, output)
- outputFile = output
+ } else {
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Cp,
+ Input: objs.objFiles[0],
+ Output: 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)
+ input := android.PathForModuleOut(ctx, "unprefixed", outputName)
transformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), input,
builderFlags, output)
output = input
diff --git a/cc/object_test.go b/cc/object_test.go
index 259a892ab..5359a357a 100644
--- a/cc/object_test.go
+++ b/cc/object_test.go
@@ -15,6 +15,7 @@
package cc
import (
+ "fmt"
"testing"
"android/soong/android"
@@ -107,3 +108,65 @@ cc_object {
expectedOutputFiles := []string{"outputbase/execroot/__main__/bazel_out.o"}
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
}
+
+func TestCcObjectOutputFile(t *testing.T) {
+ testcases := []struct {
+ name string
+ moduleName string
+ bp string
+ }{
+ {
+ name: "normal",
+ moduleName: "foo",
+ bp: `
+ srcs: ["bar.c"],
+ `,
+ },
+ {
+ name: "suffix",
+ moduleName: "foo.o",
+ bp: `
+ srcs: ["bar.c"],
+ `,
+ },
+ {
+ name: "keep symbols",
+ moduleName: "foo",
+ bp: `
+ srcs: ["bar.c"],
+ prefix_symbols: "foo_",
+ `,
+ },
+ {
+ name: "partial linking",
+ moduleName: "foo",
+ bp: `
+ srcs: ["bar.c", "baz.c"],
+ `,
+ },
+ {
+ name: "partial linking and prefix symbols",
+ moduleName: "foo",
+ bp: `
+ srcs: ["bar.c", "baz.c"],
+ prefix_symbols: "foo_",
+ `,
+ },
+ }
+
+ for _, testcase := range testcases {
+ bp := fmt.Sprintf(`
+ cc_object {
+ name: "%s",
+ %s
+ }
+ `, testcase.moduleName, testcase.bp)
+ t.Run(testcase.name, func(t *testing.T) {
+ ctx := PrepareForIntegrationTestWithCc.RunTestWithBp(t, bp)
+ android.AssertPathRelativeToTopEquals(t, "expected output file foo.o",
+ fmt.Sprintf("out/soong/.intermediates/%s/android_arm64_armv8-a/foo.o", testcase.moduleName),
+ ctx.ModuleForTests(testcase.moduleName, "android_arm64_armv8-a").Output("foo.o").Output)
+ })
+ }
+
+}