From fc3b064c9a23081901c0b599ecd4a4b1baab5fc4 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 1 Sep 2022 11:02:15 -0700 Subject: [PATCH] Make toolchain more compose-y Remove many of the overridden methods from toolchainBase in favor of having smaller composable types. toolchainNoCrt, toolchain32Bit and toolchain64Bit now only provide a few methods and can be mixed in to any toolchain type. toolchainLinux, toolchainBionic, toolchainWindows and toolchainDarwin now embed toolchainBase to provide the default flags methods for when they don't override them. This avoids the need for disambiguation methods required when a type embeds two types that implement the same method. Test: cc_test.go Change-Id: I641da2a47aba597c517f693efedb65cf41273c82 --- cc/config/bionic.go | 7 +++++++ cc/config/darwin_host.go | 6 ++++++ cc/config/toolchain.go | 26 +++++++------------------- cc/config/x86_linux_host.go | 10 ++++++++++ cc/config/x86_windows_host.go | 2 ++ 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/cc/config/bionic.go b/cc/config/bionic.go index e87f5712b..a1e3851dc 100644 --- a/cc/config/bionic.go +++ b/cc/config/bionic.go @@ -15,6 +15,7 @@ package config type toolchainBionic struct { + toolchainBase } var ( @@ -29,6 +30,12 @@ func (toolchainBionic) Bionic() bool { return true } func (toolchainBionic) DefaultSharedLibraries() []string { return bionicDefaultSharedLibraries } +func (toolchainBionic) ShlibSuffix() string { return ".so" } + +func (toolchainBionic) ExecutableSuffix() string { return "" } + +func (toolchainBionic) AvailableLibraries() []string { return nil } + func (toolchainBionic) CrtBeginStaticBinary() []string { return bionicCrtBeginStaticBinary } func (toolchainBionic) CrtBeginSharedBinary() []string { return bionicCrtBeginSharedBinary } func (toolchainBionic) CrtBeginSharedLibrary() []string { return bionicCrtBeginSharedLibrary } diff --git a/cc/config/darwin_host.go b/cc/config/darwin_host.go index 5e3f7c7d6..01b1e635c 100644 --- a/cc/config/darwin_host.go +++ b/cc/config/darwin_host.go @@ -176,6 +176,8 @@ func getMacTools(ctx android.PathContext) *macPlatformTools { type toolchainDarwin struct { cFlags, ldFlags string toolchain64Bit + toolchainNoCrt + toolchainBase } type toolchainDarwinX86 struct { @@ -254,6 +256,10 @@ func (t *toolchainDarwin) ShlibSuffix() string { return ".dylib" } +func (t *toolchainDarwin) ExecutableSuffix() string { + return "" +} + func (t *toolchainDarwin) AvailableLibraries() []string { return darwinAvailableLibraries } diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go index 253bb06d2..d9eaf533f 100644 --- a/cc/config/toolchain.go +++ b/cc/config/toolchain.go @@ -140,14 +140,6 @@ func (toolchainBase) ToolchainLdflags() string { return "" } -func (toolchainBase) ShlibSuffix() string { - return ".so" -} - -func (toolchainBase) ExecutableSuffix() string { - return "" -} - func (toolchainBase) Asflags() string { return "" } @@ -160,16 +152,14 @@ func (toolchainBase) LibclangRuntimeLibraryArch() string { return "" } -func (toolchainBase) AvailableLibraries() []string { - return nil -} +type toolchainNoCrt struct{} -func (toolchainBase) CrtBeginStaticBinary() []string { return nil } -func (toolchainBase) CrtBeginSharedBinary() []string { return nil } -func (toolchainBase) CrtBeginSharedLibrary() []string { return nil } -func (toolchainBase) CrtEndStaticBinary() []string { return nil } -func (toolchainBase) CrtEndSharedBinary() []string { return nil } -func (toolchainBase) CrtEndSharedLibrary() []string { return nil } +func (toolchainNoCrt) CrtBeginStaticBinary() []string { return nil } +func (toolchainNoCrt) CrtBeginSharedBinary() []string { return nil } +func (toolchainNoCrt) CrtBeginSharedLibrary() []string { return nil } +func (toolchainNoCrt) CrtEndStaticBinary() []string { return nil } +func (toolchainNoCrt) CrtEndSharedBinary() []string { return nil } +func (toolchainNoCrt) CrtEndSharedLibrary() []string { return nil } func (toolchainBase) DefaultSharedLibraries() []string { return nil @@ -188,7 +178,6 @@ func (toolchainBase) Musl() bool { } type toolchain64Bit struct { - toolchainBase } func (toolchain64Bit) Is64Bit() bool { @@ -196,7 +185,6 @@ func (toolchain64Bit) Is64Bit() bool { } type toolchain32Bit struct { - toolchainBase } func (toolchain32Bit) Is64Bit() bool { diff --git a/cc/config/x86_linux_host.go b/cc/config/x86_linux_host.go index 4e8fd7752..1b126dea1 100644 --- a/cc/config/x86_linux_host.go +++ b/cc/config/x86_linux_host.go @@ -158,6 +158,7 @@ func init() { } type toolchainLinux struct { + toolchainBase cFlags, ldFlags string } @@ -247,9 +248,18 @@ func (t *toolchainLinux) AvailableLibraries() []string { return linuxAvailableLibraries } +func (toolchainLinux) ShlibSuffix() string { + return ".so" +} + +func (toolchainLinux) ExecutableSuffix() string { + return "" +} + // glibc specialization of the linux toolchain type toolchainGlibc struct { + toolchainNoCrt } func (toolchainGlibc) Glibc() bool { return true } diff --git a/cc/config/x86_windows_host.go b/cc/config/x86_windows_host.go index 2c8321100..a33606f99 100644 --- a/cc/config/x86_windows_host.go +++ b/cc/config/x86_windows_host.go @@ -153,6 +153,8 @@ func init() { type toolchainWindows struct { cFlags, ldFlags string + toolchainBase + toolchainNoCrt } type toolchainWindowsX86 struct {