From b8ecdfe0398c4d43178b433bea2d6c9d0c4fd509 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 3 May 2016 15:10:29 -0700 Subject: [PATCH] Fix stripping on Darwin The strip tool is different on Darwin, use a separate darwinStrip rule instead of calling strip.sh for host builds on Darwin. Change-Id: I6d421cba0dcea04367d5bc638a03f64c81e2ead0 --- cc/builder.go | 32 +++++++++++++++++++++++--------- cc/cc.go | 12 ++++++++---- cc/x86_darwin_host.go | 5 +++++ 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/cc/builder.go b/cc/builder.go index 10c85087d..b97f29b8a 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -79,19 +79,26 @@ var ( darwinAr = pctx.StaticRule("darwinAr", blueprint.RuleParams{ - Command: "rm -f ${out} && $arCmd $arFlags $out $in", - CommandDeps: []string{"$arCmd"}, + Command: "rm -f ${out} && ${macArPath} $arFlags $out $in", + CommandDeps: []string{"${macArPath}"}, Description: "ar $out", }, - "arCmd", "arFlags") + "arFlags") darwinAppendAr = pctx.StaticRule("darwinAppendAr", blueprint.RuleParams{ - Command: "cp -f ${inAr} ${out}.tmp && $arCmd $arFlags ${out}.tmp $in && mv ${out}.tmp ${out}", - CommandDeps: []string{"$arCmd"}, + Command: "cp -f ${inAr} ${out}.tmp && ${macArPath} $arFlags ${out}.tmp $in && mv ${out}.tmp ${out}", + CommandDeps: []string{"${macArPath}"}, Description: "ar $out", }, - "arCmd", "arFlags", "inAr") + "arFlags", "inAr") + + darwinStrip = pctx.StaticRule("darwinStrip", + blueprint.RuleParams{ + Command: "${macStripPath} -u -r -o $out $in", + CommandDeps: []string{"${macStripPath}"}, + Description: "strip $out", + }) prefixSymbols = pctx.StaticRule("prefixSymbols", blueprint.RuleParams{ @@ -252,7 +259,6 @@ func TransformObjToStaticLib(ctx common.AndroidModuleContext, objFiles common.Pa func TransformDarwinObjToStaticLib(ctx common.AndroidModuleContext, objFiles common.Paths, flags builderFlags, outputPath common.ModuleOutPath) { - arCmd := "${macArPath}" arFlags := "cqs" // ARG_MAX on darwin is 262144, use half that to be safe @@ -278,7 +284,6 @@ func TransformDarwinObjToStaticLib(ctx common.AndroidModuleContext, objFiles com Inputs: l, Args: map[string]string{ "arFlags": arFlags, - "arCmd": arCmd, }, }) } else { @@ -289,7 +294,6 @@ func TransformDarwinObjToStaticLib(ctx common.AndroidModuleContext, objFiles com Implicits: []string{in}, Args: map[string]string{ "arFlags": arFlags, - "arCmd": arCmd, "inAr": in, }, }) @@ -439,6 +443,16 @@ func TransformStrip(ctx common.AndroidModuleContext, inputFile common.Path, }) } +func TransformDarwinStrip(ctx common.AndroidModuleContext, inputFile common.Path, + outputFile common.WritablePath) { + + ctx.ModuleBuild(pctx, common.ModuleBuildParams{ + Rule: darwinStrip, + Output: outputFile, + Input: inputFile, + }) +} + func CopyGccLib(ctx common.AndroidModuleContext, libName string, flags builderFlags, outputFile common.WritablePath) { diff --git a/cc/cc.go b/cc/cc.go index 052df2b8f..1a8ba3b12 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1979,10 +1979,14 @@ func (stripper *stripper) needsStrip(ctx ModuleContext) bool { func (stripper *stripper) strip(ctx ModuleContext, in, out common.ModuleOutPath, flags builderFlags) { - flags.stripKeepSymbols = stripper.StripProperties.Strip.Keep_symbols - // TODO(ccross): don't add gnu debuglink for user builds - flags.stripAddGnuDebuglink = true - TransformStrip(ctx, in, out, flags) + if ctx.Darwin() { + TransformDarwinStrip(ctx, in, out) + } else { + flags.stripKeepSymbols = stripper.StripProperties.Strip.Keep_symbols + // TODO(ccross): don't add gnu debuglink for user builds + flags.stripAddGnuDebuglink = true + TransformStrip(ctx, in, out, flags) + } } func testPerSrcMutator(mctx common.AndroidBottomUpMutatorContext) { diff --git a/cc/x86_darwin_host.go b/cc/x86_darwin_host.go index 559a9a518..52add5cbb 100644 --- a/cc/x86_darwin_host.go +++ b/cc/x86_darwin_host.go @@ -105,6 +105,11 @@ func init() { return strings.TrimSpace(string(bytes)), err }) + pctx.VariableFunc("macStripPath", func(config interface{}) (string, error) { + bytes, err := exec.Command("xcrun", "--find", "strip").Output() + return strings.TrimSpace(string(bytes)), err + }) + pctx.StaticVariable("darwinGccVersion", darwinGccVersion) pctx.SourcePathVariable("darwinGccRoot", "prebuilts/gcc/${HostPrebuiltTag}/host/i686-apple-darwin-${darwinGccVersion}")