Merge "Copy cc_object output files to a name that matches the module"
This commit is contained in:
32
cc/object.go
32
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]
|
||||
|
||||
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
|
||||
|
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user