/
backend.go
60 lines (53 loc) · 1.53 KB
/
backend.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// The backend package provides platform specific configuration for the generator.
// Based on the type of generator used, different paths will be required.
package backend
import (
"sync"
"github.com/ARM-software/bob-build/core/config"
"github.com/ARM-software/bob-build/core/toolchain"
"github.com/ARM-software/bob-build/internal/utils"
"github.com/google/blueprint"
)
// Backend platform singleton.
// Abstracts platform specific (AOSP, Ninja) parameters and stores toolchains.
type Platform interface {
BuildDir() string
SourceDir() string
BobScriptsDir() string
SourceOutputDir(blueprint.Module) string
SharedLibsDir(tgt toolchain.TgtType) string
StaticLibOutputDir(tgt toolchain.TgtType) string
BinaryOutputDir(tgt toolchain.TgtType) string
KernelModOutputDir() string
EscapeFlag(string) string
Init(*config.Properties)
GetToolchain(tgt toolchain.TgtType) toolchain.Toolchain
}
var platform Platform
var lock = &sync.Mutex{}
func Get() Platform {
if platform == nil {
lock.Lock()
defer lock.Unlock()
if platform == nil {
panic("The Backend Platform has not been configured, please call Setup() before use.")
}
}
return platform
}
func Setup(env *config.EnvironmentVariables, cfg *config.Properties) {
if platform == nil {
lock.Lock()
defer lock.Unlock()
if platform == nil {
switch {
case cfg.GetBool("builder_ninja"):
platform = NewLinuxPlatform(env, cfg)
case cfg.GetBool("builder_android_bp"):
platform = NewAndroidPlatform(env, cfg)
default:
utils.Die("Unknown builder backend")
}
}
}
}