Use ctx.ModuleBuild for darwin ar

Test: builds
Change-Id: If90975c8545158012bc6201acadd136363c21260
This commit is contained in:
Colin Cross 2017-05-09 13:34:34 -07:00
parent 51d4ab2d5e
commit 5b52959c99
3 changed files with 56 additions and 32 deletions

View file

@ -721,3 +721,25 @@ func validatePath(ctx PathContext, paths ...string) string {
}
return validateSafePath(ctx, paths...)
}
type testPath struct {
basePath
}
func (p testPath) String() string {
return p.path
}
func PathForTesting(paths ...string) Path {
p := validateSafePath(nil, paths...)
return testPath{basePath{path: p, rel: p}}
}
func PathsForTesting(strs []string) Paths {
p := make(Paths, len(strs))
for i, s := range strs {
p[i] = PathForTesting(s)
}
return p
}

View file

@ -468,7 +468,7 @@ func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
// very small command line length limit, so we have to split the ar into multiple
// steps, each appending to the previous one.
func transformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
flags builderFlags, outputPath android.ModuleOutPath, deps android.Paths) {
flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths) {
arFlags := "cqs"
@ -493,7 +493,7 @@ func transformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.P
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Rule: darwinAppendAr,
Output: outputPath,
Output: outputFile,
Input: dummy,
Args: map[string]string{
"arFlags": "d",
@ -505,42 +505,33 @@ func transformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.P
}
// ARG_MAX on darwin is 262144, use half that to be safe
objFilesLists, err := splitListForSize(objFiles.Strings(), 131072)
objFilesLists, err := splitListForSize(objFiles, 131072)
if err != nil {
ctx.ModuleErrorf("%s", err.Error())
}
outputFile := outputPath.String()
var in, out string
var in, out android.WritablePath
for i, l := range objFilesLists {
in = out
out = outputFile
if i != len(objFilesLists)-1 {
out += "." + strconv.Itoa(i)
out = android.PathForModuleOut(ctx, outputFile.Base()+strconv.Itoa(i))
}
if in == "" {
ctx.Build(pctx, blueprint.BuildParams{
build := android.ModuleBuildParams{
Rule: darwinAr,
Outputs: []string{out},
Output: out,
Inputs: l,
Implicits: deps.Strings(),
Implicits: deps,
Args: map[string]string{
"arFlags": arFlags,
},
})
} else {
ctx.Build(pctx, blueprint.BuildParams{
Rule: darwinAppendAr,
Outputs: []string{out},
Inputs: l,
Args: map[string]string{
"arFlags": arFlags,
"inAr": in,
},
})
}
if i != 0 {
build.Rule = darwinAppendAr
build.Args["inAr"] = in.String()
}
ctx.ModuleBuild(pctx, build)
}
}
@ -779,13 +770,13 @@ func gccCmd(toolchain config.Toolchain, cmd string) string {
return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd)
}
func splitListForSize(list []string, limit int) (lists [][]string, err error) {
func splitListForSize(list android.Paths, limit int) (lists []android.Paths, err error) {
var i int
start := 0
bytes := 0
for i = range list {
l := len(list[i])
l := len(list[i].String())
if l > limit {
return nil, fmt.Errorf("list element greater than size limit (%d)", limit)
}

View file

@ -1,6 +1,7 @@
package cc
import (
"android/soong/android"
"reflect"
"testing"
)
@ -142,13 +143,23 @@ var splitListForSizeTestCases = []struct {
func TestSplitListForSize(t *testing.T) {
for _, testCase := range splitListForSizeTestCases {
out, _ := splitListForSize(testCase.in, testCase.size)
if !reflect.DeepEqual(out, testCase.out) {
out, _ := splitListForSize(android.PathsForTesting(testCase.in), testCase.size)
var outStrings [][]string
if len(out) > 0 {
outStrings = make([][]string, len(out))
for i, o := range out {
outStrings[i] = o.Strings()
}
}
if !reflect.DeepEqual(outStrings, testCase.out) {
t.Errorf("incorrect output:")
t.Errorf(" input: %#v", testCase.in)
t.Errorf(" size: %d", testCase.size)
t.Errorf(" expected: %#v", testCase.out)
t.Errorf(" got: %#v", out)
t.Errorf(" got: %#v", outStrings)
}
}
}