2015-01-31 02:27:36 +01: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 (
|
2016-07-29 22:44:28 +02:00
|
|
|
"path/filepath"
|
2015-05-01 01:36:18 +02:00
|
|
|
"runtime"
|
2021-09-10 08:20:39 +02:00
|
|
|
"strconv"
|
2015-01-31 02:27:36 +01:00
|
|
|
"strings"
|
2015-03-26 22:43:45 +01:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2019-06-08 02:58:59 +02:00
|
|
|
"github.com/google/blueprint/pathtools"
|
2016-07-29 22:44:28 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc/config"
|
2020-04-13 19:21:23 +02:00
|
|
|
"android/soong/remoteexec"
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-04-29 03:17:56 +02:00
|
|
|
objectExtension = ".o"
|
2015-01-31 02:27:36 +01:00
|
|
|
staticLibraryExtension = ".a"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-05-19 00:37:25 +02:00
|
|
|
pctx = android.NewPackageContext("android/soong/cc")
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to invoke gcc with given command, flags, and dependencies. Outputs a .d depfile.
|
2020-01-27 20:19:44 +01:00
|
|
|
cc = pctx.AndroidRemoteStaticRule("cc", android.RemoteRuleSupports{Goma: true, RBE: true},
|
2015-01-31 02:27:36 +01:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
2020-10-20 07:52:49 +02:00
|
|
|
Command: "$relPwd ${config.CcWrapper}$ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$ccCmd"},
|
2015-01-31 02:27:36 +01:00
|
|
|
},
|
2015-11-18 00:19:46 +01:00
|
|
|
"ccCmd", "cFlags")
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to invoke gcc with given command and flags, but no dependencies.
|
2020-02-17 09:26:55 +01:00
|
|
|
ccNoDeps = pctx.AndroidStaticRule("ccNoDeps",
|
2019-01-04 08:25:11 +01:00
|
|
|
blueprint.RuleParams{
|
2020-10-20 07:52:49 +02:00
|
|
|
Command: "$relPwd $ccCmd -c $cFlags -o $out $in",
|
2019-01-04 08:25:11 +01:00
|
|
|
CommandDeps: []string{"$ccCmd"},
|
|
|
|
},
|
|
|
|
"ccCmd", "cFlags")
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rules to invoke ld to link binaries. Uses a .rsp file to list dependencies, as there may
|
|
|
|
// be many.
|
2021-03-12 20:28:25 +01:00
|
|
|
ld, ldRE = pctx.RemoteStaticRules("ld",
|
2015-01-31 02:27:36 +01:00
|
|
|
blueprint.RuleParams{
|
2020-04-17 21:03:58 +02:00
|
|
|
Command: "$reTemplate$ldCmd ${crtBegin} @${out}.rsp " +
|
2019-08-02 15:02:20 +02:00
|
|
|
"${libFlags} ${crtEnd} -o ${out} ${ldFlags} ${extraLibFlags}",
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$ldCmd"},
|
2015-03-31 02:47:53 +02:00
|
|
|
Rspfile: "${out}.rsp",
|
|
|
|
RspfileContent: "${in}",
|
2019-03-29 23:55:30 +01:00
|
|
|
// clang -Wl,--out-implib doesn't update its output file if it hasn't changed.
|
|
|
|
Restat: true,
|
2015-01-31 02:27:36 +01:00
|
|
|
},
|
2020-04-17 21:03:58 +02:00
|
|
|
&remoteexec.REParams{
|
|
|
|
Labels: map[string]string{"type": "link", "tool": "clang"},
|
2020-04-13 19:21:23 +02:00
|
|
|
ExecStrategy: "${config.RECXXLinksExecStrategy}",
|
2020-08-28 20:21:55 +02:00
|
|
|
Inputs: []string{"${out}.rsp", "$implicitInputs"},
|
2021-03-24 22:09:28 +01:00
|
|
|
RSPFiles: []string{"${out}.rsp"},
|
2020-04-22 22:31:09 +02:00
|
|
|
OutputFiles: []string{"${out}", "$implicitOutputs"},
|
2020-04-13 19:21:23 +02:00
|
|
|
ToolchainInputs: []string{"$ldCmd"},
|
|
|
|
Platform: map[string]string{remoteexec.PoolKey: "${config.RECXXLinksPool}"},
|
2020-08-28 20:21:55 +02:00
|
|
|
}, []string{"ldCmd", "crtBegin", "libFlags", "crtEnd", "ldFlags", "extraLibFlags"}, []string{"implicitInputs", "implicitOutputs"})
|
2020-04-13 19:21:23 +02:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rules for .o files to combine to other .o files, using ld partial linking.
|
2021-03-12 20:28:25 +01:00
|
|
|
partialLd, partialLdRE = pctx.RemoteStaticRules("partialLd",
|
2015-01-31 02:27:36 +01:00
|
|
|
blueprint.RuleParams{
|
2018-01-10 23:30:44 +01:00
|
|
|
// Without -no-pie, clang 7.0 adds -pie to link Android files,
|
|
|
|
// but -r and -pie cannot be used together.
|
2020-04-17 21:03:58 +02:00
|
|
|
Command: "$reTemplate$ldCmd -fuse-ld=lld -nostdlib -no-pie -Wl,-r ${in} -o ${out} ${ldFlags}",
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$ldCmd"},
|
2020-04-13 19:21:23 +02:00
|
|
|
}, &remoteexec.REParams{
|
2020-08-28 20:21:55 +02:00
|
|
|
Labels: map[string]string{"type": "link", "tool": "clang"},
|
|
|
|
ExecStrategy: "${config.RECXXLinksExecStrategy}",
|
|
|
|
Inputs: []string{"$inCommaList", "$implicitInputs"},
|
2020-04-22 22:31:09 +02:00
|
|
|
OutputFiles: []string{"${out}", "$implicitOutputs"},
|
2020-04-13 19:21:23 +02:00
|
|
|
ToolchainInputs: []string{"$ldCmd"},
|
|
|
|
Platform: map[string]string{remoteexec.PoolKey: "${config.RECXXLinksPool}"},
|
2020-08-28 20:21:55 +02:00
|
|
|
}, []string{"ldCmd", "ldFlags"}, []string{"implicitInputs", "inCommaList", "implicitOutputs"})
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to invoke `ar` with given cmd and flags, but no static library depenencies.
|
2016-08-30 01:14:13 +02:00
|
|
|
ar = pctx.AndroidStaticRule("ar",
|
2015-01-31 02:27:36 +01:00
|
|
|
blueprint.RuleParams{
|
2015-03-31 02:47:53 +02:00
|
|
|
Command: "rm -f ${out} && $arCmd $arFlags $out @${out}.rsp",
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$arCmd"},
|
2015-03-31 02:47:53 +02:00
|
|
|
Rspfile: "${out}.rsp",
|
|
|
|
RspfileContent: "${in}",
|
2015-01-31 02:27:36 +01:00
|
|
|
},
|
|
|
|
"arCmd", "arFlags")
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to invoke `ar` with given cmd, flags, and library dependencies. Generates a .a
|
|
|
|
// (archive) file from .o files.
|
2020-04-17 18:34:31 +02:00
|
|
|
arWithLibs = pctx.AndroidStaticRule("arWithLibs",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "rm -f ${out} && $arCmd $arObjFlags $out @${out}.rsp && $arCmd $arLibFlags $out $arLibs",
|
|
|
|
CommandDeps: []string{"$arCmd"},
|
|
|
|
Rspfile: "${out}.rsp",
|
|
|
|
RspfileContent: "${arObjs}",
|
|
|
|
},
|
|
|
|
"arCmd", "arObjFlags", "arObjs", "arLibFlags", "arLibs")
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to run objcopy --prefix-symbols (to prefix all symbols in a file with a given string).
|
2016-08-30 01:14:13 +02:00
|
|
|
prefixSymbols = pctx.AndroidStaticRule("prefixSymbols",
|
2015-03-26 22:44:11 +01:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$objcopyCmd --prefix-symbols=${prefix} ${in} ${out}",
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$objcopyCmd"},
|
2015-03-26 22:44:11 +01:00
|
|
|
},
|
|
|
|
"objcopyCmd", "prefix")
|
|
|
|
|
2017-03-27 23:27:58 +02:00
|
|
|
_ = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh")
|
2018-03-09 19:47:52 +01:00
|
|
|
_ = pctx.SourcePathVariable("xzCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/xz")
|
2021-04-29 22:06:47 +02:00
|
|
|
_ = pctx.SourcePathVariable("createMiniDebugInfo", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/create_minidebuginfo")
|
2016-04-28 23:50:03 +02:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to invoke `strip` (to discard symbols and data from object files).
|
|
|
|
strip = pctx.AndroidStaticRule("strip",
|
|
|
|
blueprint.RuleParams{
|
2021-04-29 22:06:47 +02:00
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
|
|
|
Command: "XZ=$xzCmd CREATE_MINIDEBUGINFO=$createMiniDebugInfo CLANG_BIN=${config.ClangBin} $stripPath ${args} -i ${in} -o ${out} -d ${out}.d",
|
|
|
|
CommandDeps: func() []string {
|
|
|
|
if runtime.GOOS != "darwin" {
|
|
|
|
return []string{"$stripPath", "$xzCmd", "$createMiniDebugInfo"}
|
|
|
|
} else {
|
|
|
|
return []string{"$stripPath", "$xzCmd"}
|
|
|
|
}
|
|
|
|
}(),
|
|
|
|
Pool: darwinStripPool,
|
2020-11-23 23:02:44 +01:00
|
|
|
},
|
2021-05-05 22:54:11 +02:00
|
|
|
"args")
|
2020-11-23 23:02:44 +01:00
|
|
|
|
|
|
|
// Rule to invoke `strip` (to discard symbols and data from object files) on darwin architecture.
|
|
|
|
darwinStrip = pctx.AndroidStaticRule("darwinStrip",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "${config.MacStripPath} -u -r -o $out $in",
|
|
|
|
CommandDeps: []string{"${config.MacStripPath}"},
|
|
|
|
})
|
|
|
|
|
2019-05-18 00:36:46 +02:00
|
|
|
// b/132822437: objcopy uses a file descriptor per .o file when called on .a files, which runs the system out of
|
2019-05-22 22:25:50 +02:00
|
|
|
// file descriptors on darwin. Limit concurrent calls to 5 on darwin.
|
2019-05-18 00:36:46 +02:00
|
|
|
darwinStripPool = func() blueprint.Pool {
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
return pctx.StaticPool("darwinStripPool", blueprint.PoolParams{
|
2019-05-22 22:25:50 +02:00
|
|
|
Depth: 5,
|
2019-05-18 00:36:46 +02:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2019-10-15 11:01:19 +02:00
|
|
|
_ = pctx.SourcePathVariable("archiveRepackPath", "build/soong/scripts/archive_repack.sh")
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to repack an archive (.a) file with a subset of object files.
|
2019-10-15 11:01:19 +02:00
|
|
|
archiveRepack = pctx.AndroidStaticRule("archiveRepack",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
|
|
|
Command: "CLANG_BIN=${config.ClangBin} $archiveRepackPath -i ${in} -o ${out} -d ${out}.d ${objects}",
|
|
|
|
CommandDeps: []string{"$archiveRepackPath"},
|
|
|
|
},
|
|
|
|
"objects")
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to create an empty file at a given path.
|
2016-08-30 01:14:13 +02:00
|
|
|
emptyFile = pctx.AndroidStaticRule("emptyFile",
|
2016-05-13 23:05:09 +02:00
|
|
|
blueprint.RuleParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Command: "rm -f $out && touch $out",
|
2016-05-13 23:05:09 +02:00
|
|
|
})
|
|
|
|
|
2017-03-27 23:27:58 +02:00
|
|
|
_ = pctx.SourcePathVariable("tocPath", "build/soong/scripts/toc.sh")
|
2016-10-01 02:10:16 +02:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// A rule for extracting a table of contents from a shared library (.so).
|
2016-10-01 02:10:16 +02:00
|
|
|
toc = pctx.AndroidStaticRule("toc",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
2021-04-01 11:45:42 +02:00
|
|
|
Command: "CLANG_BIN=$clangBin $tocPath $format -i ${in} -o ${out} -d ${out}.d",
|
2016-10-01 02:10:16 +02:00
|
|
|
CommandDeps: []string{"$tocPath"},
|
|
|
|
Restat: true,
|
|
|
|
},
|
2021-04-01 11:45:42 +02:00
|
|
|
"clangBin", "format")
|
2016-09-27 00:45:04 +02:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule for invoking clang-tidy (a clang-based linter).
|
2021-03-12 20:28:25 +01:00
|
|
|
clangTidy, clangTidyRE = pctx.RemoteStaticRules("clangTidy",
|
2016-09-27 00:45:04 +02:00
|
|
|
blueprint.RuleParams{
|
Use ccCmd to generate clang-tidy dependent file
* After this change, make libtinyxml2-tidy should generate
correct out/.../libtinyxml2.tidy.d file.
Touching one of the dependent files, e.g., tinyxml2.h,
should invoke clang-tidy but not to recompile tinyxml2.o.
* Note that linking libraries still depend on .tidy targets,
so make libtinyxml2 will call clang-tidy, regnerate
tinyxml2.tidy.d, tinyxml2.tidy, tinyxml2.o.d, tinyxml2.o.
* A clang-tidy rule uses the same $cFlags for both clang and clang-tidy.
To share it and avoid over long command lines, we use modern shell
array variables and cannot use old bourne shell.
Bug: 199169329
Test: WITH_TIDY=1 make
Test: WITH_TIDY=1 make libtinyxml2-tidy | grep tinyxml2
Test: touch external/tinyxml2/tinyxml2.h; make libtinyxml2-tidy | grep tinyxml2
Change-Id: I6175add58d7313ee50c9308b78c9290a60770052
2021-09-11 02:25:28 +02:00
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
|
|
|
// Pick bash because some machines with old /bin/sh cannot handle arrays.
|
|
|
|
// All $cFlags and $tidyFlags should have single quotes escaped.
|
|
|
|
// Assume no single quotes in other parameters like $in, $out, $ccCmd.
|
|
|
|
Command: "/bin/bash -c 'SRCF=$in; TIDYF=$out; CLANGFLAGS=($cFlags); " +
|
|
|
|
"rm -f $$TIDYF $${TIDYF}.d && " +
|
|
|
|
"${config.CcWrapper}$ccCmd \"$${CLANGFLAGS[@]}\" -E -o /dev/null $$SRCF " +
|
|
|
|
"-MQ $$TIDYF -MD -MF $${TIDYF}.d && " +
|
|
|
|
"$tidyVars $reTemplate${config.ClangBin}/clang-tidy $tidyFlags $$SRCF " +
|
|
|
|
"-- \"$${CLANGFLAGS[@]}\" && touch $$TIDYF'",
|
|
|
|
CommandDeps: []string{"${config.ClangBin}/clang-tidy", "$ccCmd"},
|
2016-09-27 00:45:04 +02:00
|
|
|
},
|
2020-06-18 18:17:51 +02:00
|
|
|
&remoteexec.REParams{
|
2021-09-10 04:12:05 +02:00
|
|
|
Labels: map[string]string{"type": "lint", "tool": "clang-tidy", "lang": "cpp"},
|
|
|
|
ExecStrategy: "${config.REClangTidyExecStrategy}",
|
|
|
|
Inputs: []string{"$in"},
|
|
|
|
EnvironmentVariables: []string{"TIDY_TIMEOUT"},
|
2021-08-30 21:49:39 +02:00
|
|
|
// Although clang-tidy has an option to "fix" source files, that feature is hardly useable
|
|
|
|
// under parallel compilation and RBE. So we assume no OutputFiles here.
|
|
|
|
// The clang-tidy fix option is best run locally in single thread.
|
|
|
|
// Copying source file back to local caused two problems:
|
|
|
|
// (1) New timestamps trigger clang and clang-tidy compilations again.
|
|
|
|
// (2) Changing source files caused concurrent clang or clang-tidy jobs to crash.
|
|
|
|
Platform: map[string]string{remoteexec.PoolKey: "${config.REClangTidyPool}"},
|
Use ccCmd to generate clang-tidy dependent file
* After this change, make libtinyxml2-tidy should generate
correct out/.../libtinyxml2.tidy.d file.
Touching one of the dependent files, e.g., tinyxml2.h,
should invoke clang-tidy but not to recompile tinyxml2.o.
* Note that linking libraries still depend on .tidy targets,
so make libtinyxml2 will call clang-tidy, regnerate
tinyxml2.tidy.d, tinyxml2.tidy, tinyxml2.o.d, tinyxml2.o.
* A clang-tidy rule uses the same $cFlags for both clang and clang-tidy.
To share it and avoid over long command lines, we use modern shell
array variables and cannot use old bourne shell.
Bug: 199169329
Test: WITH_TIDY=1 make
Test: WITH_TIDY=1 make libtinyxml2-tidy | grep tinyxml2
Test: touch external/tinyxml2/tinyxml2.h; make libtinyxml2-tidy | grep tinyxml2
Change-Id: I6175add58d7313ee50c9308b78c9290a60770052
2021-09-11 02:25:28 +02:00
|
|
|
}, []string{"ccCmd", "cFlags", "tidyFlags", "tidyVars"}, []string{})
|
2016-12-03 02:13:24 +01:00
|
|
|
|
2017-03-27 23:27:58 +02:00
|
|
|
_ = pctx.SourcePathVariable("yasmCmd", "prebuilts/misc/${config.HostPrebuiltTag}/yasm/yasm")
|
2016-12-03 02:13:24 +01:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule for invoking yasm to compile .asm assembly files.
|
2016-12-03 02:13:24 +01:00
|
|
|
yasm = pctx.AndroidStaticRule("yasm",
|
|
|
|
blueprint.RuleParams{
|
2017-08-23 05:53:45 +02:00
|
|
|
Command: "$yasmCmd $asFlags -o $out $in && $yasmCmd $asFlags -M $in >$out.d",
|
2016-12-03 02:13:24 +01:00
|
|
|
CommandDeps: []string{"$yasmCmd"},
|
2017-08-23 05:53:45 +02:00
|
|
|
Depfile: "$out.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
2016-12-03 02:13:24 +01:00
|
|
|
},
|
|
|
|
"asFlags")
|
2017-02-08 22:45:53 +01:00
|
|
|
|
2018-02-20 21:36:51 +01:00
|
|
|
_ = pctx.SourcePathVariable("sAbiDumper", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-dumper")
|
2017-02-08 22:45:53 +01:00
|
|
|
|
2017-04-20 15:53:59 +02:00
|
|
|
// -w has been added since header-abi-dumper does not need to produce any sort of diagnostic information.
|
2021-03-12 20:28:25 +01:00
|
|
|
sAbiDump, sAbiDumpRE = pctx.RemoteStaticRules("sAbiDump",
|
2017-02-08 22:45:53 +01:00
|
|
|
blueprint.RuleParams{
|
2021-07-09 09:59:03 +02:00
|
|
|
Command: "rm -f $out && $reTemplate$sAbiDumper --root-dir . --root-dir $$OUT_DIR:out -o ${out} $in $exportDirs -- $cFlags -w -isystem prebuilts/clang-tools/${config.HostPrebuiltTag}/clang-headers",
|
2017-02-08 22:45:53 +01:00
|
|
|
CommandDeps: []string{"$sAbiDumper"},
|
2020-04-17 21:03:58 +02:00
|
|
|
}, &remoteexec.REParams{
|
|
|
|
Labels: map[string]string{"type": "abi-dump", "tool": "header-abi-dumper"},
|
|
|
|
ExecStrategy: "${config.REAbiDumperExecStrategy}",
|
2020-11-25 22:54:35 +01:00
|
|
|
Inputs: []string{"$sAbiLinkerLibs"},
|
2020-04-17 21:03:58 +02:00
|
|
|
Platform: map[string]string{
|
2020-11-23 23:02:44 +01:00
|
|
|
remoteexec.PoolKey: "${config.RECXXPool}",
|
2020-04-17 21:03:58 +02:00
|
|
|
},
|
|
|
|
}, []string{"cFlags", "exportDirs"}, nil)
|
2017-02-08 22:45:53 +01:00
|
|
|
|
2018-02-20 21:36:51 +01:00
|
|
|
_ = pctx.SourcePathVariable("sAbiLinker", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-linker")
|
2020-05-07 12:56:47 +02:00
|
|
|
_ = pctx.SourcePathVariable("sAbiLinkerLibs", "prebuilts/clang-tools/${config.HostPrebuiltTag}/lib64")
|
2017-02-08 22:45:53 +01:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to combine .dump sAbi dump files from multiple source files into a single .ldump
|
|
|
|
// sAbi dump file.
|
2021-03-12 20:28:25 +01:00
|
|
|
sAbiLink, sAbiLinkRE = pctx.RemoteStaticRules("sAbiLink",
|
2017-02-08 22:45:53 +01:00
|
|
|
blueprint.RuleParams{
|
2021-07-09 09:59:03 +02:00
|
|
|
Command: "$reTemplate$sAbiLinker --root-dir . --root-dir $$OUT_DIR:out -o ${out} $symbolFilter -arch $arch $exportedHeaderFlags @${out}.rsp",
|
2017-02-08 22:45:53 +01:00
|
|
|
CommandDeps: []string{"$sAbiLinker"},
|
|
|
|
Rspfile: "${out}.rsp",
|
|
|
|
RspfileContent: "${in}",
|
2020-05-07 12:56:47 +02:00
|
|
|
}, &remoteexec.REParams{
|
|
|
|
Labels: map[string]string{"type": "tool", "name": "abi-linker"},
|
|
|
|
ExecStrategy: "${config.REAbiLinkerExecStrategy}",
|
2020-08-28 20:21:55 +02:00
|
|
|
Inputs: []string{"$sAbiLinkerLibs", "${out}.rsp", "$implicitInputs"},
|
2021-03-24 22:09:28 +01:00
|
|
|
RSPFiles: []string{"${out}.rsp"},
|
2020-05-07 12:56:47 +02:00
|
|
|
OutputFiles: []string{"$out"},
|
|
|
|
ToolchainInputs: []string{"$sAbiLinker"},
|
|
|
|
Platform: map[string]string{remoteexec.PoolKey: "${config.RECXXPool}"},
|
2020-08-28 20:21:55 +02:00
|
|
|
}, []string{"symbolFilter", "arch", "exportedHeaderFlags"}, []string{"implicitInputs"})
|
2017-02-08 22:45:53 +01:00
|
|
|
|
2018-02-20 21:36:51 +01:00
|
|
|
_ = pctx.SourcePathVariable("sAbiDiffer", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-diff")
|
2017-04-20 15:53:59 +02:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to compare linked sAbi dump files (.ldump).
|
2019-09-25 22:31:46 +02:00
|
|
|
sAbiDiff = pctx.RuleFunc("sAbiDiff",
|
2018-03-12 21:24:09 +01:00
|
|
|
func(ctx android.PackageRuleContext) blueprint.RuleParams {
|
2019-10-02 00:58:07 +02:00
|
|
|
commandStr := "($sAbiDiffer ${extraFlags} -lib ${libName} -arch ${arch} -o ${out} -new ${in} -old ${referenceDump})"
|
2019-02-18 06:12:21 +01:00
|
|
|
commandStr += "|| (echo 'error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py ${createReferenceDumpFlags} -l ${libName}'"
|
2019-01-28 05:14:54 +01:00
|
|
|
commandStr += " && (mkdir -p $$DIST_DIR/abidiffs && cp ${out} $$DIST_DIR/abidiffs/)"
|
2018-02-02 02:23:09 +01:00
|
|
|
commandStr += " && exit 1)"
|
2017-11-27 23:52:21 +01:00
|
|
|
return blueprint.RuleParams{
|
|
|
|
Command: commandStr,
|
|
|
|
CommandDeps: []string{"$sAbiDiffer"},
|
2018-03-12 21:24:09 +01:00
|
|
|
}
|
2017-02-08 22:45:53 +01:00
|
|
|
},
|
2019-10-02 00:58:07 +02:00
|
|
|
"extraFlags", "referenceDump", "libName", "arch", "createReferenceDumpFlags")
|
2017-04-20 15:53:59 +02:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to unzip a reference abi dump.
|
2017-04-20 15:53:59 +02:00
|
|
|
unzipRefSAbiDump = pctx.AndroidStaticRule("unzipRefSAbiDump",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "gunzip -c $in > $out",
|
|
|
|
})
|
2019-04-24 23:22:25 +02:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to zip files.
|
2019-04-24 23:22:25 +02:00
|
|
|
zip = pctx.AndroidStaticRule("zip",
|
|
|
|
blueprint.RuleParams{
|
2020-08-19 22:51:47 +02:00
|
|
|
Command: "${SoongZipCmd} -o ${out} -C $$OUT_DIR -r ${out}.rsp",
|
2019-04-24 23:22:25 +02:00
|
|
|
CommandDeps: []string{"${SoongZipCmd}"},
|
2020-08-19 22:51:47 +02:00
|
|
|
Rspfile: "${out}.rsp",
|
2019-04-24 23:22:25 +02:00
|
|
|
RspfileContent: "$in",
|
|
|
|
})
|
2018-11-06 01:49:08 +01:00
|
|
|
|
|
|
|
_ = pctx.SourcePathVariable("cxxExtractor",
|
|
|
|
"prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/cxx_extractor")
|
2019-09-27 05:14:28 +02:00
|
|
|
_ = pctx.SourcePathVariable("kytheVnames", "build/soong/vnames.json")
|
2018-11-06 01:49:08 +01:00
|
|
|
_ = pctx.VariableFunc("kytheCorpus",
|
|
|
|
func(ctx android.PackageVarContext) string { return ctx.Config().XrefCorpusName() })
|
2020-01-10 02:34:23 +01:00
|
|
|
_ = pctx.VariableFunc("kytheCuEncoding",
|
|
|
|
func(ctx android.PackageVarContext) string { return ctx.Config().XrefCuEncoding() })
|
2020-11-23 23:02:44 +01:00
|
|
|
|
|
|
|
// Rule to use kythe extractors to generate .kzip files, used to build code cross references.
|
2018-11-06 01:49:08 +01:00
|
|
|
kytheExtract = pctx.StaticRule("kythe",
|
|
|
|
blueprint.RuleParams{
|
2020-01-10 02:34:23 +01:00
|
|
|
Command: `rm -f $out && ` +
|
2020-04-22 02:08:35 +02:00
|
|
|
`KYTHE_CORPUS=${kytheCorpus} ` +
|
|
|
|
`KYTHE_OUTPUT_FILE=$out ` +
|
|
|
|
`KYTHE_VNAMES=$kytheVnames ` +
|
|
|
|
`KYTHE_KZIP_ENCODING=${kytheCuEncoding} ` +
|
|
|
|
`KYTHE_CANONICALIZE_VNAME_PATHS=prefer-relative ` +
|
2020-01-10 02:34:23 +01:00
|
|
|
`$cxxExtractor $cFlags $in `,
|
2019-09-27 05:14:28 +02:00
|
|
|
CommandDeps: []string{"$cxxExtractor", "$kytheVnames"},
|
2018-11-06 01:49:08 +01:00
|
|
|
},
|
|
|
|
"cFlags")
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
2020-05-20 15:03:20 +02:00
|
|
|
func PwdPrefix() string {
|
|
|
|
// Darwin doesn't have /proc
|
|
|
|
if runtime.GOOS != "darwin" {
|
|
|
|
return "PWD=/proc/self/cwd"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2015-11-18 00:19:46 +01: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.
|
2020-05-20 15:03:20 +02:00
|
|
|
pctx.StaticVariable("relPwd", PwdPrefix())
|
2019-04-24 23:22:25 +02:00
|
|
|
|
|
|
|
pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
|
2015-11-18 00:19:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// builderFlags contains various types of command line flags (and settings) for use in building
|
|
|
|
// build statements related to C++.
|
2015-01-31 02:27:36 +01:00
|
|
|
type builderFlags struct {
|
2020-11-23 23:02:44 +01:00
|
|
|
// Global flags (which build system or toolchain is responsible for). These are separate from
|
|
|
|
// local flags because they should appear first (so that they may be overridden by local flags).
|
2019-11-06 16:06:58 +01:00
|
|
|
globalCommonFlags string
|
|
|
|
globalAsFlags string
|
|
|
|
globalYasmFlags string
|
|
|
|
globalCFlags string
|
|
|
|
globalToolingCFlags string // A separate set of cFlags for clang LibTooling tools
|
|
|
|
globalToolingCppFlags string // A separate set of cppFlags for clang LibTooling tools
|
|
|
|
globalConlyFlags string
|
|
|
|
globalCppFlags string
|
|
|
|
globalLdFlags string
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Local flags (which individual modules are responsible for). These may override global flags.
|
2019-11-06 16:06:58 +01:00
|
|
|
localCommonFlags string
|
|
|
|
localAsFlags string
|
|
|
|
localYasmFlags string
|
|
|
|
localCFlags string
|
|
|
|
localToolingCFlags string // A separate set of cFlags for clang LibTooling tools
|
|
|
|
localToolingCppFlags string // A separate set of cppFlags for clang LibTooling tools
|
|
|
|
localConlyFlags string
|
|
|
|
localCppFlags string
|
|
|
|
localLdFlags string
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
libFlags string // Flags to add to the linker directly after specifying libraries to link.
|
|
|
|
extraLibFlags string // Flags to add to the linker last.
|
|
|
|
tidyFlags string // Flags that apply to clang-tidy
|
|
|
|
sAbiFlags string // Flags that apply to header-abi-dumps
|
|
|
|
aidlFlags string // Flags that apply to aidl source files
|
|
|
|
rsFlags string // Flags that apply to renderscript source files
|
2019-11-06 16:06:58 +01:00
|
|
|
toolchain config.Toolchain
|
2016-04-28 23:50:03 +02:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// True if these extra features are enabled.
|
|
|
|
tidy bool
|
|
|
|
gcovCoverage bool
|
|
|
|
sAbiDump bool
|
|
|
|
emitXrefs bool
|
|
|
|
|
|
|
|
assemblerWithCpp bool // True if .s files should be processed with the c preprocessor.
|
2019-08-28 06:20:40 +02:00
|
|
|
|
2017-03-31 00:03:04 +02:00
|
|
|
systemIncludeFlags string
|
|
|
|
|
2019-03-28 22:45:07 +01:00
|
|
|
proto android.ProtoFlags
|
2020-11-23 23:02:44 +01:00
|
|
|
protoC bool // If true, compile protos as `.c` files. Otherwise, output as `.cc`.
|
|
|
|
protoOptionsFile bool // If true, output a proto options file.
|
2019-04-11 07:59:54 +02:00
|
|
|
|
|
|
|
yacc *YaccProperties
|
2020-07-15 10:58:56 +02:00
|
|
|
lex *LexProperties
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// StripFlags represents flags related to stripping. This is separate from builderFlags, as these
|
|
|
|
// flags are useful outside of this package (such as for Rust).
|
2020-08-19 14:53:01 +02:00
|
|
|
type StripFlags struct {
|
|
|
|
Toolchain config.Toolchain
|
|
|
|
StripKeepSymbols bool
|
|
|
|
StripKeepSymbolsList string
|
|
|
|
StripKeepSymbolsAndDebugFrame bool
|
|
|
|
StripKeepMiniDebugInfo bool
|
|
|
|
StripAddGnuDebuglink bool
|
|
|
|
StripUseGnuStrip bool
|
|
|
|
}
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Objects is a collection of file paths corresponding to outputs for C++ related build statements.
|
2016-09-27 02:33:01 +02:00
|
|
|
type Objects struct {
|
2017-02-10 01:16:31 +01:00
|
|
|
objFiles android.Paths
|
2021-10-25 20:09:19 +02:00
|
|
|
tidyFiles android.WritablePaths
|
2017-02-10 01:16:31 +01:00
|
|
|
coverageFiles android.Paths
|
2017-02-08 22:45:53 +01:00
|
|
|
sAbiDumpFiles android.Paths
|
2018-11-06 01:49:08 +01:00
|
|
|
kytheFiles android.Paths
|
2016-09-27 02:33:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a Objects) Copy() Objects {
|
|
|
|
return Objects{
|
2017-02-10 01:16:31 +01:00
|
|
|
objFiles: append(android.Paths{}, a.objFiles...),
|
2021-10-25 20:09:19 +02:00
|
|
|
tidyFiles: append(android.WritablePaths{}, a.tidyFiles...),
|
2017-02-10 01:16:31 +01:00
|
|
|
coverageFiles: append(android.Paths{}, a.coverageFiles...),
|
2017-02-08 22:45:53 +01:00
|
|
|
sAbiDumpFiles: append(android.Paths{}, a.sAbiDumpFiles...),
|
2018-11-06 01:49:08 +01:00
|
|
|
kytheFiles: append(android.Paths{}, a.kytheFiles...),
|
2016-09-27 02:33:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a Objects) Append(b Objects) Objects {
|
|
|
|
return Objects{
|
2017-02-10 01:16:31 +01:00
|
|
|
objFiles: append(a.objFiles, b.objFiles...),
|
|
|
|
tidyFiles: append(a.tidyFiles, b.tidyFiles...),
|
|
|
|
coverageFiles: append(a.coverageFiles, b.coverageFiles...),
|
2017-02-08 22:45:53 +01:00
|
|
|
sAbiDumpFiles: append(a.sAbiDumpFiles, b.sAbiDumpFiles...),
|
2018-11-06 01:49:08 +01:00
|
|
|
kytheFiles: append(a.kytheFiles, b.kytheFiles...),
|
2016-09-27 02:33:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Use ccCmd to generate clang-tidy dependent file
* After this change, make libtinyxml2-tidy should generate
correct out/.../libtinyxml2.tidy.d file.
Touching one of the dependent files, e.g., tinyxml2.h,
should invoke clang-tidy but not to recompile tinyxml2.o.
* Note that linking libraries still depend on .tidy targets,
so make libtinyxml2 will call clang-tidy, regnerate
tinyxml2.tidy.d, tinyxml2.tidy, tinyxml2.o.d, tinyxml2.o.
* A clang-tidy rule uses the same $cFlags for both clang and clang-tidy.
To share it and avoid over long command lines, we use modern shell
array variables and cannot use old bourne shell.
Bug: 199169329
Test: WITH_TIDY=1 make
Test: WITH_TIDY=1 make libtinyxml2-tidy | grep tinyxml2
Test: touch external/tinyxml2/tinyxml2.h; make libtinyxml2-tidy | grep tinyxml2
Change-Id: I6175add58d7313ee50c9308b78c9290a60770052
2021-09-11 02:25:28 +02:00
|
|
|
func escapeSingleQuotes(s string) string {
|
|
|
|
// Replace single quotes to work when embedded in a single quoted string for bash.
|
|
|
|
// Relying on string concatenation of bash to get A'B from quoted 'A'\''B'.
|
|
|
|
return strings.Replace(s, `'`, `'\''`, -1)
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files
|
2021-09-18 02:18:39 +02:00
|
|
|
func transformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles, noTidySrcs android.Paths,
|
2018-01-23 19:49:04 +01:00
|
|
|
flags builderFlags, pathDeps android.Paths, cFlagsDeps android.Paths) Objects {
|
2015-04-08 01:50:10 +02:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Source files are one-to-one with tidy, coverage, or kythe files, if enabled.
|
2016-09-27 02:33:01 +02:00
|
|
|
objFiles := make(android.Paths, len(srcFiles))
|
2021-10-25 20:09:19 +02:00
|
|
|
var tidyFiles android.WritablePaths
|
2021-09-18 02:18:39 +02:00
|
|
|
noTidySrcsMap := make(map[android.Path]bool)
|
2021-09-10 04:12:05 +02:00
|
|
|
var tidyVars string
|
2018-10-08 05:54:34 +02:00
|
|
|
if flags.tidy {
|
2021-10-25 20:09:19 +02:00
|
|
|
tidyFiles = make(android.WritablePaths, 0, len(srcFiles))
|
2021-09-18 02:18:39 +02:00
|
|
|
for _, path := range noTidySrcs {
|
|
|
|
noTidySrcsMap[path] = true
|
|
|
|
}
|
2021-09-10 04:12:05 +02:00
|
|
|
tidyTimeout := ctx.Config().Getenv("TIDY_TIMEOUT")
|
|
|
|
if len(tidyTimeout) > 0 {
|
|
|
|
tidyVars += "TIDY_TIMEOUT=" + tidyTimeout
|
|
|
|
}
|
2016-09-27 00:45:04 +02:00
|
|
|
}
|
2017-02-10 01:16:31 +01:00
|
|
|
var coverageFiles android.Paths
|
2020-04-21 21:40:27 +02:00
|
|
|
if flags.gcovCoverage {
|
2017-02-10 01:16:31 +01:00
|
|
|
coverageFiles = make(android.Paths, 0, len(srcFiles))
|
|
|
|
}
|
2018-11-06 01:49:08 +01:00
|
|
|
var kytheFiles android.Paths
|
|
|
|
if flags.emitXrefs {
|
|
|
|
kytheFiles = make(android.Paths, 0, len(srcFiles))
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2019-11-06 16:06:58 +01:00
|
|
|
// Produce fully expanded flags for use by C tools, C compiles, C++ tools, C++ compiles, and asm compiles
|
|
|
|
// respectively.
|
|
|
|
toolingCflags := flags.globalCommonFlags + " " +
|
|
|
|
flags.globalToolingCFlags + " " +
|
|
|
|
flags.globalConlyFlags + " " +
|
|
|
|
flags.localCommonFlags + " " +
|
|
|
|
flags.localToolingCFlags + " " +
|
|
|
|
flags.localConlyFlags + " " +
|
|
|
|
flags.systemIncludeFlags
|
|
|
|
|
|
|
|
cflags := flags.globalCommonFlags + " " +
|
|
|
|
flags.globalCFlags + " " +
|
|
|
|
flags.globalConlyFlags + " " +
|
|
|
|
flags.localCommonFlags + " " +
|
|
|
|
flags.localCFlags + " " +
|
|
|
|
flags.localConlyFlags + " " +
|
|
|
|
flags.systemIncludeFlags
|
|
|
|
|
|
|
|
toolingCppflags := flags.globalCommonFlags + " " +
|
|
|
|
flags.globalToolingCFlags + " " +
|
|
|
|
flags.globalToolingCppFlags + " " +
|
|
|
|
flags.localCommonFlags + " " +
|
|
|
|
flags.localToolingCFlags + " " +
|
|
|
|
flags.localToolingCppFlags + " " +
|
|
|
|
flags.systemIncludeFlags
|
|
|
|
|
|
|
|
cppflags := flags.globalCommonFlags + " " +
|
|
|
|
flags.globalCFlags + " " +
|
|
|
|
flags.globalCppFlags + " " +
|
|
|
|
flags.localCommonFlags + " " +
|
|
|
|
flags.localCFlags + " " +
|
|
|
|
flags.localCppFlags + " " +
|
|
|
|
flags.systemIncludeFlags
|
|
|
|
|
|
|
|
asflags := flags.globalCommonFlags + " " +
|
|
|
|
flags.globalAsFlags + " " +
|
|
|
|
flags.localCommonFlags + " " +
|
|
|
|
flags.localAsFlags + " " +
|
|
|
|
flags.systemIncludeFlags
|
2017-06-15 23:45:18 +02:00
|
|
|
|
2017-02-08 22:45:53 +01:00
|
|
|
var sAbiDumpFiles android.Paths
|
2018-10-08 05:54:34 +02:00
|
|
|
if flags.sAbiDump {
|
2017-02-08 22:45:53 +01:00
|
|
|
sAbiDumpFiles = make(android.Paths, 0, len(srcFiles))
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2021-07-15 03:45:05 +02:00
|
|
|
cflags += " ${config.NoOverrideGlobalCflags}"
|
|
|
|
toolingCflags += " ${config.NoOverrideGlobalCflags}"
|
|
|
|
cppflags += " ${config.NoOverrideGlobalCflags}"
|
|
|
|
toolingCppflags += " ${config.NoOverrideGlobalCflags}"
|
2016-03-04 02:21:04 +01:00
|
|
|
|
2021-09-10 08:20:39 +02:00
|
|
|
// Multiple source files have build rules usually share the same cFlags or tidyFlags.
|
|
|
|
// Define only one version in this module and share it in multiple build rules.
|
|
|
|
// To simplify the code, the shared variables are all named as $flags<nnn>.
|
|
|
|
numSharedFlags := 0
|
|
|
|
flagsMap := make(map[string]string)
|
|
|
|
|
|
|
|
// Share flags only when there are multiple files or tidy rules.
|
|
|
|
var hasMultipleRules = len(srcFiles) > 1 || flags.tidy
|
|
|
|
|
|
|
|
var shareFlags = func(kind string, flags string) string {
|
|
|
|
if !hasMultipleRules || len(flags) < 60 {
|
|
|
|
// Modules have long names and so do the module variables.
|
|
|
|
// It does not save space by replacing a short name with a long one.
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
mapKey := kind + flags
|
|
|
|
n, ok := flagsMap[mapKey]
|
|
|
|
if !ok {
|
|
|
|
numSharedFlags += 1
|
|
|
|
n = strconv.Itoa(numSharedFlags)
|
|
|
|
flagsMap[mapKey] = n
|
|
|
|
ctx.Variable(pctx, kind+n, flags)
|
|
|
|
}
|
|
|
|
return "$" + kind + n
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
for i, srcFile := range srcFiles {
|
2016-11-03 04:43:13 +01:00
|
|
|
objFile := android.ObjPathWithExt(ctx, subdir, srcFile, "o")
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
objFiles[i] = objFile
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Register compilation build statements. The actual rule used depends on the source file type.
|
2017-09-09 10:15:26 +02:00
|
|
|
switch srcFile.Ext() {
|
|
|
|
case ".asm":
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: yasm,
|
|
|
|
Description: "yasm " + srcFile.Rel(),
|
|
|
|
Output: objFile,
|
|
|
|
Input: srcFile,
|
2018-01-23 19:49:04 +01:00
|
|
|
Implicits: cFlagsDeps,
|
|
|
|
OrderOnly: pathDeps,
|
2016-12-03 02:13:24 +01:00
|
|
|
Args: map[string]string{
|
2021-09-10 08:20:39 +02:00
|
|
|
"asFlags": shareFlags("asFlags", flags.globalYasmFlags+" "+flags.localYasmFlags),
|
2016-12-03 02:13:24 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
continue
|
2019-08-16 21:14:32 +02:00
|
|
|
case ".o":
|
|
|
|
objFiles[i] = srcFile
|
|
|
|
continue
|
2016-12-03 02:13:24 +01:00
|
|
|
}
|
|
|
|
|
2019-11-06 16:06:58 +01:00
|
|
|
var moduleFlags string
|
|
|
|
var moduleToolingFlags string
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
var ccCmd string
|
2018-10-08 05:54:34 +02:00
|
|
|
tidy := flags.tidy
|
2020-04-21 21:40:27 +02:00
|
|
|
coverage := flags.gcovCoverage
|
2018-10-08 05:54:34 +02:00
|
|
|
dump := flags.sAbiDump
|
2019-01-04 08:25:11 +01:00
|
|
|
rule := cc
|
2018-11-06 01:49:08 +01:00
|
|
|
emitXref := flags.emitXrefs
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
switch srcFile.Ext() {
|
2019-01-04 08:25:11 +01:00
|
|
|
case ".s":
|
2019-08-28 06:20:40 +02:00
|
|
|
if !flags.assemblerWithCpp {
|
|
|
|
rule = ccNoDeps
|
|
|
|
}
|
2019-01-04 08:25:11 +01:00
|
|
|
fallthrough
|
|
|
|
case ".S":
|
2018-10-08 05:54:34 +02:00
|
|
|
ccCmd = "clang"
|
2019-11-06 16:06:58 +01:00
|
|
|
moduleFlags = asflags
|
2016-09-27 00:45:04 +02:00
|
|
|
tidy = false
|
2017-02-10 01:16:31 +01:00
|
|
|
coverage = false
|
2017-02-08 22:45:53 +01:00
|
|
|
dump = false
|
2018-11-06 01:49:08 +01:00
|
|
|
emitXref = false
|
2015-01-31 02:27:36 +01:00
|
|
|
case ".c":
|
2018-10-08 05:54:34 +02:00
|
|
|
ccCmd = "clang"
|
2019-11-06 16:06:58 +01:00
|
|
|
moduleFlags = cflags
|
|
|
|
moduleToolingFlags = toolingCflags
|
2019-06-27 23:46:10 +02:00
|
|
|
case ".cpp", ".cc", ".cxx", ".mm":
|
2018-10-08 05:54:34 +02:00
|
|
|
ccCmd = "clang++"
|
2019-11-06 16:06:58 +01:00
|
|
|
moduleFlags = cppflags
|
|
|
|
moduleToolingFlags = toolingCppflags
|
2020-12-03 23:12:41 +01:00
|
|
|
case ".h", ".hpp":
|
|
|
|
ctx.PropertyErrorf("srcs", "Header file %s is not supported, instead use export_include_dirs or local_include_dirs.", srcFile)
|
|
|
|
continue
|
2015-01-31 02:27:36 +01:00
|
|
|
default:
|
2020-12-03 23:12:41 +01:00
|
|
|
ctx.PropertyErrorf("srcs", "File %s has unknown extension. Supported extensions: .s, .S, .c, .cpp, .cc, .cxx, .mm", srcFile)
|
2015-01-31 02:27:36 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-05-09 22:45:28 +02:00
|
|
|
ccDesc := ccCmd
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2018-10-08 05:54:34 +02:00
|
|
|
ccCmd = "${config.ClangBin}/" + ccCmd
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2017-02-10 01:16:31 +01: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 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2019-01-04 08:25:11 +01:00
|
|
|
Rule: rule,
|
2017-05-09 22:45:28 +02:00
|
|
|
Description: ccDesc + " " + srcFile.Rel(),
|
2017-02-10 01:16:31 +01:00
|
|
|
Output: objFile,
|
|
|
|
ImplicitOutputs: implicitOutputs,
|
|
|
|
Input: srcFile,
|
2018-01-23 19:49:04 +01:00
|
|
|
Implicits: cFlagsDeps,
|
|
|
|
OrderOnly: pathDeps,
|
2015-01-31 02:27:36 +01:00
|
|
|
Args: map[string]string{
|
2021-09-10 08:20:39 +02:00
|
|
|
"cFlags": shareFlags("cFlags", moduleFlags),
|
|
|
|
"ccCmd": ccCmd, // short and not shared
|
2015-01-31 02:27:36 +01:00
|
|
|
},
|
|
|
|
})
|
2016-09-27 00:45:04 +02:00
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Register post-process build statements (such as for tidy or kythe).
|
2018-11-06 01:49:08 +01:00
|
|
|
if emitXref {
|
|
|
|
kytheFile := android.ObjPathWithExt(ctx, subdir, srcFile, "kzip")
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: kytheExtract,
|
|
|
|
Description: "Xref C++ extractor " + srcFile.Rel(),
|
|
|
|
Output: kytheFile,
|
|
|
|
Input: srcFile,
|
|
|
|
Implicits: cFlagsDeps,
|
|
|
|
OrderOnly: pathDeps,
|
|
|
|
Args: map[string]string{
|
2021-09-10 08:20:39 +02:00
|
|
|
"cFlags": shareFlags("cFlags", moduleFlags),
|
2018-11-06 01:49:08 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
kytheFiles = append(kytheFiles, kytheFile)
|
|
|
|
}
|
|
|
|
|
2021-09-18 02:18:39 +02:00
|
|
|
// Even with tidy, some src file could be skipped by noTidySrcsMap.
|
|
|
|
if tidy && !noTidySrcsMap[srcFile] {
|
2016-11-03 04:43:13 +01:00
|
|
|
tidyFile := android.ObjPathWithExt(ctx, subdir, srcFile, "tidy")
|
2016-09-27 00:45:04 +02:00
|
|
|
tidyFiles = append(tidyFiles, tidyFile)
|
|
|
|
|
2020-06-18 18:17:51 +02:00
|
|
|
rule := clangTidy
|
2020-09-03 07:29:49 +02:00
|
|
|
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CLANG_TIDY") {
|
2020-06-18 18:17:51 +02:00
|
|
|
rule = clangTidyRE
|
|
|
|
}
|
|
|
|
|
Add tidy-soong, tidy-dir-path, module-tidy targets
* When WITH_TIDY=1, these targets allow quick check of C/C++
source code with clang-tidy, without building C/C++ binaries.
* For each module with tidy rules, add a module-tidy target, e.g.,
libart-tidy, libartd-tidy, bionic-benchmarks-tidy, libnativehelper-tidy, etc.
* Add a tidy-soong phony target that depends on all module-tidy targets.
* For each directory X/Y add a tidy-X-Y phony target that depends
on all *-tidy targets in X/Y and tidy-X-Y-Z for all X/Y/Z directories,
e.g., tidy-bionic, tidy-bionic-benchmarks, tidy-libnativehelper, etc.
* Only soong modules are collected for now.
Tidy rules in .mk files will be collected later.
* Some comment lines reformatted by gofmt.
Test: WITH_TIDY=1 make <some_module>-tidy tidy-<some_directory>
Test: WITH_TIDY=1 make tidy-soong
Bug: 199169329
Change-Id: I45aef3875f70288a8e070761e5f083dbbdfa6e94
2021-09-06 05:15:38 +02:00
|
|
|
ctx.TidyFile(tidyFile)
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2020-06-18 18:17:51 +02:00
|
|
|
Rule: rule,
|
2017-05-09 22:45:28 +02:00
|
|
|
Description: "clang-tidy " + srcFile.Rel(),
|
|
|
|
Output: tidyFile,
|
|
|
|
Input: srcFile,
|
Use ccCmd to generate clang-tidy dependent file
* After this change, make libtinyxml2-tidy should generate
correct out/.../libtinyxml2.tidy.d file.
Touching one of the dependent files, e.g., tinyxml2.h,
should invoke clang-tidy but not to recompile tinyxml2.o.
* Note that linking libraries still depend on .tidy targets,
so make libtinyxml2 will call clang-tidy, regnerate
tinyxml2.tidy.d, tinyxml2.tidy, tinyxml2.o.d, tinyxml2.o.
* A clang-tidy rule uses the same $cFlags for both clang and clang-tidy.
To share it and avoid over long command lines, we use modern shell
array variables and cannot use old bourne shell.
Bug: 199169329
Test: WITH_TIDY=1 make
Test: WITH_TIDY=1 make libtinyxml2-tidy | grep tinyxml2
Test: touch external/tinyxml2/tinyxml2.h; make libtinyxml2-tidy | grep tinyxml2
Change-Id: I6175add58d7313ee50c9308b78c9290a60770052
2021-09-11 02:25:28 +02:00
|
|
|
Implicits: cFlagsDeps,
|
|
|
|
OrderOnly: pathDeps,
|
2016-09-27 00:45:04 +02:00
|
|
|
Args: map[string]string{
|
Use ccCmd to generate clang-tidy dependent file
* After this change, make libtinyxml2-tidy should generate
correct out/.../libtinyxml2.tidy.d file.
Touching one of the dependent files, e.g., tinyxml2.h,
should invoke clang-tidy but not to recompile tinyxml2.o.
* Note that linking libraries still depend on .tidy targets,
so make libtinyxml2 will call clang-tidy, regnerate
tinyxml2.tidy.d, tinyxml2.tidy, tinyxml2.o.d, tinyxml2.o.
* A clang-tidy rule uses the same $cFlags for both clang and clang-tidy.
To share it and avoid over long command lines, we use modern shell
array variables and cannot use old bourne shell.
Bug: 199169329
Test: WITH_TIDY=1 make
Test: WITH_TIDY=1 make libtinyxml2-tidy | grep tinyxml2
Test: touch external/tinyxml2/tinyxml2.h; make libtinyxml2-tidy | grep tinyxml2
Change-Id: I6175add58d7313ee50c9308b78c9290a60770052
2021-09-11 02:25:28 +02:00
|
|
|
"ccCmd": ccCmd,
|
|
|
|
"cFlags": shareFlags("cFlags", escapeSingleQuotes(moduleToolingFlags)),
|
|
|
|
"tidyFlags": shareFlags("tidyFlags", escapeSingleQuotes(config.TidyFlagsForSrcFile(srcFile, flags.tidyFlags))),
|
2021-09-10 08:20:39 +02:00
|
|
|
"tidyVars": tidyVars, // short and not shared
|
2016-09-27 00:45:04 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-08 22:45:53 +01:00
|
|
|
if dump {
|
|
|
|
sAbiDumpFile := android.ObjPathWithExt(ctx, subdir, srcFile, "sdump")
|
|
|
|
sAbiDumpFiles = append(sAbiDumpFiles, sAbiDumpFile)
|
|
|
|
|
2020-04-17 21:03:58 +02:00
|
|
|
dumpRule := sAbiDump
|
2020-09-03 07:29:49 +02:00
|
|
|
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_ABI_DUMPER") {
|
2020-04-17 21:03:58 +02:00
|
|
|
dumpRule = sAbiDumpRE
|
|
|
|
}
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2020-04-17 21:03:58 +02:00
|
|
|
Rule: dumpRule,
|
2017-05-09 22:45:28 +02:00
|
|
|
Description: "header-abi-dumper " + srcFile.Rel(),
|
|
|
|
Output: sAbiDumpFile,
|
|
|
|
Input: srcFile,
|
|
|
|
Implicit: objFile,
|
2019-08-09 21:45:53 +02:00
|
|
|
Implicits: cFlagsDeps,
|
|
|
|
OrderOnly: pathDeps,
|
2017-02-08 22:45:53 +01:00
|
|
|
Args: map[string]string{
|
2021-09-10 08:20:39 +02:00
|
|
|
"cFlags": shareFlags("cFlags", moduleToolingFlags),
|
|
|
|
"exportDirs": shareFlags("exportDirs", flags.sAbiFlags),
|
2017-02-08 22:45:53 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-09-27 02:33:01 +02:00
|
|
|
return Objects{
|
2017-02-10 01:16:31 +01:00
|
|
|
objFiles: objFiles,
|
|
|
|
tidyFiles: tidyFiles,
|
|
|
|
coverageFiles: coverageFiles,
|
2017-02-08 22:45:53 +01:00
|
|
|
sAbiDumpFiles: sAbiDumpFiles,
|
2018-11-06 01:49:08 +01:00
|
|
|
kytheFiles: kytheFiles,
|
2016-09-27 02:33:01 +02:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a rule for compiling multiple .o files to a static library (.a)
|
2020-11-23 23:02:44 +01:00
|
|
|
func transformObjToStaticLib(ctx android.ModuleContext,
|
2020-04-17 18:34:31 +02:00
|
|
|
objFiles android.Paths, wholeStaticLibs android.Paths,
|
2021-10-25 20:09:19 +02:00
|
|
|
flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths, validations android.WritablePaths) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2018-01-10 08:29:04 +01:00
|
|
|
arCmd := "${config.ClangBin}/llvm-ar"
|
2020-04-17 18:34:31 +02:00
|
|
|
arFlags := ""
|
2018-01-10 08:29:04 +01:00
|
|
|
if !ctx.Darwin() {
|
|
|
|
arFlags += " -format=gnu"
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2020-04-17 18:34:31 +02:00
|
|
|
if len(wholeStaticLibs) == 0 {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: ar,
|
|
|
|
Description: "static link " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: objFiles,
|
|
|
|
Implicits: deps,
|
2021-10-25 20:09:19 +02:00
|
|
|
Validations: validations.Paths(),
|
2020-04-17 18:34:31 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"arFlags": "crsPD" + arFlags,
|
|
|
|
"arCmd": arCmd,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: arWithLibs,
|
|
|
|
Description: "static link " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: append(objFiles, wholeStaticLibs...),
|
|
|
|
Implicits: deps,
|
|
|
|
Args: map[string]string{
|
|
|
|
"arCmd": arCmd,
|
|
|
|
"arObjFlags": "crsPD" + arFlags,
|
|
|
|
"arObjs": strings.Join(objFiles.Strings(), " "),
|
|
|
|
"arLibFlags": "cqsL" + arFlags,
|
|
|
|
"arLibs": strings.Join(wholeStaticLibs.Strings(), " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries,
|
2017-09-28 02:01:44 +02:00
|
|
|
// and shared libraries, to a shared library (.so) or dynamic executable
|
2020-11-23 23:02:44 +01:00
|
|
|
func transformObjToDynamicBinary(ctx android.ModuleContext,
|
2021-06-12 03:00:04 +02:00
|
|
|
objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps, crtBegin, crtEnd android.Paths,
|
|
|
|
groupLate bool, flags builderFlags, outputFile android.WritablePath,
|
|
|
|
implicitOutputs android.WritablePaths, validations android.WritablePaths) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2018-10-08 05:54:34 +02:00
|
|
|
ldCmd := "${config.ClangBin}/clang++"
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
var libFlagsList []string
|
|
|
|
|
2016-01-06 23:41:07 +01:00
|
|
|
if len(flags.libFlags) > 0 {
|
|
|
|
libFlagsList = append(libFlagsList, flags.libFlags)
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
if len(wholeStaticLibs) > 0 {
|
2015-11-25 02:53:15 +01:00
|
|
|
if ctx.Host() && ctx.Darwin() {
|
2016-05-19 00:37:25 +02:00
|
|
|
libFlagsList = append(libFlagsList, android.JoinWithPrefix(wholeStaticLibs.Strings(), "-force_load "))
|
2015-05-01 01:36:18 +02:00
|
|
|
} else {
|
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--whole-archive ")
|
2015-09-24 00:26:20 +02:00
|
|
|
libFlagsList = append(libFlagsList, wholeStaticLibs.Strings()...)
|
2015-05-01 01:36:18 +02:00
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--no-whole-archive ")
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
libFlagsList = append(libFlagsList, staticLibs.Strings()...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-07-19 00:54:54 +02:00
|
|
|
if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 {
|
2015-07-08 22:02:23 +02:00
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--start-group")
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
libFlagsList = append(libFlagsList, lateStaticLibs.Strings()...)
|
2016-07-19 00:54:54 +02:00
|
|
|
if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 {
|
2015-07-08 22:02:23 +02:00
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--end-group")
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
for _, lib := range sharedLibs {
|
2019-06-08 02:58:59 +02:00
|
|
|
libFile := lib.String()
|
|
|
|
if ctx.Windows() {
|
|
|
|
libFile = pathtools.ReplaceExtension(libFile, "lib")
|
|
|
|
}
|
|
|
|
libFlagsList = append(libFlagsList, libFile)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
deps = append(deps, staticLibs...)
|
2015-03-17 18:47:08 +01:00
|
|
|
deps = append(deps, lateStaticLibs...)
|
2015-01-31 02:27:36 +01:00
|
|
|
deps = append(deps, wholeStaticLibs...)
|
2021-06-12 03:00:04 +02:00
|
|
|
deps = append(deps, crtBegin...)
|
|
|
|
deps = append(deps, crtEnd...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2020-04-13 19:21:23 +02:00
|
|
|
rule := ld
|
2020-04-22 22:31:09 +02:00
|
|
|
args := map[string]string{
|
|
|
|
"ldCmd": ldCmd,
|
2021-06-12 03:00:04 +02:00
|
|
|
"crtBegin": strings.Join(crtBegin.Strings(), " "),
|
2020-04-22 22:31:09 +02:00
|
|
|
"libFlags": strings.Join(libFlagsList, " "),
|
|
|
|
"extraLibFlags": flags.extraLibFlags,
|
|
|
|
"ldFlags": flags.globalLdFlags + " " + flags.localLdFlags,
|
2021-06-12 03:00:04 +02:00
|
|
|
"crtEnd": strings.Join(crtEnd.Strings(), " "),
|
2020-04-22 22:31:09 +02:00
|
|
|
}
|
2020-09-03 07:29:49 +02:00
|
|
|
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CXX_LINKS") {
|
2020-04-13 19:21:23 +02:00
|
|
|
rule = ldRE
|
2020-04-22 22:31:09 +02:00
|
|
|
args["implicitOutputs"] = strings.Join(implicitOutputs.Strings(), ",")
|
2020-08-28 20:21:55 +02:00
|
|
|
args["implicitInputs"] = strings.Join(deps.Strings(), ",")
|
2020-04-13 19:21:23 +02:00
|
|
|
}
|
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2020-04-13 19:21:23 +02:00
|
|
|
Rule: rule,
|
2019-06-08 02:58:59 +02:00
|
|
|
Description: "link " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
ImplicitOutputs: implicitOutputs,
|
|
|
|
Inputs: objFiles,
|
|
|
|
Implicits: deps,
|
2021-05-14 02:45:36 +02:00
|
|
|
OrderOnly: sharedLibs,
|
2021-06-12 00:22:41 +02:00
|
|
|
Validations: validations.Paths(),
|
2020-04-22 22:31:09 +02:00
|
|
|
Args: args,
|
2015-01-31 02:27:36 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-08 22:45:53 +01:00
|
|
|
// Generate a rule to combine .dump sAbi dump files from multiple source files
|
|
|
|
// into a single .ldump sAbi dump file
|
2020-11-23 23:02:44 +01:00
|
|
|
func transformDumpToLinkedDump(ctx android.ModuleContext, sAbiDumps android.Paths, soFile android.Path,
|
2019-01-16 17:18:02 +01:00
|
|
|
baseName, exportedHeaderFlags string, symbolFile android.OptionalPath,
|
|
|
|
excludedSymbolVersions, excludedSymbolTags []string) android.OptionalPath {
|
|
|
|
|
2017-02-08 22:45:53 +01:00
|
|
|
outputFile := android.PathForModuleOut(ctx, baseName+".lsdump")
|
2019-01-16 17:18:02 +01:00
|
|
|
|
|
|
|
implicits := android.Paths{soFile}
|
2018-01-17 20:11:42 +01:00
|
|
|
symbolFilterStr := "-so " + soFile.String()
|
2019-01-16 17:18:02 +01:00
|
|
|
|
|
|
|
if symbolFile.Valid() {
|
|
|
|
implicits = append(implicits, symbolFile.Path())
|
|
|
|
symbolFilterStr += " -v " + symbolFile.String()
|
|
|
|
}
|
|
|
|
for _, ver := range excludedSymbolVersions {
|
|
|
|
symbolFilterStr += " --exclude-symbol-version " + ver
|
|
|
|
}
|
|
|
|
for _, tag := range excludedSymbolTags {
|
|
|
|
symbolFilterStr += " --exclude-symbol-tag " + tag
|
|
|
|
}
|
2020-05-07 12:56:47 +02:00
|
|
|
rule := sAbiLink
|
|
|
|
args := map[string]string{
|
|
|
|
"symbolFilter": symbolFilterStr,
|
|
|
|
"arch": ctx.Arch().ArchType.Name,
|
|
|
|
"exportedHeaderFlags": exportedHeaderFlags,
|
|
|
|
}
|
2020-09-03 07:29:49 +02:00
|
|
|
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_ABI_LINKER") {
|
2020-05-07 12:56:47 +02:00
|
|
|
rule = sAbiLinkRE
|
|
|
|
rbeImplicits := implicits.Strings()
|
|
|
|
for _, p := range strings.Split(exportedHeaderFlags, " ") {
|
|
|
|
if len(p) > 2 {
|
|
|
|
// Exclude the -I prefix.
|
|
|
|
rbeImplicits = append(rbeImplicits, p[2:])
|
|
|
|
}
|
|
|
|
}
|
2020-08-28 20:21:55 +02:00
|
|
|
args["implicitInputs"] = strings.Join(rbeImplicits, ",")
|
2020-05-07 12:56:47 +02:00
|
|
|
}
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2020-05-07 12:56:47 +02:00
|
|
|
Rule: rule,
|
2017-05-09 22:45:28 +02:00
|
|
|
Description: "header-abi-linker " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: sAbiDumps,
|
2019-01-16 17:18:02 +01:00
|
|
|
Implicits: implicits,
|
2020-05-07 12:56:47 +02:00
|
|
|
Args: args,
|
2017-02-08 22:45:53 +01:00
|
|
|
})
|
|
|
|
return android.OptionalPathForPath(outputFile)
|
|
|
|
}
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// unzipRefDump registers a build statement to unzip a reference abi dump.
|
|
|
|
func unzipRefDump(ctx android.ModuleContext, zippedRefDump android.Path, baseName string) android.Path {
|
2017-04-20 15:53:59 +02:00
|
|
|
outputFile := android.PathForModuleOut(ctx, baseName+"_ref.lsdump")
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-04-20 15:53:59 +02:00
|
|
|
Rule: unzipRefSAbiDump,
|
|
|
|
Description: "gunzip" + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: zippedRefDump,
|
|
|
|
})
|
|
|
|
return outputFile
|
|
|
|
}
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// sourceAbiDiff registers a build statement to compare linked sAbi dump files (.ldump).
|
|
|
|
func sourceAbiDiff(ctx android.ModuleContext, inputDump android.Path, referenceDump android.Path,
|
2019-10-02 00:58:07 +02:00
|
|
|
baseName, exportedHeaderFlags string, checkAllApis, isLlndk, isNdk, isVndkExt bool) android.OptionalPath {
|
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 11:04:35 +01:00
|
|
|
|
2017-02-08 22:45:53 +01:00
|
|
|
outputFile := android.PathForModuleOut(ctx, baseName+".abidiff")
|
2018-06-01 00:42:26 +02:00
|
|
|
libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
|
2019-02-18 06:12:21 +01:00
|
|
|
createReferenceDumpFlags := ""
|
|
|
|
|
2019-10-02 00:58:07 +02:00
|
|
|
var extraFlags []string
|
|
|
|
if checkAllApis {
|
|
|
|
extraFlags = append(extraFlags, "-check-all-apis")
|
|
|
|
} else {
|
|
|
|
extraFlags = append(extraFlags,
|
|
|
|
"-allow-unreferenced-changes",
|
|
|
|
"-allow-unreferenced-elf-symbol-changes")
|
|
|
|
}
|
|
|
|
|
2018-01-17 22:13:33 +01:00
|
|
|
if exportedHeaderFlags == "" {
|
2019-10-02 00:58:07 +02:00
|
|
|
extraFlags = append(extraFlags, "-advice-only")
|
2018-01-17 22:13:33 +01:00
|
|
|
}
|
2019-10-02 00:58:07 +02:00
|
|
|
|
2019-02-18 08:40:42 +01:00
|
|
|
if isLlndk || isNdk {
|
2019-02-18 06:12:21 +01:00
|
|
|
createReferenceDumpFlags = "--llndk"
|
2019-02-18 08:40:42 +01:00
|
|
|
if isLlndk {
|
|
|
|
// TODO(b/130324828): "-consider-opaque-types-different" should apply to
|
|
|
|
// both LLNDK and NDK shared libs. However, a known issue in header-abi-diff
|
|
|
|
// breaks libaaudio. Remove the if-guard after the issue is fixed.
|
2019-10-02 00:58:07 +02:00
|
|
|
extraFlags = append(extraFlags, "-consider-opaque-types-different")
|
2019-02-18 08:40:42 +01:00
|
|
|
}
|
2018-06-01 00:42:26 +02:00
|
|
|
}
|
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 11:04:35 +01:00
|
|
|
if isVndkExt {
|
2019-10-02 00:58:07 +02:00
|
|
|
extraFlags = append(extraFlags, "-allow-extensions")
|
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 11:04:35 +01:00
|
|
|
}
|
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: sAbiDiff,
|
|
|
|
Description: "header-abi-diff " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputDump,
|
|
|
|
Implicit: referenceDump,
|
2017-02-08 22:45:53 +01:00
|
|
|
Args: map[string]string{
|
2019-02-18 06:12:21 +01:00
|
|
|
"referenceDump": referenceDump.String(),
|
|
|
|
"libName": libName,
|
|
|
|
"arch": ctx.Arch().ArchType.Name,
|
2019-10-02 00:58:07 +02:00
|
|
|
"extraFlags": strings.Join(extraFlags, " "),
|
2019-02-18 06:12:21 +01:00
|
|
|
"createReferenceDumpFlags": createReferenceDumpFlags,
|
2017-02-08 22:45:53 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
return android.OptionalPathForPath(outputFile)
|
|
|
|
}
|
|
|
|
|
2017-09-28 02:01:44 +02:00
|
|
|
// Generate a rule for extracting a table of contents from a shared library (.so)
|
2021-11-03 20:30:18 +01:00
|
|
|
func TransformSharedObjectToToc(ctx android.ModuleContext, inputFile android.Path, outputFile android.WritablePath) {
|
2016-10-01 02:10:16 +02:00
|
|
|
|
2018-09-11 01:50:05 +02:00
|
|
|
var format string
|
|
|
|
if ctx.Darwin() {
|
|
|
|
format = "--macho"
|
|
|
|
} else if ctx.Windows() {
|
|
|
|
format = "--pe"
|
|
|
|
} else {
|
|
|
|
format = "--elf"
|
|
|
|
}
|
2016-10-01 02:10:16 +02:00
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: toc,
|
|
|
|
Description: "generate toc " + inputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputFile,
|
2016-10-01 02:10:16 +02:00
|
|
|
Args: map[string]string{
|
2021-04-01 11:45:42 +02:00
|
|
|
"clangBin": "${config.ClangBin}",
|
|
|
|
"format": format,
|
2016-10-01 02:10:16 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// Generate a rule for compiling multiple .o files to a .o using ld partial linking
|
2020-11-23 23:02:44 +01:00
|
|
|
func transformObjsToObj(ctx android.ModuleContext, objFiles android.Paths,
|
2019-09-19 19:50:18 +02:00
|
|
|
flags builderFlags, outputFile android.WritablePath, deps android.Paths) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2018-10-08 05:54:34 +02:00
|
|
|
ldCmd := "${config.ClangBin}/clang++"
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2020-04-13 19:21:23 +02:00
|
|
|
rule := partialLd
|
|
|
|
args := map[string]string{
|
|
|
|
"ldCmd": ldCmd,
|
|
|
|
"ldFlags": flags.globalLdFlags + " " + flags.localLdFlags,
|
|
|
|
}
|
2020-09-03 07:29:49 +02:00
|
|
|
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CXX_LINKS") {
|
2020-04-13 19:21:23 +02:00
|
|
|
rule = partialLdRE
|
|
|
|
args["inCommaList"] = strings.Join(objFiles.Strings(), ",")
|
2020-08-28 20:21:55 +02:00
|
|
|
args["implicitInputs"] = strings.Join(deps.Strings(), ",")
|
2020-04-13 19:21:23 +02:00
|
|
|
}
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2020-04-13 19:21:23 +02:00
|
|
|
Rule: rule,
|
2017-05-09 22:45:28 +02:00
|
|
|
Description: "link " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: objFiles,
|
2019-09-19 19:50:18 +02:00
|
|
|
Implicits: deps,
|
2020-04-13 19:21:23 +02:00
|
|
|
Args: args,
|
2015-01-31 02:27:36 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Generate a rule for running objcopy --prefix-symbols on a binary
|
|
|
|
func transformBinaryPrefixSymbols(ctx android.ModuleContext, prefix string, inputFile android.Path,
|
2016-05-19 00:37:25 +02:00
|
|
|
flags builderFlags, outputFile android.WritablePath) {
|
2015-03-26 22:44:11 +01:00
|
|
|
|
2021-04-19 21:58:43 +02:00
|
|
|
objcopyCmd := "${config.ClangBin}/llvm-objcopy"
|
2015-03-26 22:44:11 +01:00
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: prefixSymbols,
|
|
|
|
Description: "prefix symbols " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputFile,
|
2015-03-26 22:44:11 +01:00
|
|
|
Args: map[string]string{
|
|
|
|
"objcopyCmd": objcopyCmd,
|
|
|
|
"prefix": prefix,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Registers a build statement to invoke `strip` (to discard symbols and data from object files).
|
|
|
|
func transformStrip(ctx android.ModuleContext, inputFile android.Path,
|
2020-08-19 14:53:01 +02:00
|
|
|
outputFile android.WritablePath, flags StripFlags) {
|
2016-04-28 23:50:03 +02:00
|
|
|
|
|
|
|
args := ""
|
2020-08-19 14:53:01 +02:00
|
|
|
if flags.StripAddGnuDebuglink {
|
2016-04-28 23:50:03 +02:00
|
|
|
args += " --add-gnu-debuglink"
|
|
|
|
}
|
2020-08-19 14:53:01 +02:00
|
|
|
if flags.StripKeepMiniDebugInfo {
|
2016-04-28 23:50:03 +02:00
|
|
|
args += " --keep-mini-debug-info"
|
|
|
|
}
|
2020-08-19 14:53:01 +02:00
|
|
|
if flags.StripKeepSymbols {
|
2016-04-28 23:50:03 +02:00
|
|
|
args += " --keep-symbols"
|
|
|
|
}
|
2020-08-19 14:53:01 +02:00
|
|
|
if flags.StripKeepSymbolsList != "" {
|
|
|
|
args += " -k" + flags.StripKeepSymbolsList
|
2019-03-30 04:05:14 +01:00
|
|
|
}
|
2020-08-19 14:53:01 +02:00
|
|
|
if flags.StripKeepSymbolsAndDebugFrame {
|
2019-05-18 01:39:54 +02:00
|
|
|
args += " --keep-symbols-and-debug-frame"
|
|
|
|
}
|
2016-04-28 23:50:03 +02:00
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: strip,
|
|
|
|
Description: "strip " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputFile,
|
2016-04-28 23:50:03 +02:00
|
|
|
Args: map[string]string{
|
2021-05-05 22:54:11 +02:00
|
|
|
"args": args,
|
2016-04-28 23:50:03 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Registers build statement to invoke `strip` on darwin architecture.
|
|
|
|
func transformDarwinStrip(ctx android.ModuleContext, inputFile android.Path,
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFile android.WritablePath) {
|
2016-05-04 00:10:29 +02:00
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: darwinStrip,
|
|
|
|
Description: "strip " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputFile,
|
2016-05-04 00:10:29 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Registers build statement to zip one or more coverage files.
|
|
|
|
func transformCoverageFilesToZip(ctx android.ModuleContext,
|
2019-04-24 23:22:25 +02:00
|
|
|
inputs Objects, baseName string) android.OptionalPath {
|
2017-02-10 01:16:31 +01:00
|
|
|
|
|
|
|
if len(inputs.coverageFiles) > 0 {
|
2019-04-24 23:22:25 +02:00
|
|
|
outputFile := android.PathForModuleOut(ctx, baseName+".zip")
|
2017-02-10 01:16:31 +01:00
|
|
|
|
2019-04-24 23:22:25 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: zip,
|
|
|
|
Description: "zip " + outputFile.Base(),
|
|
|
|
Inputs: inputs.coverageFiles,
|
|
|
|
Output: outputFile,
|
|
|
|
})
|
2017-02-10 01:16:31 +01:00
|
|
|
|
|
|
|
return android.OptionalPathForPath(outputFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
return android.OptionalPath{}
|
|
|
|
}
|
|
|
|
|
2020-11-23 23:02:44 +01:00
|
|
|
// Rule to repack an archive (.a) file with a subset of object files.
|
|
|
|
func transformArchiveRepack(ctx android.ModuleContext, inputFile android.Path,
|
2019-10-15 11:01:19 +02:00
|
|
|
outputFile android.WritablePath, objects []string) {
|
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: archiveRepack,
|
|
|
|
Description: "Repack archive " + outputFile.Base(),
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputFile,
|
|
|
|
Args: map[string]string{
|
|
|
|
"objects": strings.Join(objects, " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-18 20:56:02 +02:00
|
|
|
func mingwCmd(toolchain config.Toolchain, cmd string) string {
|
2015-01-31 02:27:36 +01:00
|
|
|
return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd)
|
|
|
|
}
|