2015-01-31 09:27:36 +08:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
// This file generates the final rules for compiling all C/C++. All properties related to
|
|
|
|
// compiling should have been translated into builderFlags or another argument to the Transform*
|
|
|
|
// functions.
|
|
|
|
|
|
|
|
import (
|
2015-05-01 07:36:18 +08:00
|
|
|
"fmt"
|
2016-07-30 04:44:28 +08:00
|
|
|
"path/filepath"
|
2015-05-01 07:36:18 +08:00
|
|
|
"runtime"
|
|
|
|
"strconv"
|
2015-01-31 09:27:36 +08:00
|
|
|
"strings"
|
2015-03-27 05:43:45 +08:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2016-07-30 04:44:28 +08:00
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc/config"
|
2015-01-31 09:27:36 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-04-29 09:17:56 +08:00
|
|
|
objectExtension = ".o"
|
2015-01-31 09:27:36 +08:00
|
|
|
staticLibraryExtension = ".a"
|
|
|
|
)
|
|
|
|
|
2017-11-02 02:12:15 +08:00
|
|
|
var (
|
|
|
|
abiCheckAllowFlags = []string{
|
|
|
|
"-allow-unreferenced-changes",
|
|
|
|
"-allow-unreferenced-elf-symbol-changes",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
var (
|
2016-05-19 06:37:25 +08:00
|
|
|
pctx = android.NewPackageContext("android/soong/cc")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
cc = pctx.AndroidGomaStaticRule("cc",
|
2015-01-31 09:27:36 +08:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
2016-08-27 03:55:49 +08:00
|
|
|
Command: "$relPwd ${config.CcWrapper}$ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$ccCmd"},
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
2015-11-18 07:19:46 +08:00
|
|
|
"ccCmd", "cFlags")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
ld = pctx.AndroidStaticRule("ld",
|
2015-01-31 09:27:36 +08:00
|
|
|
blueprint.RuleParams{
|
2016-07-22 04:16:49 +08:00
|
|
|
Command: "$ldCmd ${crtBegin} @${out}.rsp " +
|
2015-04-23 04:07:53 +08:00
|
|
|
"${libFlags} ${crtEnd} -o ${out} ${ldFlags}",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$ldCmd"},
|
2015-03-31 08:47:53 +08:00
|
|
|
Rspfile: "${out}.rsp",
|
|
|
|
RspfileContent: "${in}",
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
2016-07-22 04:16:49 +08:00
|
|
|
"ldCmd", "crtBegin", "libFlags", "crtEnd", "ldFlags")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
partialLd = pctx.AndroidStaticRule("partialLd",
|
2015-01-31 09:27:36 +08:00
|
|
|
blueprint.RuleParams{
|
2018-01-11 06:30:44 +08:00
|
|
|
// Without -no-pie, clang 7.0 adds -pie to link Android files,
|
|
|
|
// but -r and -pie cannot be used together.
|
|
|
|
Command: "$ldCmd -nostdlib -no-pie -Wl,-r ${in} -o ${out} ${ldFlags}",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$ldCmd"},
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
2015-11-24 06:01:42 +08:00
|
|
|
"ldCmd", "ldFlags")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
ar = pctx.AndroidStaticRule("ar",
|
2015-01-31 09:27:36 +08:00
|
|
|
blueprint.RuleParams{
|
2015-03-31 08:47:53 +08:00
|
|
|
Command: "rm -f ${out} && $arCmd $arFlags $out @${out}.rsp",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$arCmd"},
|
2015-03-31 08:47:53 +08:00
|
|
|
Rspfile: "${out}.rsp",
|
|
|
|
RspfileContent: "${in}",
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
|
|
|
"arCmd", "arFlags")
|
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
darwinAr = pctx.AndroidStaticRule("darwinAr",
|
2015-05-01 07:36:18 +08:00
|
|
|
blueprint.RuleParams{
|
2016-07-30 04:44:28 +08:00
|
|
|
Command: "rm -f ${out} && ${config.MacArPath} $arFlags $out $in",
|
|
|
|
CommandDeps: []string{"${config.MacArPath}"},
|
2015-05-01 07:36:18 +08:00
|
|
|
},
|
2016-05-04 06:10:29 +08:00
|
|
|
"arFlags")
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
darwinAppendAr = pctx.AndroidStaticRule("darwinAppendAr",
|
2015-05-01 07:36:18 +08:00
|
|
|
blueprint.RuleParams{
|
2016-07-30 04:44:28 +08:00
|
|
|
Command: "cp -f ${inAr} ${out}.tmp && ${config.MacArPath} $arFlags ${out}.tmp $in && mv ${out}.tmp ${out}",
|
|
|
|
CommandDeps: []string{"${config.MacArPath}", "${inAr}"},
|
2015-05-01 07:36:18 +08:00
|
|
|
},
|
2016-05-04 06:10:29 +08:00
|
|
|
"arFlags", "inAr")
|
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
darwinStrip = pctx.AndroidStaticRule("darwinStrip",
|
2016-05-04 06:10:29 +08:00
|
|
|
blueprint.RuleParams{
|
2016-08-02 06:42:38 +08:00
|
|
|
Command: "${config.MacStripPath} -u -r -o $out $in",
|
|
|
|
CommandDeps: []string{"${config.MacStripPath}"},
|
2016-05-04 06:10:29 +08:00
|
|
|
})
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
prefixSymbols = pctx.AndroidStaticRule("prefixSymbols",
|
2015-03-27 05:44:11 +08:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$objcopyCmd --prefix-symbols=${prefix} ${in} ${out}",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$objcopyCmd"},
|
2015-03-27 05:44:11 +08:00
|
|
|
},
|
|
|
|
"objcopyCmd", "prefix")
|
|
|
|
|
2017-03-28 05:27:58 +08:00
|
|
|
_ = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh")
|
2018-03-10 02:47:52 +08:00
|
|
|
_ = pctx.SourcePathVariable("xzCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/xz")
|
2016-04-29 05:50:03 +08:00
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
strip = pctx.AndroidStaticRule("strip",
|
2016-04-29 05:50:03 +08:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
2018-03-10 02:47:52 +08:00
|
|
|
Command: "CROSS_COMPILE=$crossCompile XZ=$xzCmd $stripPath ${args} -i ${in} -o ${out} -d ${out}.d",
|
|
|
|
CommandDeps: []string{"$stripPath", "$xzCmd"},
|
2016-04-29 05:50:03 +08:00
|
|
|
},
|
|
|
|
"args", "crossCompile")
|
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
emptyFile = pctx.AndroidStaticRule("emptyFile",
|
2016-05-14 05:05:09 +08:00
|
|
|
blueprint.RuleParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Command: "rm -f $out && touch $out",
|
2016-05-14 05:05:09 +08:00
|
|
|
})
|
|
|
|
|
2017-03-28 05:27:58 +08:00
|
|
|
_ = pctx.SourcePathVariable("copyGccLibPath", "build/soong/scripts/copygcclib.sh")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
copyGccLib = pctx.AndroidStaticRule("copyGccLib",
|
2015-01-31 09:27:36 +08:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
|
|
|
Command: "$copyGccLibPath $out $ccCmd $cFlags -print-file-name=${libName}",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$copyGccLibPath", "$ccCmd"},
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
|
|
|
"ccCmd", "cFlags", "libName")
|
2016-10-01 08:10:16 +08:00
|
|
|
|
2017-03-28 05:27:58 +08:00
|
|
|
_ = pctx.SourcePathVariable("tocPath", "build/soong/scripts/toc.sh")
|
2016-10-01 08:10:16 +08:00
|
|
|
|
|
|
|
toc = pctx.AndroidStaticRule("toc",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
|
|
|
Command: "CROSS_COMPILE=$crossCompile $tocPath -i ${in} -o ${out} -d ${out}.d",
|
|
|
|
CommandDeps: []string{"$tocPath"},
|
|
|
|
Restat: true,
|
|
|
|
},
|
|
|
|
"crossCompile")
|
2016-09-27 06:45:04 +08:00
|
|
|
|
|
|
|
clangTidy = pctx.AndroidStaticRule("clangTidy",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "rm -f $out && ${config.ClangBin}/clang-tidy $tidyFlags $in -- $cFlags && touch $out",
|
|
|
|
CommandDeps: []string{"${config.ClangBin}/clang-tidy"},
|
|
|
|
},
|
|
|
|
"cFlags", "tidyFlags")
|
2016-12-03 09:13:24 +08:00
|
|
|
|
2017-03-28 05:27:58 +08:00
|
|
|
_ = pctx.SourcePathVariable("yasmCmd", "prebuilts/misc/${config.HostPrebuiltTag}/yasm/yasm")
|
2016-12-03 09:13:24 +08:00
|
|
|
|
|
|
|
yasm = pctx.AndroidStaticRule("yasm",
|
|
|
|
blueprint.RuleParams{
|
2017-08-23 11:53:45 +08:00
|
|
|
Command: "$yasmCmd $asFlags -o $out $in && $yasmCmd $asFlags -M $in >$out.d",
|
2016-12-03 09:13:24 +08:00
|
|
|
CommandDeps: []string{"$yasmCmd"},
|
2017-08-23 11:53:45 +08:00
|
|
|
Depfile: "$out.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
2016-12-03 09:13:24 +08:00
|
|
|
},
|
|
|
|
"asFlags")
|
2017-02-09 05:45:53 +08:00
|
|
|
|
2017-09-09 16:15:26 +08:00
|
|
|
windres = pctx.AndroidStaticRule("windres",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$windresCmd $flags -I$$(dirname $in) -i $in -o $out",
|
|
|
|
CommandDeps: []string{"$windresCmd"},
|
|
|
|
},
|
|
|
|
"windresCmd", "flags")
|
|
|
|
|
2018-02-21 04:36:51 +08:00
|
|
|
_ = pctx.SourcePathVariable("sAbiDumper", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-dumper")
|
2017-02-09 05:45:53 +08:00
|
|
|
|
2017-04-20 21:53:59 +08:00
|
|
|
// -w has been added since header-abi-dumper does not need to produce any sort of diagnostic information.
|
2017-02-09 05:45:53 +08:00
|
|
|
sAbiDump = pctx.AndroidStaticRule("sAbiDump",
|
|
|
|
blueprint.RuleParams{
|
2017-04-20 21:53:59 +08:00
|
|
|
Command: "rm -f $out && $sAbiDumper -o ${out} $in $exportDirs -- $cFlags -w -isystem ${config.RSIncludePath}",
|
2017-02-09 05:45:53 +08:00
|
|
|
CommandDeps: []string{"$sAbiDumper"},
|
|
|
|
},
|
|
|
|
"cFlags", "exportDirs")
|
|
|
|
|
2018-02-21 04:36:51 +08:00
|
|
|
_ = pctx.SourcePathVariable("sAbiLinker", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-linker")
|
2017-02-09 05:45:53 +08:00
|
|
|
|
|
|
|
sAbiLink = pctx.AndroidStaticRule("sAbiLink",
|
|
|
|
blueprint.RuleParams{
|
2018-01-18 03:11:42 +08:00
|
|
|
Command: "$sAbiLinker -o ${out} $symbolFilter -arch $arch $exportedHeaderFlags @${out}.rsp ",
|
2017-02-09 05:45:53 +08:00
|
|
|
CommandDeps: []string{"$sAbiLinker"},
|
|
|
|
Rspfile: "${out}.rsp",
|
|
|
|
RspfileContent: "${in}",
|
|
|
|
},
|
2018-01-18 03:11:42 +08:00
|
|
|
"symbolFilter", "arch", "exportedHeaderFlags")
|
2017-02-09 05:45:53 +08:00
|
|
|
|
2018-02-21 04:36:51 +08:00
|
|
|
_ = pctx.SourcePathVariable("sAbiDiffer", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-diff")
|
2017-04-20 21:53:59 +08:00
|
|
|
|
2017-11-28 06:52:21 +08:00
|
|
|
sAbiDiff = pctx.AndroidRuleFunc("sAbiDiff",
|
2018-03-13 04:24:09 +08:00
|
|
|
func(ctx android.PackageRuleContext) blueprint.RuleParams {
|
2017-11-28 06:52:21 +08:00
|
|
|
|
|
|
|
commandStr := "($sAbiDiffer $allowFlags -lib $libName -arch $arch -check-all-apis -o ${out} -new $in -old $referenceDump)"
|
2018-03-11 08:25:53 +08:00
|
|
|
distAbiDiffDir := android.PathForDist(ctx, "abidiffs")
|
2018-04-17 11:19:51 +08:00
|
|
|
commandStr += "|| (echo ' ---- Please update abi references by running $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py -l ${libName} ----'"
|
2018-03-11 08:25:53 +08:00
|
|
|
if distAbiDiffDir.Valid() {
|
2018-04-18 01:41:11 +08:00
|
|
|
commandStr += " && (mkdir -p " + distAbiDiffDir.String() + " && cp ${out} " + distAbiDiffDir.String() + ")"
|
2017-11-28 06:52:21 +08:00
|
|
|
}
|
2018-02-02 09:23:09 +08:00
|
|
|
commandStr += " && exit 1)"
|
2017-11-28 06:52:21 +08:00
|
|
|
return blueprint.RuleParams{
|
|
|
|
Command: commandStr,
|
|
|
|
CommandDeps: []string{"$sAbiDiffer"},
|
2018-03-13 04:24:09 +08:00
|
|
|
}
|
2017-02-09 05:45:53 +08:00
|
|
|
},
|
2017-11-02 02:12:15 +08:00
|
|
|
"allowFlags", "referenceDump", "libName", "arch")
|
2017-04-20 21:53:59 +08:00
|
|
|
|
|
|
|
unzipRefSAbiDump = pctx.AndroidStaticRule("unzipRefSAbiDump",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "gunzip -c $in > $out",
|
|
|
|
})
|
2015-01-31 09:27:36 +08:00
|
|
|
)
|
|
|
|
|
2015-11-18 07:19:46 +08:00
|
|
|
func init() {
|
|
|
|
// We run gcc/clang with PWD=/proc/self/cwd to remove $TOP from the
|
|
|
|
// debug output. That way two builds in two different directories will
|
|
|
|
// create the same output.
|
|
|
|
if runtime.GOOS != "darwin" {
|
|
|
|
pctx.StaticVariable("relPwd", "PWD=/proc/self/cwd")
|
|
|
|
} else {
|
|
|
|
// Darwin doesn't have /proc
|
|
|
|
pctx.StaticVariable("relPwd", "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
type builderFlags struct {
|
2017-11-19 10:23:14 +08:00
|
|
|
globalFlags string
|
|
|
|
arFlags string
|
|
|
|
asFlags string
|
|
|
|
cFlags string
|
|
|
|
toolingCFlags string // A separate set of Cflags for clang LibTooling tools
|
|
|
|
conlyFlags string
|
|
|
|
cppFlags string
|
|
|
|
ldFlags string
|
|
|
|
libFlags string
|
|
|
|
yaccFlags string
|
|
|
|
protoFlags string
|
|
|
|
protoOutParams string
|
|
|
|
tidyFlags string
|
|
|
|
sAbiFlags string
|
|
|
|
yasmFlags string
|
|
|
|
aidlFlags string
|
|
|
|
rsFlags string
|
|
|
|
toolchain config.Toolchain
|
|
|
|
clang bool
|
|
|
|
tidy bool
|
|
|
|
coverage bool
|
|
|
|
sAbiDump bool
|
2018-02-15 05:58:34 +08:00
|
|
|
protoRoot bool
|
2016-04-29 05:50:03 +08:00
|
|
|
|
2017-03-31 06:03:04 +08:00
|
|
|
systemIncludeFlags string
|
|
|
|
|
2016-12-02 06:45:23 +08:00
|
|
|
groupStaticLibs bool
|
2018-02-09 10:32:11 +08:00
|
|
|
arGoldPlugin bool
|
2016-12-02 06:45:23 +08:00
|
|
|
|
2016-04-29 05:50:03 +08:00
|
|
|
stripKeepSymbols bool
|
|
|
|
stripKeepMiniDebugInfo bool
|
|
|
|
stripAddGnuDebuglink bool
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
type Objects struct {
|
2017-02-10 08:16:31 +08:00
|
|
|
objFiles android.Paths
|
|
|
|
tidyFiles android.Paths
|
|
|
|
coverageFiles android.Paths
|
2017-02-09 05:45:53 +08:00
|
|
|
sAbiDumpFiles android.Paths
|
2016-09-27 08:33:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a Objects) Copy() Objects {
|
|
|
|
return Objects{
|
2017-02-10 08:16:31 +08:00
|
|
|
objFiles: append(android.Paths{}, a.objFiles...),
|
|
|
|
tidyFiles: append(android.Paths{}, a.tidyFiles...),
|
|
|
|
coverageFiles: append(android.Paths{}, a.coverageFiles...),
|
2017-02-09 05:45:53 +08:00
|
|
|
sAbiDumpFiles: append(android.Paths{}, a.sAbiDumpFiles...),
|
2016-09-27 08:33:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a Objects) Append(b Objects) Objects {
|
|
|
|
return Objects{
|
2017-02-10 08:16:31 +08:00
|
|
|
objFiles: append(a.objFiles, b.objFiles...),
|
|
|
|
tidyFiles: append(a.tidyFiles, b.tidyFiles...),
|
|
|
|
coverageFiles: append(a.coverageFiles, b.coverageFiles...),
|
2017-02-09 05:45:53 +08:00
|
|
|
sAbiDumpFiles: append(a.sAbiDumpFiles, b.sAbiDumpFiles...),
|
2016-09-27 08:33:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
// Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files
|
2016-05-19 06:37:25 +08:00
|
|
|
func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles android.Paths,
|
2018-01-24 02:49:04 +08:00
|
|
|
flags builderFlags, pathDeps android.Paths, cFlagsDeps android.Paths) Objects {
|
2015-04-08 07:50:10 +08:00
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
objFiles := make(android.Paths, len(srcFiles))
|
2016-09-27 06:45:04 +08:00
|
|
|
var tidyFiles android.Paths
|
|
|
|
if flags.tidy && flags.clang {
|
|
|
|
tidyFiles = make(android.Paths, 0, len(srcFiles))
|
|
|
|
}
|
2017-02-10 08:16:31 +08:00
|
|
|
var coverageFiles android.Paths
|
|
|
|
if flags.coverage {
|
|
|
|
coverageFiles = make(android.Paths, 0, len(srcFiles))
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2017-06-16 05:45:18 +08:00
|
|
|
commonFlags := strings.Join([]string{
|
2017-03-31 06:03:04 +08:00
|
|
|
flags.globalFlags,
|
|
|
|
flags.systemIncludeFlags,
|
2017-06-16 05:45:18 +08:00
|
|
|
}, " ")
|
|
|
|
|
|
|
|
toolingCflags := strings.Join([]string{
|
|
|
|
commonFlags,
|
|
|
|
flags.toolingCFlags,
|
|
|
|
flags.conlyFlags,
|
|
|
|
}, " ")
|
|
|
|
|
|
|
|
cflags := strings.Join([]string{
|
|
|
|
commonFlags,
|
2017-03-31 06:03:04 +08:00
|
|
|
flags.cFlags,
|
|
|
|
flags.conlyFlags,
|
|
|
|
}, " ")
|
|
|
|
|
2017-06-16 05:45:18 +08:00
|
|
|
toolingCppflags := strings.Join([]string{
|
|
|
|
commonFlags,
|
|
|
|
flags.toolingCFlags,
|
|
|
|
flags.cppFlags,
|
|
|
|
}, " ")
|
|
|
|
|
2017-03-31 06:03:04 +08:00
|
|
|
cppflags := strings.Join([]string{
|
2017-06-16 05:45:18 +08:00
|
|
|
commonFlags,
|
2017-03-31 06:03:04 +08:00
|
|
|
flags.cFlags,
|
|
|
|
flags.cppFlags,
|
|
|
|
}, " ")
|
|
|
|
|
|
|
|
asflags := strings.Join([]string{
|
2017-06-16 05:45:18 +08:00
|
|
|
commonFlags,
|
2017-03-31 06:03:04 +08:00
|
|
|
flags.asFlags,
|
|
|
|
}, " ")
|
2017-06-16 05:45:18 +08:00
|
|
|
|
2017-02-09 05:45:53 +08:00
|
|
|
var sAbiDumpFiles android.Paths
|
|
|
|
if flags.sAbiDump && flags.clang {
|
|
|
|
sAbiDumpFiles = make(android.Paths, 0, len(srcFiles))
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-03-04 09:21:04 +08:00
|
|
|
if flags.clang {
|
2016-07-30 04:44:28 +08:00
|
|
|
cflags += " ${config.NoOverrideClangGlobalCflags}"
|
2017-06-16 05:45:18 +08:00
|
|
|
toolingCflags += " ${config.NoOverrideClangGlobalCflags}"
|
2016-07-30 04:44:28 +08:00
|
|
|
cppflags += " ${config.NoOverrideClangGlobalCflags}"
|
2017-06-16 05:45:18 +08:00
|
|
|
toolingCppflags += " ${config.NoOverrideClangGlobalCflags}"
|
2016-03-04 09:21:04 +08:00
|
|
|
} else {
|
2016-07-30 04:44:28 +08:00
|
|
|
cflags += " ${config.NoOverrideGlobalCflags}"
|
|
|
|
cppflags += " ${config.NoOverrideGlobalCflags}"
|
2016-03-04 09:21:04 +08:00
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
for i, srcFile := range srcFiles {
|
2016-11-03 11:43:13 +08:00
|
|
|
objFile := android.ObjPathWithExt(ctx, subdir, srcFile, "o")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
objFiles[i] = objFile
|
|
|
|
|
2017-09-09 16:15:26 +08:00
|
|
|
switch srcFile.Ext() {
|
|
|
|
case ".asm":
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: yasm,
|
|
|
|
Description: "yasm " + srcFile.Rel(),
|
|
|
|
Output: objFile,
|
|
|
|
Input: srcFile,
|
2018-01-24 02:49:04 +08:00
|
|
|
Implicits: cFlagsDeps,
|
|
|
|
OrderOnly: pathDeps,
|
2016-12-03 09:13:24 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"asFlags": flags.yasmFlags,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
continue
|
2017-09-09 16:15:26 +08:00
|
|
|
case ".rc":
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-09-09 16:15:26 +08:00
|
|
|
Rule: windres,
|
|
|
|
Description: "windres " + srcFile.Rel(),
|
|
|
|
Output: objFile,
|
|
|
|
Input: srcFile,
|
2018-01-24 02:49:04 +08:00
|
|
|
Implicits: cFlagsDeps,
|
|
|
|
OrderOnly: pathDeps,
|
2017-09-09 16:15:26 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"windresCmd": gccCmd(flags.toolchain, "windres"),
|
|
|
|
"flags": flags.toolchain.WindresFlags(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
continue
|
2016-12-03 09:13:24 +08:00
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
var moduleCflags string
|
2017-06-16 05:45:18 +08:00
|
|
|
var moduleToolingCflags string
|
2015-01-31 09:27:36 +08:00
|
|
|
var ccCmd string
|
2016-09-27 06:45:04 +08:00
|
|
|
tidy := flags.tidy && flags.clang
|
2017-02-10 08:16:31 +08:00
|
|
|
coverage := flags.coverage
|
2017-02-09 05:45:53 +08:00
|
|
|
dump := flags.sAbiDump && flags.clang
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
switch srcFile.Ext() {
|
2015-01-31 09:27:36 +08:00
|
|
|
case ".S", ".s":
|
|
|
|
ccCmd = "gcc"
|
|
|
|
moduleCflags = asflags
|
2016-09-27 06:45:04 +08:00
|
|
|
tidy = false
|
2017-02-10 08:16:31 +08:00
|
|
|
coverage = false
|
2017-02-09 05:45:53 +08:00
|
|
|
dump = false
|
2015-01-31 09:27:36 +08:00
|
|
|
case ".c":
|
|
|
|
ccCmd = "gcc"
|
|
|
|
moduleCflags = cflags
|
2017-06-16 05:45:18 +08:00
|
|
|
moduleToolingCflags = toolingCflags
|
2016-12-02 07:31:22 +08:00
|
|
|
case ".cpp", ".cc", ".mm":
|
2015-01-31 09:27:36 +08:00
|
|
|
ccCmd = "g++"
|
|
|
|
moduleCflags = cppflags
|
2017-06-16 05:45:18 +08:00
|
|
|
moduleToolingCflags = toolingCppflags
|
2015-01-31 09:27:36 +08:00
|
|
|
default:
|
|
|
|
ctx.ModuleErrorf("File %s has unknown extension", srcFile)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if flags.clang {
|
|
|
|
switch ccCmd {
|
|
|
|
case "gcc":
|
|
|
|
ccCmd = "clang"
|
|
|
|
case "g++":
|
|
|
|
ccCmd = "clang++"
|
|
|
|
default:
|
|
|
|
panic("unrecoginzied ccCmd")
|
|
|
|
}
|
2017-05-10 04:45:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ccDesc := ccCmd
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2017-05-10 04:45:28 +08:00
|
|
|
if flags.clang {
|
2016-07-30 04:44:28 +08:00
|
|
|
ccCmd = "${config.ClangBin}/" + ccCmd
|
2015-01-31 09:27:36 +08:00
|
|
|
} else {
|
|
|
|
ccCmd = gccCmd(flags.toolchain, ccCmd)
|
|
|
|
}
|
|
|
|
|
2017-02-10 08:16:31 +08:00
|
|
|
var implicitOutputs android.WritablePaths
|
|
|
|
if coverage {
|
|
|
|
gcnoFile := android.ObjPathWithExt(ctx, subdir, srcFile, "gcno")
|
|
|
|
implicitOutputs = append(implicitOutputs, gcnoFile)
|
|
|
|
coverageFiles = append(coverageFiles, gcnoFile)
|
|
|
|
}
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-02-10 08:16:31 +08:00
|
|
|
Rule: cc,
|
2017-05-10 04:45:28 +08:00
|
|
|
Description: ccDesc + " " + srcFile.Rel(),
|
2017-02-10 08:16:31 +08:00
|
|
|
Output: objFile,
|
|
|
|
ImplicitOutputs: implicitOutputs,
|
|
|
|
Input: srcFile,
|
2018-01-24 02:49:04 +08:00
|
|
|
Implicits: cFlagsDeps,
|
|
|
|
OrderOnly: pathDeps,
|
2015-01-31 09:27:36 +08:00
|
|
|
Args: map[string]string{
|
2015-04-23 04:07:53 +08:00
|
|
|
"cFlags": moduleCflags,
|
|
|
|
"ccCmd": ccCmd,
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
|
|
|
})
|
2016-09-27 06:45:04 +08:00
|
|
|
|
|
|
|
if tidy {
|
2016-11-03 11:43:13 +08:00
|
|
|
tidyFile := android.ObjPathWithExt(ctx, subdir, srcFile, "tidy")
|
2016-09-27 06:45:04 +08:00
|
|
|
tidyFiles = append(tidyFiles, tidyFile)
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: clangTidy,
|
|
|
|
Description: "clang-tidy " + srcFile.Rel(),
|
|
|
|
Output: tidyFile,
|
|
|
|
Input: srcFile,
|
2016-09-27 06:45:04 +08:00
|
|
|
// We must depend on objFile, since clang-tidy doesn't
|
|
|
|
// support exporting dependencies.
|
|
|
|
Implicit: objFile,
|
|
|
|
Args: map[string]string{
|
2017-06-16 05:45:18 +08:00
|
|
|
"cFlags": moduleToolingCflags,
|
2016-09-27 06:45:04 +08:00
|
|
|
"tidyFlags": flags.tidyFlags,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-09 05:45:53 +08:00
|
|
|
if dump {
|
|
|
|
sAbiDumpFile := android.ObjPathWithExt(ctx, subdir, srcFile, "sdump")
|
|
|
|
sAbiDumpFiles = append(sAbiDumpFiles, sAbiDumpFile)
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: sAbiDump,
|
|
|
|
Description: "header-abi-dumper " + srcFile.Rel(),
|
|
|
|
Output: sAbiDumpFile,
|
|
|
|
Input: srcFile,
|
|
|
|
Implicit: objFile,
|
2017-02-09 05:45:53 +08:00
|
|
|
Args: map[string]string{
|
2017-06-16 05:45:18 +08:00
|
|
|
"cFlags": moduleToolingCflags,
|
2017-02-09 05:45:53 +08:00
|
|
|
"exportDirs": flags.sAbiFlags,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
return Objects{
|
2017-02-10 08:16:31 +08:00
|
|
|
objFiles: objFiles,
|
|
|
|
tidyFiles: tidyFiles,
|
|
|
|
coverageFiles: coverageFiles,
|
2017-02-09 05:45:53 +08:00
|
|
|
sAbiDumpFiles: sAbiDumpFiles,
|
2016-09-27 08:33:01 +08:00
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a rule for compiling multiple .o files to a static library (.a)
|
2016-05-19 06:37:25 +08:00
|
|
|
func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
|
2016-09-27 06:45:04 +08:00
|
|
|
flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths) {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2017-02-10 08:16:31 +08:00
|
|
|
if ctx.Darwin() {
|
|
|
|
transformDarwinObjToStaticLib(ctx, objFiles, flags, outputFile, deps)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-10 15:29:04 +08:00
|
|
|
arCmd := "${config.ClangBin}/llvm-ar"
|
|
|
|
arFlags := "crsD"
|
|
|
|
if !ctx.Darwin() {
|
|
|
|
arFlags += " -format=gnu"
|
|
|
|
}
|
2018-02-09 10:32:11 +08:00
|
|
|
if flags.arGoldPlugin {
|
|
|
|
arFlags += " --plugin ${config.LLVMGoldPlugin}"
|
|
|
|
}
|
2017-03-17 02:01:23 +08:00
|
|
|
if flags.arFlags != "" {
|
|
|
|
arFlags += " " + flags.arFlags
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: ar,
|
|
|
|
Description: "static link " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: objFiles,
|
|
|
|
Implicits: deps,
|
2015-01-31 09:27:36 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"arFlags": arFlags,
|
|
|
|
"arCmd": arCmd,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
// Generate a rule for compiling multiple .o files to a static library (.a) on
|
|
|
|
// darwin. The darwin ar tool doesn't support @file for list files, and has a
|
|
|
|
// very small command line length limit, so we have to split the ar into multiple
|
|
|
|
// steps, each appending to the previous one.
|
2017-02-10 08:16:31 +08:00
|
|
|
func transformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
|
2017-05-10 04:34:34 +08:00
|
|
|
flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths) {
|
2015-05-01 07:36:18 +08:00
|
|
|
|
|
|
|
arFlags := "cqs"
|
|
|
|
|
2016-05-14 05:05:09 +08:00
|
|
|
if len(objFiles) == 0 {
|
2016-05-19 06:37:25 +08:00
|
|
|
dummy := android.PathForModuleOut(ctx, "dummy"+objectExtension)
|
|
|
|
dummyAr := android.PathForModuleOut(ctx, "dummy"+staticLibraryExtension)
|
2016-05-14 05:05:09 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: emptyFile,
|
|
|
|
Description: "empty object file",
|
|
|
|
Output: dummy,
|
|
|
|
Implicits: deps,
|
2016-05-14 05:05:09 +08:00
|
|
|
})
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: darwinAr,
|
|
|
|
Description: "empty static archive",
|
|
|
|
Output: dummyAr,
|
|
|
|
Input: dummy,
|
2016-05-14 05:05:09 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"arFlags": arFlags,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: darwinAppendAr,
|
|
|
|
Description: "static link " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: dummy,
|
2016-05-14 05:05:09 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"arFlags": "d",
|
|
|
|
"inAr": dummyAr.String(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
// ARG_MAX on darwin is 262144, use half that to be safe
|
2017-05-10 04:34:34 +08:00
|
|
|
objFilesLists, err := splitListForSize(objFiles, 131072)
|
2015-05-01 07:36:18 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("%s", err.Error())
|
|
|
|
}
|
|
|
|
|
2017-05-10 04:34:34 +08:00
|
|
|
var in, out android.WritablePath
|
2015-05-01 07:36:18 +08:00
|
|
|
for i, l := range objFilesLists {
|
|
|
|
in = out
|
|
|
|
out = outputFile
|
|
|
|
if i != len(objFilesLists)-1 {
|
2017-05-10 04:34:34 +08:00
|
|
|
out = android.PathForModuleOut(ctx, outputFile.Base()+strconv.Itoa(i))
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
build := android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: darwinAr,
|
|
|
|
Description: "static link " + out.Base(),
|
|
|
|
Output: out,
|
|
|
|
Inputs: l,
|
|
|
|
Implicits: deps,
|
2017-05-10 04:34:34 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"arFlags": arFlags,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if i != 0 {
|
|
|
|
build.Rule = darwinAppendAr
|
|
|
|
build.Args["inAr"] = in.String()
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, build)
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
// Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries,
|
2017-09-28 08:01:44 +08:00
|
|
|
// and shared libraries, to a shared library (.so) or dynamic executable
|
2016-05-19 06:37:25 +08:00
|
|
|
func TransformObjToDynamicBinary(ctx android.ModuleContext,
|
|
|
|
objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps android.Paths,
|
|
|
|
crtBegin, crtEnd android.OptionalPath, groupLate bool, flags builderFlags, outputFile android.WritablePath) {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
var ldCmd string
|
|
|
|
if flags.clang {
|
2016-07-30 04:44:28 +08:00
|
|
|
ldCmd = "${config.ClangBin}/clang++"
|
2015-01-31 09:27:36 +08:00
|
|
|
} else {
|
|
|
|
ldCmd = gccCmd(flags.toolchain, "g++")
|
|
|
|
}
|
|
|
|
|
|
|
|
var libFlagsList []string
|
|
|
|
|
2016-01-07 06:41:07 +08:00
|
|
|
if len(flags.libFlags) > 0 {
|
|
|
|
libFlagsList = append(libFlagsList, flags.libFlags)
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
if len(wholeStaticLibs) > 0 {
|
2015-11-25 09:53:15 +08:00
|
|
|
if ctx.Host() && ctx.Darwin() {
|
2016-05-19 06:37:25 +08:00
|
|
|
libFlagsList = append(libFlagsList, android.JoinWithPrefix(wholeStaticLibs.Strings(), "-force_load "))
|
2015-05-01 07:36:18 +08:00
|
|
|
} else {
|
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--whole-archive ")
|
2015-09-24 06:26:20 +08:00
|
|
|
libFlagsList = append(libFlagsList, wholeStaticLibs.Strings()...)
|
2015-05-01 07:36:18 +08:00
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--no-whole-archive ")
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-12-06 10:47:39 +08:00
|
|
|
if flags.groupStaticLibs && !ctx.Darwin() && len(staticLibs) > 0 {
|
2016-12-02 06:45:23 +08:00
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--start-group")
|
|
|
|
}
|
2015-09-24 06:26:20 +08:00
|
|
|
libFlagsList = append(libFlagsList, staticLibs.Strings()...)
|
2016-12-06 10:47:39 +08:00
|
|
|
if flags.groupStaticLibs && !ctx.Darwin() && len(staticLibs) > 0 {
|
2016-12-02 06:45:23 +08:00
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--end-group")
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-07-19 06:54:54 +08:00
|
|
|
if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 {
|
2015-07-09 04:02:23 +08:00
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--start-group")
|
|
|
|
}
|
2015-09-24 06:26:20 +08:00
|
|
|
libFlagsList = append(libFlagsList, lateStaticLibs.Strings()...)
|
2016-07-19 06:54:54 +08:00
|
|
|
if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 {
|
2015-07-09 04:02:23 +08:00
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--end-group")
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
for _, lib := range sharedLibs {
|
2016-07-21 23:47:33 +08:00
|
|
|
libFlagsList = append(libFlagsList, lib.String())
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
deps = append(deps, staticLibs...)
|
2015-03-18 01:47:08 +08:00
|
|
|
deps = append(deps, lateStaticLibs...)
|
2015-01-31 09:27:36 +08:00
|
|
|
deps = append(deps, wholeStaticLibs...)
|
2015-09-24 06:26:20 +08:00
|
|
|
if crtBegin.Valid() {
|
|
|
|
deps = append(deps, crtBegin.Path(), crtEnd.Path())
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: ld,
|
|
|
|
Description: "link " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: objFiles,
|
|
|
|
Implicits: deps,
|
2015-01-31 09:27:36 +08:00
|
|
|
Args: map[string]string{
|
2016-07-22 04:16:49 +08:00
|
|
|
"ldCmd": ldCmd,
|
|
|
|
"crtBegin": crtBegin.String(),
|
|
|
|
"libFlags": strings.Join(libFlagsList, " "),
|
|
|
|
"ldFlags": flags.ldFlags,
|
|
|
|
"crtEnd": crtEnd.String(),
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-09 05:45:53 +08:00
|
|
|
// Generate a rule to combine .dump sAbi dump files from multiple source files
|
|
|
|
// into a single .ldump sAbi dump file
|
2017-06-27 03:52:58 +08:00
|
|
|
func TransformDumpToLinkedDump(ctx android.ModuleContext, sAbiDumps android.Paths, soFile android.Path,
|
2018-01-18 03:11:42 +08:00
|
|
|
baseName, exportedHeaderFlags string) android.OptionalPath {
|
2017-02-09 05:45:53 +08:00
|
|
|
outputFile := android.PathForModuleOut(ctx, baseName+".lsdump")
|
2018-02-24 08:43:23 +08:00
|
|
|
sabiLock.Lock()
|
|
|
|
lsdumpPaths = append(lsdumpPaths, outputFile.String())
|
|
|
|
sabiLock.Unlock()
|
2018-01-18 03:11:42 +08:00
|
|
|
symbolFilterStr := "-so " + soFile.String()
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: sAbiLink,
|
|
|
|
Description: "header-abi-linker " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: sAbiDumps,
|
2018-01-18 03:11:42 +08:00
|
|
|
Implicit: soFile,
|
2017-02-09 05:45:53 +08:00
|
|
|
Args: map[string]string{
|
2018-01-18 03:11:42 +08:00
|
|
|
"symbolFilter": symbolFilterStr,
|
|
|
|
"arch": ctx.Arch().ArchType.Name,
|
2017-02-09 05:45:53 +08:00
|
|
|
"exportedHeaderFlags": exportedHeaderFlags,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
return android.OptionalPathForPath(outputFile)
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:53:59 +08:00
|
|
|
func UnzipRefDump(ctx android.ModuleContext, zippedRefDump android.Path, baseName string) android.Path {
|
|
|
|
outputFile := android.PathForModuleOut(ctx, baseName+"_ref.lsdump")
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-04-20 21:53:59 +08:00
|
|
|
Rule: unzipRefSAbiDump,
|
|
|
|
Description: "gunzip" + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: zippedRefDump,
|
|
|
|
})
|
|
|
|
return outputFile
|
|
|
|
}
|
|
|
|
|
2017-02-09 05:45:53 +08:00
|
|
|
func SourceAbiDiff(ctx android.ModuleContext, inputDump android.Path, referenceDump android.Path,
|
Support VNDK extensions
This commit adds `extends: "name"` property and provides basic support
to VNDK extensions. This is the simplest example:
```
cc_library {
name: "libvndk",
vendor_available: true,
vndk {
enabled: true,
},
}
cc_library {
name: "libvndk_ext",
vendor: true,
vndk: {
enabled: true,
extends: "libvndk",
},
}
```
A vndk extension library must extend an existing vndk library which has
`vendor_available: true`. These two libraries must have the same
`support_system_process` property.
VNDK-ext libraries are installed to `/vendor/lib[64]/vndk` and
VNDK-SP-ext libraries are installed to `/vendor/lib[64]/vndk-sp` by
default.
If there is a matching abi-dumps in `prebuilts/abi-dumps`,
`header-abi-diff` will be invoked to check for ABI breakages.
Bug: 38340960
Test: lunch aosp_walleye-userdebug && make -j8 # runs unit tests
Test: lunch aosp_arm-userdebug && make -j8 # build a target w/o VNDK
Test: Create a lsdump for a vndk lib, add an exported API to vndk lib,
and build fails as expected.
Test: Create a lsdump for a vndk lib, create an vndk extension lib with
extra API, and build succeeds as expected.
Test: Create libutils_ext, add an extra function to libutils_ext, and
call it from a HIDL service.
Change-Id: Iba90e08848ee99814405457f047321e6b52b2df0
2017-10-31 18:04:35 +08:00
|
|
|
baseName, exportedHeaderFlags string, isVndkExt bool) android.OptionalPath {
|
|
|
|
|
2017-02-09 05:45:53 +08:00
|
|
|
outputFile := android.PathForModuleOut(ctx, baseName+".abidiff")
|
Support VNDK extensions
This commit adds `extends: "name"` property and provides basic support
to VNDK extensions. This is the simplest example:
```
cc_library {
name: "libvndk",
vendor_available: true,
vndk {
enabled: true,
},
}
cc_library {
name: "libvndk_ext",
vendor: true,
vndk: {
enabled: true,
extends: "libvndk",
},
}
```
A vndk extension library must extend an existing vndk library which has
`vendor_available: true`. These two libraries must have the same
`support_system_process` property.
VNDK-ext libraries are installed to `/vendor/lib[64]/vndk` and
VNDK-SP-ext libraries are installed to `/vendor/lib[64]/vndk-sp` by
default.
If there is a matching abi-dumps in `prebuilts/abi-dumps`,
`header-abi-diff` will be invoked to check for ABI breakages.
Bug: 38340960
Test: lunch aosp_walleye-userdebug && make -j8 # runs unit tests
Test: lunch aosp_arm-userdebug && make -j8 # build a target w/o VNDK
Test: Create a lsdump for a vndk lib, add an exported API to vndk lib,
and build fails as expected.
Test: Create a lsdump for a vndk lib, create an vndk extension lib with
extra API, and build succeeds as expected.
Test: Create libutils_ext, add an extra function to libutils_ext, and
call it from a HIDL service.
Change-Id: Iba90e08848ee99814405457f047321e6b52b2df0
2017-10-31 18:04:35 +08:00
|
|
|
|
2018-01-18 05:13:33 +08:00
|
|
|
localAbiCheckAllowFlags := append([]string(nil), abiCheckAllowFlags...)
|
|
|
|
if exportedHeaderFlags == "" {
|
|
|
|
localAbiCheckAllowFlags = append(localAbiCheckAllowFlags, "-advice-only")
|
|
|
|
}
|
Support VNDK extensions
This commit adds `extends: "name"` property and provides basic support
to VNDK extensions. This is the simplest example:
```
cc_library {
name: "libvndk",
vendor_available: true,
vndk {
enabled: true,
},
}
cc_library {
name: "libvndk_ext",
vendor: true,
vndk: {
enabled: true,
extends: "libvndk",
},
}
```
A vndk extension library must extend an existing vndk library which has
`vendor_available: true`. These two libraries must have the same
`support_system_process` property.
VNDK-ext libraries are installed to `/vendor/lib[64]/vndk` and
VNDK-SP-ext libraries are installed to `/vendor/lib[64]/vndk-sp` by
default.
If there is a matching abi-dumps in `prebuilts/abi-dumps`,
`header-abi-diff` will be invoked to check for ABI breakages.
Bug: 38340960
Test: lunch aosp_walleye-userdebug && make -j8 # runs unit tests
Test: lunch aosp_arm-userdebug && make -j8 # build a target w/o VNDK
Test: Create a lsdump for a vndk lib, add an exported API to vndk lib,
and build fails as expected.
Test: Create a lsdump for a vndk lib, create an vndk extension lib with
extra API, and build succeeds as expected.
Test: Create libutils_ext, add an extra function to libutils_ext, and
call it from a HIDL service.
Change-Id: Iba90e08848ee99814405457f047321e6b52b2df0
2017-10-31 18:04:35 +08:00
|
|
|
if isVndkExt {
|
|
|
|
localAbiCheckAllowFlags = append(localAbiCheckAllowFlags, "-allow-extensions")
|
|
|
|
}
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: sAbiDiff,
|
|
|
|
Description: "header-abi-diff " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputDump,
|
|
|
|
Implicit: referenceDump,
|
2017-02-09 05:45:53 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"referenceDump": referenceDump.String(),
|
2018-02-02 09:23:09 +08:00
|
|
|
"libName": baseName[0:(len(baseName) - len(filepath.Ext(baseName)))],
|
2017-05-23 01:53:24 +08:00
|
|
|
"arch": ctx.Arch().ArchType.Name,
|
2018-01-18 05:13:33 +08:00
|
|
|
"allowFlags": strings.Join(localAbiCheckAllowFlags, " "),
|
2017-02-09 05:45:53 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
return android.OptionalPathForPath(outputFile)
|
|
|
|
}
|
|
|
|
|
2017-09-28 08:01:44 +08:00
|
|
|
// Generate a rule for extracting a table of contents from a shared library (.so)
|
|
|
|
func TransformSharedObjectToToc(ctx android.ModuleContext, inputFile android.Path,
|
2016-10-01 08:10:16 +08:00
|
|
|
outputFile android.WritablePath, flags builderFlags) {
|
|
|
|
|
|
|
|
crossCompile := gccCmd(flags.toolchain, "")
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: toc,
|
|
|
|
Description: "generate toc " + inputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputFile,
|
2016-10-01 08:10:16 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"crossCompile": crossCompile,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
// Generate a rule for compiling multiple .o files to a .o using ld partial linking
|
2016-05-19 06:37:25 +08:00
|
|
|
func TransformObjsToObj(ctx android.ModuleContext, objFiles android.Paths,
|
|
|
|
flags builderFlags, outputFile android.WritablePath) {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-11-24 06:01:42 +08:00
|
|
|
var ldCmd string
|
|
|
|
if flags.clang {
|
2016-07-30 04:44:28 +08:00
|
|
|
ldCmd = "${config.ClangBin}/clang++"
|
2015-11-24 06:01:42 +08:00
|
|
|
} else {
|
|
|
|
ldCmd = gccCmd(flags.toolchain, "g++")
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: partialLd,
|
|
|
|
Description: "link " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: objFiles,
|
2015-01-31 09:27:36 +08:00
|
|
|
Args: map[string]string{
|
2015-09-24 06:26:20 +08:00
|
|
|
"ldCmd": ldCmd,
|
2015-11-24 06:01:42 +08:00
|
|
|
"ldFlags": flags.ldFlags,
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-03-27 05:44:11 +08:00
|
|
|
// Generate a rule for runing objcopy --prefix-symbols on a binary
|
2016-05-19 06:37:25 +08:00
|
|
|
func TransformBinaryPrefixSymbols(ctx android.ModuleContext, prefix string, inputFile android.Path,
|
|
|
|
flags builderFlags, outputFile android.WritablePath) {
|
2015-03-27 05:44:11 +08:00
|
|
|
|
|
|
|
objcopyCmd := gccCmd(flags.toolchain, "objcopy")
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: prefixSymbols,
|
|
|
|
Description: "prefix symbols " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputFile,
|
2015-03-27 05:44:11 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"objcopyCmd": objcopyCmd,
|
|
|
|
"prefix": prefix,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func TransformStrip(ctx android.ModuleContext, inputFile android.Path,
|
|
|
|
outputFile android.WritablePath, flags builderFlags) {
|
2016-04-29 05:50:03 +08:00
|
|
|
|
|
|
|
crossCompile := gccCmd(flags.toolchain, "")
|
|
|
|
args := ""
|
|
|
|
if flags.stripAddGnuDebuglink {
|
|
|
|
args += " --add-gnu-debuglink"
|
|
|
|
}
|
|
|
|
if flags.stripKeepMiniDebugInfo {
|
|
|
|
args += " --keep-mini-debug-info"
|
|
|
|
}
|
|
|
|
if flags.stripKeepSymbols {
|
|
|
|
args += " --keep-symbols"
|
|
|
|
}
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: strip,
|
|
|
|
Description: "strip " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputFile,
|
2016-04-29 05:50:03 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"crossCompile": crossCompile,
|
|
|
|
"args": args,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func TransformDarwinStrip(ctx android.ModuleContext, inputFile android.Path,
|
|
|
|
outputFile android.WritablePath) {
|
2016-05-04 06:10:29 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: darwinStrip,
|
|
|
|
Description: "strip " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputFile,
|
2016-05-04 06:10:29 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-10 08:16:31 +08:00
|
|
|
func TransformCoverageFilesToLib(ctx android.ModuleContext,
|
|
|
|
inputs Objects, flags builderFlags, baseName string) android.OptionalPath {
|
|
|
|
|
|
|
|
if len(inputs.coverageFiles) > 0 {
|
|
|
|
outputFile := android.PathForModuleOut(ctx, baseName+".gcnodir")
|
|
|
|
|
|
|
|
TransformObjToStaticLib(ctx, inputs.coverageFiles, flags, outputFile, nil)
|
|
|
|
|
|
|
|
return android.OptionalPathForPath(outputFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
return android.OptionalPath{}
|
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func CopyGccLib(ctx android.ModuleContext, libName string,
|
|
|
|
flags builderFlags, outputFile android.WritablePath) {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: copyGccLib,
|
|
|
|
Description: "copy gcc library " + libName,
|
|
|
|
Output: outputFile,
|
2015-01-31 09:27:36 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"ccCmd": gccCmd(flags.toolchain, "gcc"),
|
|
|
|
"cFlags": flags.globalFlags,
|
|
|
|
"libName": libName,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
func gccCmd(toolchain config.Toolchain, cmd string) string {
|
2015-01-31 09:27:36 +08:00
|
|
|
return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd)
|
|
|
|
}
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2017-05-10 04:34:34 +08:00
|
|
|
func splitListForSize(list android.Paths, limit int) (lists []android.Paths, err error) {
|
2015-05-01 07:36:18 +08:00
|
|
|
var i int
|
|
|
|
|
|
|
|
start := 0
|
|
|
|
bytes := 0
|
|
|
|
for i = range list {
|
2017-05-10 04:34:34 +08:00
|
|
|
l := len(list[i].String())
|
2015-05-01 07:36:18 +08:00
|
|
|
if l > limit {
|
|
|
|
return nil, fmt.Errorf("list element greater than size limit (%d)", limit)
|
|
|
|
}
|
|
|
|
if bytes+l > limit {
|
|
|
|
lists = append(lists, list[start:i])
|
|
|
|
start = i
|
|
|
|
bytes = 0
|
|
|
|
}
|
|
|
|
bytes += l + 1 // count a space between each list element
|
|
|
|
}
|
|
|
|
|
|
|
|
lists = append(lists, list[start:])
|
|
|
|
|
|
|
|
totalLen := 0
|
|
|
|
for _, l := range lists {
|
|
|
|
totalLen += len(l)
|
|
|
|
}
|
|
|
|
if totalLen != len(list) {
|
|
|
|
panic(fmt.Errorf("Failed breaking up list, %d != %d", len(list), totalLen))
|
|
|
|
}
|
|
|
|
return lists, nil
|
|
|
|
}
|