Merge changes If90975c8,I2a873fc6

* changes:
  Use ctx.ModuleBuild for darwin ar
  Run gofmt
This commit is contained in:
Colin Cross
2017-05-10 17:28:20 +00:00
committed by Gerrit Code Review
4 changed files with 59 additions and 35 deletions

View File

@@ -721,3 +721,25 @@ func validatePath(ctx PathContext, paths ...string) string {
} }
return validateSafePath(ctx, paths...) 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 // very small command line length limit, so we have to split the ar into multiple
// steps, each appending to the previous one. // steps, each appending to the previous one.
func transformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths, 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" arFlags := "cqs"
@@ -493,7 +493,7 @@ func transformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.P
ctx.ModuleBuild(pctx, android.ModuleBuildParams{ ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Rule: darwinAppendAr, Rule: darwinAppendAr,
Output: outputPath, Output: outputFile,
Input: dummy, Input: dummy,
Args: map[string]string{ Args: map[string]string{
"arFlags": "d", "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 // 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 { if err != nil {
ctx.ModuleErrorf("%s", err.Error()) ctx.ModuleErrorf("%s", err.Error())
} }
outputFile := outputPath.String() var in, out android.WritablePath
var in, out string
for i, l := range objFilesLists { for i, l := range objFilesLists {
in = out in = out
out = outputFile out = outputFile
if i != len(objFilesLists)-1 { if i != len(objFilesLists)-1 {
out += "." + strconv.Itoa(i) out = android.PathForModuleOut(ctx, outputFile.Base()+strconv.Itoa(i))
} }
if in == "" { build := android.ModuleBuildParams{
ctx.Build(pctx, blueprint.BuildParams{
Rule: darwinAr, Rule: darwinAr,
Outputs: []string{out}, Output: out,
Inputs: l, Inputs: l,
Implicits: deps.Strings(), Implicits: deps,
Args: map[string]string{ Args: map[string]string{
"arFlags": arFlags, "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) 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 var i int
start := 0 start := 0
bytes := 0 bytes := 0
for i = range list { for i = range list {
l := len(list[i]) l := len(list[i].String())
if l > limit { if l > limit {
return nil, fmt.Errorf("list element greater than size limit (%d)", limit) return nil, fmt.Errorf("list element greater than size limit (%d)", limit)
} }

View File

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

View File

@@ -217,12 +217,12 @@ func writeAllIncludeDirectories(includes []string, f *os.File, isSystem bool) {
f.WriteString(")\n\n") f.WriteString(")\n\n")
// Also add all headers to source files. // Also add all headers to source files.
f.WriteString("file (GLOB_RECURSE TMP_HEADERS\n"); f.WriteString("file (GLOB_RECURSE TMP_HEADERS\n")
for _, include := range includes { for _, include := range includes {
f.WriteString(fmt.Sprintf(" \"%s/**/*.h\"\n", buildCMakePath(include))) f.WriteString(fmt.Sprintf(" \"%s/**/*.h\"\n", buildCMakePath(include)))
} }
f.WriteString(")\n") f.WriteString(")\n")
f.WriteString("list (APPEND SOURCE_FILES ${TMP_HEADERS})\n\n"); f.WriteString("list (APPEND SOURCE_FILES ${TMP_HEADERS})\n\n")
} }
func writeAllFlags(flags []string, f *os.File, tag string) { func writeAllFlags(flags []string, f *os.File, tag string) {