-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_profiles.py
executable file
·152 lines (116 loc) · 4.3 KB
/
render_profiles.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/env python3
from jinja2 import Environment, FileSystemLoader
from pathlib import Path
from typing import Any
"""
This script will render the profiles for the different platforms and compilers
that we support. It will also symlink the default profile to the one we want to
use by default.
The profiles are rendered from the templates in the jinja templates directory.
So if you want to change the profiles, you should change the templates instead.
"""
file_dir = Path(__file__).parent
# Path to templates
template_dir = file_dir / "templates"
# Path to profiles
profile_dir = file_dir / "profiles"
# Create the jinja2 environment
env = Environment(
loader=FileSystemLoader(template_dir), trim_blocks=True, lstrip_blocks=True
)
def render_template(template_name, **kwargs):
# Load the template
template = env.get_template(template_name)
# Render the template
return template.render(**kwargs)
def save_profile(profile, settings):
os = settings["os"]["name"].lower()
architecture = settings["architecture"]["name"].lower()
compiler = (
f"{settings['compiler']['name'].lower()}-{settings['compiler']['version']}"
)
build_type = settings["build_type"].lower()
file_name = f"{architecture}-{os}-{build_type}-{compiler}"
with open(profile_dir / file_name, "w") as f:
f.write(profile)
def render_and_save_profile(settings):
profile = (
render_template(
settings["os"]["name"].lower() + ".jinja",
**settings,
).rstrip()
+ "\n"
)
save_profile(profile, settings)
def main():
# Clean out the profiles directory
print("Cleaning out profiles directory")
for file in profile_dir.glob("*"):
file.unlink()
architectures = {
"x86_64": {"name": "x86_64", "conan_name": "x86_64", "apple_name": "x86_64"},
"aarch64": {"name": "aarch64", "conan_name": "armv8", "apple_name": "arm64"},
}
compilers = [
{"name": "gcc", "version": "11"},
{"name": "gcc", "version": "9"},
{"name": "clang", "version": "14"},
]
build_types = ["Debug", "RelWithDebInfo", "Release"]
# Create linux profiles
print("Creating linux profiles")
settings: dict[str, Any] = {
"os": {"name": "Linux", },
}
for architecture in architectures.values():
for compiler in compilers:
# Skip aarch64 clang, for now
if architecture["name"] == "aarch64" and compiler["name"] == "clang":
continue
for build_type in build_types:
settings["architecture"] = architecture
settings["compiler"] = compiler
settings["build_type"] = build_type
render_and_save_profile(settings)
# Create windows profiles
print("Creating windows profiles")
settings = {
"os": {"name": "Windows", },
"architecture": architectures["x86_64"],
"compiler": {"name": "msvc", "version": "192", "runtime": "dynamic"},
}
for build_type in build_types:
settings["build_type"] = build_type
render_and_save_profile(settings)
# Create android profiles
print("Creating android profiles")
settings = {
"os": {"name": "Android", },
"architecture": architectures["aarch64"],
"compiler": {"name": "clang", "version": "14"},
}
for build_type in build_types:
settings["build_type"] = build_type
render_and_save_profile(settings)
# Create macos profiles
print("Creating macos profiles")
settings = {
"os": {"name": "Macos", "version": "11.0"},
"architecture": architectures["x86_64"],
"compiler": {"name": "apple-clang", "version": "14"},
}
for build_type in build_types:
for architecture in architectures.values():
settings["build_type"] = build_type
settings["architecture"] = architecture
render_and_save_profile(settings)
# Set up the symlink for the default profile
print("Setting up default profile")
default_profile = profile_dir / "default"
if default_profile.exists():
default_profile.unlink()
# The default profile is the x86_64-linux-release-gcc-9 profile
default_profile.symlink_to("x86_64-linux-release-gcc-9")
print("Done!")
if __name__ == "__main__":
main()