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.
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
package config
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
import (
|
2015-03-18 20:28:32 +01:00
|
|
|
"fmt"
|
2017-03-13 20:40:30 +01:00
|
|
|
"path/filepath"
|
2015-03-18 20:28:32 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
type toolchainFactory func(arch android.Arch) Toolchain
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
var toolchainFactories = make(map[android.OsType]map[android.ArchType]toolchainFactory)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
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
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
func FindToolchain(os android.OsType, arch android.Arch) Toolchain {
|
|
|
|
factory := toolchainFactories[os][arch.ArchType]
|
|
|
|
if factory == nil {
|
|
|
|
panic(fmt.Errorf("Toolchain not found for %s arch %q", os.String(), arch.String()))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return factory(arch)
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
type Toolchain interface {
|
2015-03-19 07:38:50 +01:00
|
|
|
Name() string
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
GccRoot() string
|
|
|
|
GccTriple() string
|
2015-12-07 21:30:44 +01:00
|
|
|
// GccVersion should return a real value, not a ninja reference
|
2015-03-19 07:38:50 +01:00
|
|
|
GccVersion() string
|
2017-03-13 20:40:30 +01:00
|
|
|
ToolPath() string
|
2015-12-07 21:30:44 +01:00
|
|
|
|
2015-11-24 01:11:30 +01:00
|
|
|
ToolchainCflags() string
|
|
|
|
ToolchainLdflags() string
|
2015-01-31 02:27:36 +01:00
|
|
|
Cflags() string
|
|
|
|
Cppflags() string
|
|
|
|
Ldflags() string
|
|
|
|
IncludeFlags() string
|
2015-03-18 20:28:32 +01:00
|
|
|
InstructionSetFlags(string) (string, error)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
ClangSupported() bool
|
2015-01-31 02:27:36 +01:00
|
|
|
ClangTriple() string
|
2015-11-24 01:11:30 +01:00
|
|
|
ToolchainClangCflags() string
|
2016-03-31 02:33:52 +02:00
|
|
|
ToolchainClangLdflags() string
|
2016-01-13 07:25:34 +01:00
|
|
|
ClangAsflags() string
|
2015-01-31 02:27:36 +01:00
|
|
|
ClangCflags() string
|
|
|
|
ClangCppflags() string
|
|
|
|
ClangLdflags() string
|
2018-04-03 20:33:34 +02:00
|
|
|
ClangLldflags() string
|
2015-11-03 23:27:00 +01:00
|
|
|
ClangInstructionSetFlags(string) (string, error)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2018-03-16 02:44:57 +01:00
|
|
|
ndkTriple() string
|
|
|
|
|
2016-12-03 02:13:24 +01:00
|
|
|
YasmFlags() string
|
|
|
|
|
2017-09-09 10:15:26 +02:00
|
|
|
WindresFlags() string
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
Is64Bit() bool
|
2015-11-25 02:53:15 +01:00
|
|
|
|
|
|
|
ShlibSuffix() string
|
|
|
|
ExecutableSuffix() string
|
2016-03-09 19:30:22 +01:00
|
|
|
|
2016-08-15 23:18:24 +02:00
|
|
|
SanitizerRuntimeLibraryArch() string
|
2016-05-25 23:47:21 +02:00
|
|
|
|
|
|
|
AvailableLibraries() []string
|
2016-11-17 10:02:25 +01:00
|
|
|
|
|
|
|
Bionic() bool
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 20:28:32 +01:00
|
|
|
type toolchainBase struct {
|
|
|
|
}
|
|
|
|
|
2018-03-16 02:44:57 +01:00
|
|
|
func (t *toolchainBase) ndkTriple() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func NDKTriple(toolchain Toolchain) string {
|
|
|
|
triple := toolchain.ndkTriple()
|
|
|
|
if triple == "" {
|
|
|
|
// Use the clang triple if there is no explicit NDK triple
|
|
|
|
triple = toolchain.ClangTriple()
|
|
|
|
}
|
|
|
|
return triple
|
|
|
|
}
|
|
|
|
|
2015-03-18 20:28:32 +01:00
|
|
|
func (toolchainBase) InstructionSetFlags(s string) (string, error) {
|
|
|
|
if s != "" {
|
|
|
|
return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s)
|
|
|
|
}
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
2015-11-03 23:27:00 +01:00
|
|
|
func (toolchainBase) ClangInstructionSetFlags(s string) (string, error) {
|
|
|
|
if s != "" {
|
|
|
|
return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s)
|
|
|
|
}
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
2015-11-24 01:11:30 +01:00
|
|
|
func (toolchainBase) ToolchainCflags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (toolchainBase) ToolchainLdflags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (toolchainBase) ToolchainClangCflags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-03-31 02:33:52 +02:00
|
|
|
func (toolchainBase) ToolchainClangLdflags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
func (toolchainBase) ClangSupported() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (toolchainBase) ShlibSuffix() string {
|
|
|
|
return ".so"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (toolchainBase) ExecutableSuffix() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-01-13 07:25:34 +01:00
|
|
|
func (toolchainBase) ClangAsflags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-12-03 02:13:24 +01:00
|
|
|
func (toolchainBase) YasmFlags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-09-09 10:15:26 +02:00
|
|
|
func (toolchainBase) WindresFlags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-08-15 23:18:24 +02:00
|
|
|
func (toolchainBase) SanitizerRuntimeLibraryArch() string {
|
2016-01-06 23:41:07 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:47:21 +02:00
|
|
|
func (toolchainBase) AvailableLibraries() []string {
|
|
|
|
return []string{}
|
|
|
|
}
|
|
|
|
|
2016-11-17 10:02:25 +01:00
|
|
|
func (toolchainBase) Bionic() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-03-13 20:40:30 +01:00
|
|
|
func (t toolchainBase) ToolPath() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
type toolchain64Bit struct {
|
2015-03-18 20:28:32 +01:00
|
|
|
toolchainBase
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (toolchain64Bit) Is64Bit() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
type toolchain32Bit struct {
|
2015-03-18 20:28:32 +01:00
|
|
|
toolchainBase
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (toolchain32Bit) Is64Bit() bool {
|
|
|
|
return false
|
|
|
|
}
|
2016-07-29 22:44:28 +02:00
|
|
|
|
|
|
|
func copyVariantFlags(m map[string][]string) map[string][]string {
|
|
|
|
ret := make(map[string][]string, len(m))
|
|
|
|
for k, v := range m {
|
|
|
|
l := make([]string, len(m[k]))
|
|
|
|
for i := range m[k] {
|
|
|
|
l[i] = v[i]
|
|
|
|
}
|
|
|
|
ret[k] = l
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func variantOrDefault(variants map[string]string, choice string) string {
|
|
|
|
if ret, ok := variants[choice]; ok {
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
return variants[""]
|
|
|
|
}
|
|
|
|
|
|
|
|
func addPrefix(list []string, prefix string) []string {
|
|
|
|
for i := range list {
|
|
|
|
list[i] = prefix + list[i]
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
2017-03-27 20:00:38 +02:00
|
|
|
func SanitizerRuntimeLibrary(t Toolchain, sanitizer string) string {
|
2016-08-15 23:18:24 +02:00
|
|
|
arch := t.SanitizerRuntimeLibraryArch()
|
|
|
|
if arch == "" {
|
|
|
|
return ""
|
|
|
|
}
|
2017-05-08 22:44:11 +02:00
|
|
|
return "libclang_rt." + sanitizer + "-" + arch + "-android"
|
2017-03-27 20:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func AddressSanitizerRuntimeLibrary(t Toolchain) string {
|
|
|
|
return SanitizerRuntimeLibrary(t, "asan")
|
2016-08-15 23:18:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func UndefinedBehaviorSanitizerRuntimeLibrary(t Toolchain) string {
|
2017-03-27 20:00:38 +02:00
|
|
|
return SanitizerRuntimeLibrary(t, "ubsan_standalone")
|
|
|
|
}
|
|
|
|
|
2018-02-22 00:49:20 +01:00
|
|
|
func UndefinedBehaviorSanitizerMinimalRuntimeLibrary(t Toolchain) string {
|
|
|
|
return SanitizerRuntimeLibrary(t, "ubsan_minimal")
|
|
|
|
}
|
|
|
|
|
2017-03-27 20:00:38 +02:00
|
|
|
func ThreadSanitizerRuntimeLibrary(t Toolchain) string {
|
|
|
|
return SanitizerRuntimeLibrary(t, "tsan")
|
2016-08-15 23:18:24 +02:00
|
|
|
}
|
2017-03-13 20:40:30 +01:00
|
|
|
|
2017-10-05 01:47:29 +02:00
|
|
|
func ProfileRuntimeLibrary(t Toolchain) string {
|
|
|
|
return SanitizerRuntimeLibrary(t, "profile")
|
|
|
|
}
|
|
|
|
|
2017-03-13 20:40:30 +01:00
|
|
|
func ToolPath(t Toolchain) string {
|
|
|
|
if p := t.ToolPath(); p != "" {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
return filepath.Join(t.GccRoot(), t.GccTriple(), "bin")
|
|
|
|
}
|
2018-02-20 22:33:42 +01:00
|
|
|
|
|
|
|
var inList = android.InList
|