Rename compiler, linker and installer methods to be unique
compiler, linker, and installer interfaces may be implemented by a single decorator object, rename their methods to be unique to avoid the same method being called multiple times. Test: out/soong/build.ninja unchanged Change-Id: I1608c41cd68f614ba99c11bb9fcc7936f618d9aa
This commit is contained in:
16
cc/binary.go
16
cc/binary.go
@@ -67,8 +67,8 @@ type binaryLinker struct {
|
||||
|
||||
var _ linker = (*binaryLinker)(nil)
|
||||
|
||||
func (binary *binaryLinker) props() []interface{} {
|
||||
return append(binary.baseLinker.props(),
|
||||
func (binary *binaryLinker) linkerProps() []interface{} {
|
||||
return append(binary.baseLinker.linkerProps(),
|
||||
&binary.Properties,
|
||||
&binary.stripper.StripProperties)
|
||||
|
||||
@@ -91,8 +91,8 @@ func (binary *binaryLinker) getStem(ctx BaseModuleContext) string {
|
||||
return stem + binary.Properties.Suffix
|
||||
}
|
||||
|
||||
func (binary *binaryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps = binary.baseLinker.deps(ctx, deps)
|
||||
func (binary *binaryLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps = binary.baseLinker.linkerDeps(ctx, deps)
|
||||
if ctx.Device() {
|
||||
if !Bool(binary.baseLinker.Properties.Nocrt) {
|
||||
if !ctx.sdk() {
|
||||
@@ -155,8 +155,8 @@ func NewBinary(hod android.HostOrDeviceSupported) *Module {
|
||||
return module
|
||||
}
|
||||
|
||||
func (binary *binaryLinker) begin(ctx BaseModuleContext) {
|
||||
binary.baseLinker.begin(ctx)
|
||||
func (binary *binaryLinker) linkerInit(ctx BaseModuleContext) {
|
||||
binary.baseLinker.linkerInit(ctx)
|
||||
|
||||
static := Bool(binary.Properties.Static_executable)
|
||||
if ctx.Host() {
|
||||
@@ -175,8 +175,8 @@ func (binary *binaryLinker) begin(ctx BaseModuleContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func (binary *binaryLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
flags = binary.baseLinker.flags(ctx, flags)
|
||||
func (binary *binaryLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
flags = binary.baseLinker.linkerFlags(ctx, flags)
|
||||
|
||||
if ctx.Host() && !binary.staticBinary() {
|
||||
flags.LdFlags = append(flags.LdFlags, "-pie")
|
||||
|
34
cc/cc.go
34
cc/cc.go
@@ -170,21 +170,29 @@ type feature interface {
|
||||
}
|
||||
|
||||
type compiler interface {
|
||||
feature
|
||||
compilerInit(ctx BaseModuleContext)
|
||||
compilerDeps(ctx BaseModuleContext, deps Deps) Deps
|
||||
compilerFlags(ctx ModuleContext, flags Flags) Flags
|
||||
compilerProps() []interface{}
|
||||
|
||||
appendCflags([]string)
|
||||
appendAsflags([]string)
|
||||
compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths
|
||||
}
|
||||
|
||||
type linker interface {
|
||||
feature
|
||||
linkerInit(ctx BaseModuleContext)
|
||||
linkerDeps(ctx BaseModuleContext, deps Deps) Deps
|
||||
linkerFlags(ctx ModuleContext, flags Flags) Flags
|
||||
linkerProps() []interface{}
|
||||
|
||||
link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles android.Paths) android.Path
|
||||
appendLdflags([]string)
|
||||
installable() bool
|
||||
}
|
||||
|
||||
type installer interface {
|
||||
props() []interface{}
|
||||
installerProps() []interface{}
|
||||
install(ctx ModuleContext, path android.Path)
|
||||
inData() bool
|
||||
}
|
||||
@@ -251,13 +259,13 @@ func (c *Module) Init() (blueprint.Module, []interface{}) {
|
||||
props = append(props, c.Customizer.Properties()...)
|
||||
}
|
||||
if c.compiler != nil {
|
||||
props = append(props, c.compiler.props()...)
|
||||
props = append(props, c.compiler.compilerProps()...)
|
||||
}
|
||||
if c.linker != nil {
|
||||
props = append(props, c.linker.props()...)
|
||||
props = append(props, c.linker.linkerProps()...)
|
||||
}
|
||||
if c.installer != nil {
|
||||
props = append(props, c.installer.props()...)
|
||||
props = append(props, c.installer.installerProps()...)
|
||||
}
|
||||
if c.stl != nil {
|
||||
props = append(props, c.stl.props()...)
|
||||
@@ -391,10 +399,10 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
||||
Clang: c.clang(ctx),
|
||||
}
|
||||
if c.compiler != nil {
|
||||
flags = c.compiler.flags(ctx, flags)
|
||||
flags = c.compiler.compilerFlags(ctx, flags)
|
||||
}
|
||||
if c.linker != nil {
|
||||
flags = c.linker.flags(ctx, flags)
|
||||
flags = c.linker.linkerFlags(ctx, flags)
|
||||
}
|
||||
if c.stl != nil {
|
||||
flags = c.stl.flags(ctx, flags)
|
||||
@@ -462,10 +470,10 @@ func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
|
||||
|
||||
func (c *Module) begin(ctx BaseModuleContext) {
|
||||
if c.compiler != nil {
|
||||
c.compiler.begin(ctx)
|
||||
c.compiler.compilerInit(ctx)
|
||||
}
|
||||
if c.linker != nil {
|
||||
c.linker.begin(ctx)
|
||||
c.linker.linkerInit(ctx)
|
||||
}
|
||||
if c.stl != nil {
|
||||
c.stl.begin(ctx)
|
||||
@@ -482,10 +490,10 @@ func (c *Module) deps(ctx BaseModuleContext) Deps {
|
||||
deps := Deps{}
|
||||
|
||||
if c.compiler != nil {
|
||||
deps = c.compiler.deps(ctx, deps)
|
||||
deps = c.compiler.compilerDeps(ctx, deps)
|
||||
}
|
||||
if c.linker != nil {
|
||||
deps = c.linker.deps(ctx, deps)
|
||||
deps = c.linker.linkerDeps(ctx, deps)
|
||||
}
|
||||
if c.stl != nil {
|
||||
deps = c.stl.deps(ctx, deps)
|
||||
@@ -850,7 +858,7 @@ type toolchainLibraryLinker struct {
|
||||
|
||||
var _ baseLinkerInterface = (*toolchainLibraryLinker)(nil)
|
||||
|
||||
func (*toolchainLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
func (*toolchainLibraryLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
// toolchain libraries can't have any dependencies
|
||||
return deps
|
||||
}
|
||||
|
@@ -103,13 +103,13 @@ func (compiler *baseCompiler) appendAsflags(flags []string) {
|
||||
compiler.Properties.Asflags = append(compiler.Properties.Asflags, flags...)
|
||||
}
|
||||
|
||||
func (compiler *baseCompiler) props() []interface{} {
|
||||
func (compiler *baseCompiler) compilerProps() []interface{} {
|
||||
return []interface{}{&compiler.Properties}
|
||||
}
|
||||
|
||||
func (compiler *baseCompiler) begin(ctx BaseModuleContext) {}
|
||||
func (compiler *baseCompiler) compilerInit(ctx BaseModuleContext) {}
|
||||
|
||||
func (compiler *baseCompiler) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
func (compiler *baseCompiler) compilerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...)
|
||||
deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...)
|
||||
|
||||
@@ -118,7 +118,7 @@ func (compiler *baseCompiler) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
|
||||
// Create a Flags struct that collects the compile flags from global values,
|
||||
// per-target values, module type values, and per-module Blueprints properties
|
||||
func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
tc := ctx.toolchain()
|
||||
|
||||
CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags)
|
||||
|
@@ -42,7 +42,7 @@ type baseInstaller struct {
|
||||
|
||||
var _ installer = (*baseInstaller)(nil)
|
||||
|
||||
func (installer *baseInstaller) props() []interface{} {
|
||||
func (installer *baseInstaller) installerProps() []interface{} {
|
||||
return []interface{}{&installer.Properties}
|
||||
}
|
||||
|
||||
|
@@ -149,13 +149,13 @@ type libraryCompiler struct {
|
||||
|
||||
var _ compiler = (*libraryCompiler)(nil)
|
||||
|
||||
func (library *libraryCompiler) props() []interface{} {
|
||||
props := library.baseCompiler.props()
|
||||
func (library *libraryCompiler) compilerProps() []interface{} {
|
||||
props := library.baseCompiler.compilerProps()
|
||||
return append(props, &library.Properties)
|
||||
}
|
||||
|
||||
func (library *libraryCompiler) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
flags = library.baseCompiler.flags(ctx, flags)
|
||||
func (library *libraryCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
flags = library.baseCompiler.compilerFlags(ctx, flags)
|
||||
|
||||
// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
|
||||
// all code is position independent, and then those warnings get promoted to
|
||||
@@ -227,8 +227,8 @@ type libraryInterface interface {
|
||||
objs() android.Paths
|
||||
}
|
||||
|
||||
func (library *libraryLinker) props() []interface{} {
|
||||
props := library.baseLinker.props()
|
||||
func (library *libraryLinker) linkerProps() []interface{} {
|
||||
props := library.baseLinker.linkerProps()
|
||||
return append(props,
|
||||
&library.Properties,
|
||||
&library.dynamicProperties,
|
||||
@@ -251,8 +251,8 @@ func (library *libraryLinker) getLibName(ctx ModuleContext) string {
|
||||
return name + library.Properties.VariantName
|
||||
}
|
||||
|
||||
func (library *libraryLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
flags = library.baseLinker.flags(ctx, flags)
|
||||
func (library *libraryLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
flags = library.baseLinker.linkerFlags(ctx, flags)
|
||||
|
||||
if !library.static() {
|
||||
libName := library.getLibName(ctx)
|
||||
@@ -288,8 +288,8 @@ func (library *libraryLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
return flags
|
||||
}
|
||||
|
||||
func (library *libraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps = library.baseLinker.deps(ctx, deps)
|
||||
func (library *libraryLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps = library.baseLinker.linkerDeps(ctx, deps)
|
||||
if library.static() {
|
||||
deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Static.Whole_static_libs...)
|
||||
deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...)
|
||||
|
@@ -82,7 +82,7 @@ func (linker *baseLinker) appendLdflags(flags []string) {
|
||||
linker.Properties.Ldflags = append(linker.Properties.Ldflags, flags...)
|
||||
}
|
||||
|
||||
func (linker *baseLinker) begin(ctx BaseModuleContext) {
|
||||
func (linker *baseLinker) linkerInit(ctx BaseModuleContext) {
|
||||
if ctx.toolchain().Is64Bit() {
|
||||
linker.dynamicProperties.RunPaths = []string{"../lib64", "lib64"}
|
||||
} else {
|
||||
@@ -90,11 +90,11 @@ func (linker *baseLinker) begin(ctx BaseModuleContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func (linker *baseLinker) props() []interface{} {
|
||||
func (linker *baseLinker) linkerProps() []interface{} {
|
||||
return []interface{}{&linker.Properties, &linker.dynamicProperties}
|
||||
}
|
||||
|
||||
func (linker *baseLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...)
|
||||
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...)
|
||||
deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs...)
|
||||
@@ -133,7 +133,7 @@ func (linker *baseLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
return deps
|
||||
}
|
||||
|
||||
func (linker *baseLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
toolchain := ctx.toolchain()
|
||||
|
||||
flags.Nocrt = Bool(linker.Properties.Nocrt)
|
||||
|
@@ -211,14 +211,14 @@ type stubLinker struct {
|
||||
libraryLinker
|
||||
}
|
||||
|
||||
func (linker *stubLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
func (linker *stubLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
return Deps{}
|
||||
}
|
||||
|
||||
func (linker *stubLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
func (linker *stubLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
linker.libraryLinker.libName = strings.TrimSuffix(ctx.ModuleName(),
|
||||
ndkLibrarySuffix)
|
||||
return linker.libraryLinker.flags(ctx, flags)
|
||||
return linker.libraryLinker.linkerFlags(ctx, flags)
|
||||
}
|
||||
|
||||
type stubInstaller struct {
|
||||
|
@@ -63,7 +63,7 @@ type ndkPrebuiltObjectLinker struct {
|
||||
objectLinker
|
||||
}
|
||||
|
||||
func (*ndkPrebuiltObjectLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
func (*ndkPrebuiltObjectLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
// NDK objects can't have any dependencies
|
||||
return deps
|
||||
}
|
||||
@@ -92,11 +92,11 @@ type ndkPrebuiltLibraryLinker struct {
|
||||
var _ baseLinkerInterface = (*ndkPrebuiltLibraryLinker)(nil)
|
||||
var _ exportedFlagsProducer = (*libraryLinker)(nil)
|
||||
|
||||
func (ndk *ndkPrebuiltLibraryLinker) props() []interface{} {
|
||||
return append(ndk.libraryLinker.props(), &ndk.Properties, &ndk.flagExporter.Properties)
|
||||
func (ndk *ndkPrebuiltLibraryLinker) linkerProps() []interface{} {
|
||||
return append(ndk.libraryLinker.linkerProps(), &ndk.Properties, &ndk.flagExporter.Properties)
|
||||
}
|
||||
|
||||
func (*ndkPrebuiltLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
func (*ndkPrebuiltLibraryLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
// NDK libraries can't have any dependencies
|
||||
return deps
|
||||
}
|
||||
|
@@ -46,18 +46,18 @@ func (object *objectLinker) appendLdflags(flags []string) {
|
||||
panic(fmt.Errorf("appendLdflags on object Linker not supported"))
|
||||
}
|
||||
|
||||
func (object *objectLinker) props() []interface{} {
|
||||
func (object *objectLinker) linkerProps() []interface{} {
|
||||
return []interface{}{&object.Properties}
|
||||
}
|
||||
|
||||
func (*objectLinker) begin(ctx BaseModuleContext) {}
|
||||
func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
|
||||
|
||||
func (object *objectLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
func (object *objectLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
|
||||
return deps
|
||||
}
|
||||
|
||||
func (*objectLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
if flags.Clang {
|
||||
flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags())
|
||||
} else {
|
||||
|
44
cc/test.go
44
cc/test.go
@@ -93,7 +93,7 @@ type testLinker struct {
|
||||
Properties TestLinkerProperties
|
||||
}
|
||||
|
||||
func (test *testLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
func (test *testLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
if !test.Properties.Gtest {
|
||||
return flags
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (test *testLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
return flags
|
||||
}
|
||||
|
||||
func (test *testLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
func (test *testLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
if test.Properties.Gtest {
|
||||
if ctx.sdk() && ctx.Device() {
|
||||
switch ctx.selectedStl() {
|
||||
@@ -142,8 +142,8 @@ type testBinaryLinker struct {
|
||||
binaryLinker
|
||||
}
|
||||
|
||||
func (test *testBinaryLinker) begin(ctx BaseModuleContext) {
|
||||
test.binaryLinker.begin(ctx)
|
||||
func (test *testBinaryLinker) linkerInit(ctx BaseModuleContext) {
|
||||
test.binaryLinker.linkerInit(ctx)
|
||||
runpath := "../../lib"
|
||||
if ctx.toolchain().Is64Bit() {
|
||||
runpath += "64"
|
||||
@@ -151,19 +151,19 @@ func (test *testBinaryLinker) begin(ctx BaseModuleContext) {
|
||||
test.dynamicProperties.RunPaths = append([]string{runpath}, test.dynamicProperties.RunPaths...)
|
||||
}
|
||||
|
||||
func (test *testBinaryLinker) props() []interface{} {
|
||||
return append(test.binaryLinker.props(), &test.testLinker.Properties)
|
||||
func (test *testBinaryLinker) linkerProps() []interface{} {
|
||||
return append(test.binaryLinker.linkerProps(), &test.testLinker.Properties)
|
||||
}
|
||||
|
||||
func (test *testBinaryLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
flags = test.binaryLinker.flags(ctx, flags)
|
||||
flags = test.testLinker.flags(ctx, flags)
|
||||
func (test *testBinaryLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
flags = test.binaryLinker.linkerFlags(ctx, flags)
|
||||
flags = test.testLinker.linkerFlags(ctx, flags)
|
||||
return flags
|
||||
}
|
||||
|
||||
func (test *testBinaryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps = test.testLinker.deps(ctx, deps)
|
||||
deps = test.binaryLinker.deps(ctx, deps)
|
||||
func (test *testBinaryLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps = test.testLinker.linkerDeps(ctx, deps)
|
||||
deps = test.binaryLinker.linkerDeps(ctx, deps)
|
||||
return deps
|
||||
}
|
||||
|
||||
@@ -172,19 +172,19 @@ type testLibraryLinker struct {
|
||||
*libraryLinker
|
||||
}
|
||||
|
||||
func (test *testLibraryLinker) props() []interface{} {
|
||||
return append(test.libraryLinker.props(), &test.testLinker.Properties)
|
||||
func (test *testLibraryLinker) linkerProps() []interface{} {
|
||||
return append(test.libraryLinker.linkerProps(), &test.testLinker.Properties)
|
||||
}
|
||||
|
||||
func (test *testLibraryLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
flags = test.libraryLinker.flags(ctx, flags)
|
||||
flags = test.testLinker.flags(ctx, flags)
|
||||
func (test *testLibraryLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
flags = test.libraryLinker.linkerFlags(ctx, flags)
|
||||
flags = test.testLinker.linkerFlags(ctx, flags)
|
||||
return flags
|
||||
}
|
||||
|
||||
func (test *testLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps = test.testLinker.deps(ctx, deps)
|
||||
deps = test.libraryLinker.deps(ctx, deps)
|
||||
func (test *testLibraryLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps = test.testLinker.linkerDeps(ctx, deps)
|
||||
deps = test.libraryLinker.linkerDeps(ctx, deps)
|
||||
return deps
|
||||
}
|
||||
|
||||
@@ -235,8 +235,8 @@ type benchmarkLinker struct {
|
||||
testBinaryLinker
|
||||
}
|
||||
|
||||
func (benchmark *benchmarkLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps = benchmark.testBinaryLinker.deps(ctx, deps)
|
||||
func (benchmark *benchmarkLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
deps = benchmark.testBinaryLinker.linkerDeps(ctx, deps)
|
||||
deps.StaticLibs = append(deps.StaticLibs, "libgoogle-benchmark")
|
||||
return deps
|
||||
}
|
||||
|
Reference in New Issue
Block a user