Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc3b064c authored by Colin Cross's avatar Colin Cross
Browse files

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
parent 52d9b95f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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 }
+6 −0
Original line number Diff line number Diff line
@@ -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
}
+7 −19
Original line number Diff line number Diff line
@@ -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 {
+10 −0
Original line number Diff line number Diff line
@@ -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 }
+2 −0
Original line number Diff line number Diff line
@@ -153,6 +153,8 @@ func init() {

type toolchainWindows struct {
	cFlags, ldFlags string
	toolchainBase
	toolchainNoCrt
}

type toolchainWindowsX86 struct {