diff options
author | Colin Cross <ccross@android.com> | 2016-06-03 01:50:47 +0000 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2016-06-03 01:50:47 +0000 |
commit | b9db480385745a9f42ea3f49a16877cb048960a9 (patch) | |
tree | 78705832794502be088258aaeda9efc9a2793188 /cc | |
parent | 54c7112c4325426eabda5fa96a8d3c4f61cb8cc7 (diff) | |
download | build_soong-b9db480385745a9f42ea3f49a16877cb048960a9.tar.gz build_soong-b9db480385745a9f42ea3f49a16877cb048960a9.tar.bz2 build_soong-b9db480385745a9f42ea3f49a16877cb048960a9.zip |
Revert "Simplify arch target handling"
This reverts commit 6713fb26cbcadf525cd75e47d7d0cbc23d282b3e.
Change-Id: Ic473cea2563b0b37dc08b0bc5d3a0ac8c4b6afe6
Diffstat (limited to 'cc')
-rw-r--r-- | cc/arm64_device.go | 2 | ||||
-rw-r--r-- | cc/arm_device.go | 2 | ||||
-rw-r--r-- | cc/cc.go | 39 | ||||
-rw-r--r-- | cc/makevars.go | 81 | ||||
-rw-r--r-- | cc/mips64_device.go | 2 | ||||
-rw-r--r-- | cc/mips_device.go | 2 | ||||
-rw-r--r-- | cc/stl.go | 18 | ||||
-rw-r--r-- | cc/toolchain.go | 22 | ||||
-rw-r--r-- | cc/x86_64_device.go | 2 | ||||
-rw-r--r-- | cc/x86_darwin_host.go | 4 | ||||
-rw-r--r-- | cc/x86_device.go | 2 | ||||
-rw-r--r-- | cc/x86_linux_host.go | 4 | ||||
-rw-r--r-- | cc/x86_windows_host.go | 4 |
13 files changed, 87 insertions, 97 deletions
diff --git a/cc/arm64_device.go b/cc/arm64_device.go index 8e7c57b0..4e412876 100644 --- a/cc/arm64_device.go +++ b/cc/arm64_device.go @@ -208,5 +208,5 @@ func arm64ToolchainFactory(arch android.Arch) Toolchain { } func init() { - registerToolchainFactory(android.Android, android.Arm64, arm64ToolchainFactory) + registerDeviceToolchainFactory(android.Arm64, arm64ToolchainFactory) } diff --git a/cc/arm_device.go b/cc/arm_device.go index 1624cfcc..766eea61 100644 --- a/cc/arm_device.go +++ b/cc/arm_device.go @@ -392,5 +392,5 @@ func armToolchainFactory(arch android.Arch) Toolchain { } func init() { - registerToolchainFactory(android.Android, android.Arm, armToolchainFactory) + registerDeviceToolchainFactory(android.Arm, armToolchainFactory) } @@ -118,7 +118,7 @@ var ( ) func init() { - if android.BuildOs == android.Linux { + if android.CurrentHostType() == android.Linux { commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=") } @@ -729,10 +729,11 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { func (c *Module) toolchain(ctx BaseModuleContext) Toolchain { if c.cachedToolchain == nil { arch := ctx.Arch() - os := ctx.Os() - factory := toolchainFactories[os][arch.ArchType] + hod := ctx.HostOrDevice() + ht := ctx.HostType() + factory := toolchainFactories[hod][ht][arch.ArchType] if factory == nil { - ctx.ModuleErrorf("Toolchain not found for %s arch %q", os.String(), arch.String()) + ctx.ModuleErrorf("Toolchain not found for %s %s arch %q", hod.String(), ht.String(), arch.String()) return nil } c.cachedToolchain = factory(arch) @@ -904,13 +905,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { return } - if a.Target().Os != ctx.Os() { - ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name) - return - } - - if a.Target().Arch.ArchType != ctx.Arch().ArchType { - ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name) + if a.HostOrDevice() != ctx.HostOrDevice() { + ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(), name) return } @@ -1085,11 +1081,6 @@ func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags { flags.LdFlags = append(flags.LdFlags, target, gccPrefix) } - hod := "host" - if ctx.Os().Class == android.Device { - hod = "device" - } - if !ctx.noDefaultCompilerFlags() { flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags) @@ -1099,7 +1090,7 @@ func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags { flags.GlobalFlags = append(flags.GlobalFlags, toolchain.ClangCflags(), "${commonClangGlobalCflags}", - fmt.Sprintf("${%sClangGlobalCflags}", hod)) + fmt.Sprintf("${%sClangGlobalCflags}", ctx.HostOrDevice())) flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}") } else { @@ -1107,7 +1098,7 @@ func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags { flags.GlobalFlags = append(flags.GlobalFlags, toolchain.Cflags(), "${commonGlobalCflags}", - fmt.Sprintf("${%sGlobalCflags}", hod)) + fmt.Sprintf("${%sGlobalCflags}", ctx.HostOrDevice())) } if Bool(ctx.AConfig().ProductVariables.Brillo) { @@ -1419,7 +1410,7 @@ func (library *libraryCompiler) flags(ctx ModuleContext, flags Flags) 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 // errors. - if ctx.Os() != android.Windows { + if ctx.HostType() != android.Windows { flags.CFlags = append(flags.CFlags, "-fPIC") } @@ -1872,7 +1863,7 @@ func (binary *binaryLinker) begin(ctx BaseModuleContext) { static := Bool(binary.Properties.Static_executable) if ctx.Host() { - if ctx.Os() == android.Linux { + if ctx.HostType() == android.Linux { if binary.Properties.Static_executable == nil && Bool(ctx.AConfig().ProductVariables.HostStaticBinaries) { static = true } @@ -1892,7 +1883,7 @@ func (binary *binaryLinker) flags(ctx ModuleContext, flags Flags) Flags { if ctx.Host() && !binary.staticBinary() { flags.LdFlags = append(flags.LdFlags, "-pie") - if ctx.Os() == android.Windows { + if ctx.HostType() == android.Windows { flags.LdFlags = append(flags.LdFlags, "-Wl,-e_mainCRTStartup") } } @@ -1900,7 +1891,7 @@ func (binary *binaryLinker) flags(ctx ModuleContext, flags Flags) 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 // errors. - if ctx.Os() != android.Windows { + if ctx.HostType() != android.Windows { flags.CFlags = append(flags.CFlags, "-fpie") } @@ -1954,7 +1945,7 @@ func (binary *binaryLinker) link(ctx ModuleContext, fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix() outputFile := android.PathForModuleOut(ctx, fileName) ret := outputFile - if ctx.Os().Class == android.Host { + if ctx.HostOrDevice().Host() { binary.hostToolPath = android.OptionalPathForPath(outputFile) } @@ -2061,7 +2052,7 @@ func (test *testLinker) flags(ctx ModuleContext, flags Flags) Flags { if ctx.Host() { flags.CFlags = append(flags.CFlags, "-O0", "-g") - switch ctx.Os() { + switch ctx.HostType() { case android.Windows: flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS") case android.Linux: diff --git a/cc/makevars.go b/cc/makevars.go index f107eff8..863e3dcc 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -41,54 +41,49 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.Strict("GLOBAL_CPPFLAGS_NO_OVERRIDE", "") ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "") - hostTargets := ctx.Config().Targets[android.Host] - makeVarsToolchain(ctx, "", hostTargets[0]) - if len(hostTargets) > 1 { - makeVarsToolchain(ctx, "2ND_", hostTargets[1]) + hostType := android.CurrentHostType() + arches := ctx.Config().HostArches[hostType] + makeVarsToolchain(ctx, "", android.Host, hostType, arches[0]) + if len(arches) > 1 { + makeVarsToolchain(ctx, "2ND_", android.Host, hostType, arches[1]) } - crossTargets := ctx.Config().Targets[android.HostCross] - if len(crossTargets) > 0 { - makeVarsToolchain(ctx, "", crossTargets[0]) - if len(crossTargets) > 1 { - makeVarsToolchain(ctx, "2ND_", crossTargets[1]) + if winArches, ok := ctx.Config().HostArches[android.Windows]; ok { + makeVarsToolchain(ctx, "", android.Host, android.Windows, winArches[0]) + if len(winArches) > 1 { + makeVarsToolchain(ctx, "2ND_", android.Host, android.Windows, winArches[1]) } } - deviceTargets := ctx.Config().Targets[android.Device] - makeVarsToolchain(ctx, "", deviceTargets[0]) - if len(deviceTargets) > 1 { - makeVarsToolchain(ctx, "2ND_", deviceTargets[1]) + arches = ctx.Config().DeviceArches + makeVarsToolchain(ctx, "", android.Device, android.NoHostType, arches[0]) + if len(arches) > 1 { + makeVarsToolchain(ctx, "2ND_", android.Device, android.NoHostType, arches[1]) } } func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, - target android.Target) { + hod android.HostOrDevice, ht android.HostType, arch android.Arch) { var typePrefix string - switch target.Os.Class { - case android.Host: - typePrefix = "HOST_" - case android.HostCross: - typePrefix = "HOST_CROSS_" - case android.Device: + if hod.Host() { + if ht == android.Windows { + typePrefix = "HOST_CROSS_" + } else { + typePrefix = "HOST_" + } + } else { typePrefix = "TARGET_" } makePrefix := secondPrefix + typePrefix - toolchain := toolchainFactories[target.Os][target.Arch.ArchType](target.Arch) + toolchain := toolchainFactories[hod][ht][arch.ArchType](arch) var productExtraCflags string var productExtraLdflags string - - hod := "host" - if target.Os.Class == android.Device { - hod = "device" - } - - if target.Os.Class == android.Device && Bool(ctx.Config().ProductVariables.Brillo) { + if hod.Device() && Bool(ctx.Config().ProductVariables.Brillo) { productExtraCflags += "-D__BRILLO__" } - if target.Os.Class == android.Host && Bool(ctx.Config().ProductVariables.HostStaticBinaries) { + if hod.Host() && Bool(ctx.Config().ProductVariables.HostStaticBinaries) { productExtraLdflags += "-static" } @@ -113,29 +108,23 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, ctx.Strict(makePrefix+"SYSTEMCPP_LDFLAGS", toolchain.SystemCppLdflags()) includeFlags, err := ctx.Eval(toolchain.IncludeFlags()) - if err != nil { - panic(err) - } + if err != nil { panic(err) } ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Replace(includeFlags, "-isystem ", "", -1)) - if target.Arch.ArchType == android.Arm { + if arch.ArchType == android.Arm { flags, err := toolchain.InstructionSetFlags("arm") - if err != nil { - panic(err) - } + if err != nil { panic(err) } ctx.Strict(makePrefix+"arm_CFLAGS", flags) flags, err = toolchain.InstructionSetFlags("thumb") - if err != nil { - panic(err) - } + if err != nil { panic(err) } ctx.Strict(makePrefix+"thumb_CFLAGS", flags) } if toolchain.ClangSupported() { clangPrefix := secondPrefix + "CLANG_" + typePrefix clangExtras := "-target " + toolchain.ClangTriple() - if target.Os != android.Darwin { + if ht != android.Darwin { clangExtras += " -B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin") } @@ -159,19 +148,19 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, clangExtras, }, " ")) - if target.Os.Class == android.Device { - ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(toolchain.AddressSanitizerRuntimeLibrary(), ".so")) + if hod.Device() { + ctx.Strict(secondPrefix + "ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(toolchain.AddressSanitizerRuntimeLibrary(), ".so")) } // This is used by external/gentoo/... - ctx.Strict("CLANG_CONFIG_"+target.Arch.ArchType.Name+"_"+typePrefix+"TRIPLE", + ctx.Strict("CLANG_CONFIG_" + arch.ArchType.Name + "_" + typePrefix + "TRIPLE", toolchain.ClangTriple()) } ctx.Strict(makePrefix+"CC", gccCmd(toolchain, "gcc")) ctx.Strict(makePrefix+"CXX", gccCmd(toolchain, "g++")) - if target.Os == android.Darwin { + if ht == android.Darwin { ctx.Strict(makePrefix+"AR", "${macArPath}") } else { ctx.Strict(makePrefix+"AR", gccCmd(toolchain, "ar")) @@ -179,11 +168,11 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm")) } - if target.Os == android.Windows { + if ht == android.Windows { ctx.Strict(makePrefix+"OBJDUMP", gccCmd(toolchain, "objdump")) } - if target.Os.Class == android.Device { + if hod.Device() { ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy")) ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld")) ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip")) diff --git a/cc/mips64_device.go b/cc/mips64_device.go index 474f284a..04e31a95 100644 --- a/cc/mips64_device.go +++ b/cc/mips64_device.go @@ -200,5 +200,5 @@ func mips64ToolchainFactory(arch android.Arch) Toolchain { } func init() { - registerToolchainFactory(android.Android, android.Mips64, mips64ToolchainFactory) + registerDeviceToolchainFactory(android.Mips64, mips64ToolchainFactory) } diff --git a/cc/mips_device.go b/cc/mips_device.go index f9dc5c68..0dbbbd7b 100644 --- a/cc/mips_device.go +++ b/cc/mips_device.go @@ -248,5 +248,5 @@ func mipsToolchainFactory(arch android.Arch) Toolchain { } func init() { - registerToolchainFactory(android.Android, android.Mips, mipsToolchainFactory) + registerDeviceToolchainFactory(android.Mips, mipsToolchainFactory) } @@ -52,7 +52,7 @@ func (stl *stl) begin(ctx BaseModuleContext) { ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", stl.Properties.Stl) return "" } - } else if ctx.Os() == android.Windows { + } else if ctx.HostType() == android.Windows { switch stl.Properties.Stl { case "libc++", "libc++_static", "libstdc++", "": // libc++ is not supported on mingw @@ -60,7 +60,7 @@ func (stl *stl) begin(ctx BaseModuleContext) { case "none": return "" default: - ctx.ModuleErrorf("stl: %q is not a supported STL for windows", stl.Properties.Stl) + ctx.ModuleErrorf("stl: %q is not a supported STL", stl.Properties.Stl) return "" } } else { @@ -133,9 +133,9 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs") flags.LdFlags = append(flags.LdFlags, "-lpthread", "-lm") if ctx.staticBinary() { - flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...) + flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.HostType()]...) } else { - flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.Os()]...) + flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.HostType()]...) } } else { if ctx.Arch().ArchType == android.Arm { @@ -167,9 +167,9 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { flags.CppFlags = append(flags.CppFlags, "-nostdinc++") flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs") if ctx.staticBinary() { - flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...) + flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.HostType()]...) } else { - flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.Os()]...) + flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.HostType()]...) } } default: @@ -179,10 +179,10 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { return flags } -var hostDynamicGccLibs, hostStaticGccLibs map[android.OsType][]string +var hostDynamicGccLibs, hostStaticGccLibs map[android.HostType][]string func init() { - hostDynamicGccLibs = map[android.OsType][]string{ + hostDynamicGccLibs = map[android.HostType][]string{ android.Linux: []string{"-lgcc_s", "-lgcc", "-lc", "-lgcc_s", "-lgcc"}, android.Darwin: []string{"-lc", "-lSystem"}, android.Windows: []string{"-lmsvcr110", "-lmingw32", "-lgcc", "-lmoldname", @@ -190,7 +190,7 @@ func init() { "-lkernel32", "-lmingw32", "-lgcc", "-lmoldname", "-lmingwex", "-lmsvcrt"}, } - hostStaticGccLibs = map[android.OsType][]string{ + hostStaticGccLibs = map[android.HostType][]string{ android.Linux: []string{"-Wl,--start-group", "-lgcc", "-lgcc_eh", "-lc", "-Wl,--end-group"}, android.Darwin: []string{"NO_STATIC_HOST_BINARIES_ON_DARWIN"}, android.Windows: []string{"NO_STATIC_HOST_BINARIES_ON_WINDOWS"}, diff --git a/cc/toolchain.go b/cc/toolchain.go index 87657ef5..efb79536 100644 --- a/cc/toolchain.go +++ b/cc/toolchain.go @@ -22,13 +22,23 @@ import ( type toolchainFactory func(arch android.Arch) Toolchain -var toolchainFactories = make(map[android.OsType]map[android.ArchType]toolchainFactory) +var toolchainFactories = map[android.HostOrDevice]map[android.HostType]map[android.ArchType]toolchainFactory{ + android.Host: map[android.HostType]map[android.ArchType]toolchainFactory{ + android.Linux: make(map[android.ArchType]toolchainFactory), + android.Darwin: make(map[android.ArchType]toolchainFactory), + android.Windows: make(map[android.ArchType]toolchainFactory), + }, + android.Device: map[android.HostType]map[android.ArchType]toolchainFactory{ + android.NoHostType: make(map[android.ArchType]toolchainFactory), + }, +} -func registerToolchainFactory(os android.OsType, arch android.ArchType, factory toolchainFactory) { - if toolchainFactories[os] == nil { - toolchainFactories[os] = make(map[android.ArchType]toolchainFactory) - } - toolchainFactories[os][arch] = factory +func registerDeviceToolchainFactory(arch android.ArchType, factory toolchainFactory) { + toolchainFactories[android.Device][android.NoHostType][arch] = factory +} + +func registerHostToolchainFactory(ht android.HostType, arch android.ArchType, factory toolchainFactory) { + toolchainFactories[android.Host][ht][arch] = factory } type Toolchain interface { diff --git a/cc/x86_64_device.go b/cc/x86_64_device.go index 986dc866..9a0d6632 100644 --- a/cc/x86_64_device.go +++ b/cc/x86_64_device.go @@ -263,5 +263,5 @@ func x86_64ToolchainFactory(arch android.Arch) Toolchain { } func init() { - registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory) + registerDeviceToolchainFactory(android.X86_64, x86_64ToolchainFactory) } diff --git a/cc/x86_darwin_host.go b/cc/x86_darwin_host.go index 987b1dd1..f3cf1c97 100644 --- a/cc/x86_darwin_host.go +++ b/cc/x86_darwin_host.go @@ -280,6 +280,6 @@ func darwinX8664ToolchainFactory(arch android.Arch) Toolchain { } func init() { - registerToolchainFactory(android.Darwin, android.X86, darwinX86ToolchainFactory) - registerToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory) + registerHostToolchainFactory(android.Darwin, android.X86, darwinX86ToolchainFactory) + registerHostToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory) } diff --git a/cc/x86_device.go b/cc/x86_device.go index f16e68b3..e47c6fb6 100644 --- a/cc/x86_device.go +++ b/cc/x86_device.go @@ -286,5 +286,5 @@ func x86ToolchainFactory(arch android.Arch) Toolchain { } func init() { - registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory) + registerDeviceToolchainFactory(android.X86, x86ToolchainFactory) } diff --git a/cc/x86_linux_host.go b/cc/x86_linux_host.go index b2d84625..a75de900 100644 --- a/cc/x86_linux_host.go +++ b/cc/x86_linux_host.go @@ -254,6 +254,6 @@ func linuxX8664ToolchainFactory(arch android.Arch) Toolchain { } func init() { - registerToolchainFactory(android.Linux, android.X86, linuxX86ToolchainFactory) - registerToolchainFactory(android.Linux, android.X86_64, linuxX8664ToolchainFactory) + registerHostToolchainFactory(android.Linux, android.X86, linuxX86ToolchainFactory) + registerHostToolchainFactory(android.Linux, android.X86_64, linuxX8664ToolchainFactory) } diff --git a/cc/x86_windows_host.go b/cc/x86_windows_host.go index cc0ef668..9f5cdc42 100644 --- a/cc/x86_windows_host.go +++ b/cc/x86_windows_host.go @@ -199,6 +199,6 @@ func windowsX8664ToolchainFactory(arch android.Arch) Toolchain { } func init() { - registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory) - registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory) + registerHostToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory) + registerHostToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory) } |