forked from anatol/osquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.py
executable file
·132 lines (94 loc) · 3.4 KB
/
system.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import sys
import argparse
import platform
class Platform:
LINUX_X86_64 = "linux-x86_64"
MACOS_X86_64 = "macos-x86_64"
FREEBSD_X86_64 = "freebsd-x86_64"
WINDOWS_X86_64 = "windows-x86_64"
class BuildType:
RELEASE = "release"
DEBUG = "debug"
BCFG_BASE_PATH = "//tools"
PLATFORM_TOOLCHAIN = {
Platform.LINUX_X86_64: "ubuntu-18.04-clang",
Platform.MACOS_X86_64: None,
Platform.FREEBSD_X86_64: "freebsd-11.2-clang",
Platform.WINDOWS_X86_64: "vsToolchainFlags",
}
def generate_config_file_flag(bcfg):
return "--config-file\n" + bcfg if bcfg else ""
def generate_toolchain(build_platform, build_type):
toolchain = PLATFORM_TOOLCHAIN[build_platform]
if toolchain is not None:
bcfg = "{}/buckconfigs/{}/toolchain/{}.bcfg".format(
BCFG_BASE_PATH, build_platform, toolchain
)
else:
bcfg = None
return generate_config_file_flag(bcfg)
def generate_type(build_platform, build_type):
bcfg = "{}/buckconfigs/{}/type/{}.bcfg".format(
BCFG_BASE_PATH, build_platform, build_type
)
return generate_config_file_flag(bcfg)
def generate_platform_base(build_platform):
bcfg = "{}/buckconfigs/{}/base.bcfg".format(BCFG_BASE_PATH, build_platform)
return generate_config_file_flag(bcfg)
def generate_base():
bcfg = "{}/buckconfigs/base.bcfg".format(BCFG_BASE_PATH)
return generate_config_file_flag(bcfg)
# Buck does not allow this script to fail, so lets pass an invalid flag ---- to
# make buck fail and print a message inside --- || || ----. This is bad but at
# least we're printing something to the user.
def fail(message):
print("---- || {} || ----".format(message))
sys.exit(1)
def get_platform():
os = platform.system().lower()
arch = platform.machine().lower()
if os == "linux" and arch == "x86_64":
return Platform.LINUX_X86_64
elif os == "darwin" and arch == "x86_64":
return Platform.MACOS_X86_64
elif os == "freebsd" and arch == "x86_64":
return Platform.FREEBSD_X86_64
elif os == "windows" and arch == "x86_64":
return Platform.WINDOWS_X86_64
else:
fail("Unsupported platform {} {}".format(os, arch))
def get_build_type(build_type):
if build_type == "release":
return BuildType.RELEASE
elif build_type == "debug":
return BuildType.DEBUG
else:
fail("Unsupported build type {}".format(build_type))
class CustomArgumentParser(argparse.ArgumentParser):
def error(self, message):
fail(message)
if __name__ == "__main__":
parser = CustomArgumentParser(
description="Automatically set the proper config files for buck. This is selected based on the platform"
)
parser.add_argument(
"--flavors",
dest="flavors",
action="store",
type=str,
help="comma seperated list of flavors. Currently supported: release and debug",
choices=[BuildType.RELEASE, BuildType.DEBUG],
default=BuildType.RELEASE,
)
args = parser.parse_args()
build_platform = get_platform()
build_type = get_build_type(args.flavors)
configs = [
generate_toolchain(build_platform, build_type),
generate_type(build_platform, build_type),
generate_platform_base(build_platform),
generate_base(),
]
print("\n".join(configs))