-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_samples.py
119 lines (108 loc) · 4.91 KB
/
generate_samples.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
#!/usr/bin/env python3
from libvgazer import Vgazer
from libvgazer.platform import GetTriplet
from libvgazer.platform import Platform
anyPlatform = Platform(arch="any", os="any", osVersion="any", abi="any")
def AddHostInstallEntries(gazer, installList, hostPlatformsList, software,
projects):
for hostPlatform in hostPlatformsList:
if gazer.ChooseProject(projects, hostPlatform) is not None:
installList.append([software, hostPlatform, anyPlatform])
def AddTargetInstallEntries(gazer, installList, hostPlatformsList,
targetPlatformsList, software, projects):
for hostPlatform in hostPlatformsList:
for targetPlatform in targetPlatformsList:
if gazer.ChooseProject(projects, targetPlatform) is not None:
installList.append([software, hostPlatform, targetPlatform])
targetPlatform = hostPlatform
if gazer.ChooseProject(projects, targetPlatform) is not None:
installList.append([software, hostPlatform, targetPlatform])
def CreateInstallList(gazer, hostPlatformsList, targetPlatformsList):
installList = []
softwareData = gazer.GetSoftwareData().GetData().items()
for software, data in sorted(softwareData):
if data["platform"] == "host":
AddHostInstallEntries(gazer, installList, hostPlatformsList,
software, data["projects"])
else:
AddTargetInstallEntries(gazer, installList, hostPlatformsList,
targetPlatformsList, software, data["projects"])
return installList
def GenerateImageLaunchTarget(hostPlatform):
return ("image-{1}-{2}-{3}-launch:\n"
"\tdocker run --net=host -i -t \\\n"
" -v ~/.vgazer:/root/.vgazer -v `pwd`:/mnt/vgazer \\\n"
" --entrypoint {0} vgazer-deps:{1}-{2}-{3} \\\n"
"\n".format("/bin/bash", hostPlatform.GetArch(), hostPlatform.GetOs(),
hostPlatform.GetOsVersion()))
def GenerateInstallAndVersionTarget(installEntry):
software = installEntry[0]
hostPlatform = installEntry[1]
targetPlatform = installEntry[2]
if targetPlatform.PlatformsEqual(hostPlatform):
targetTriplet = GetTriplet(targetPlatform)
targetInstallString = software
targetArg = ""
elif targetPlatform == anyPlatform:
targetTriplet = "any-any-any"
targetInstallString = software
targetArg = ""
else:
targetTriplet = GetTriplet(targetPlatform)
targetInstallString = "{0}-{1}".format(software, targetTriplet)
targetArg = "--target={triplet}".format(triplet=targetTriplet)
return (
"sample-{harch}-{hos}-{hver}-version-{platform}:\n"
"\tdocker run --net=host -i -t \\\n"
" -v ~/.vgazer:/root/.vgazer \\\n"
" -v `pwd`:/mnt/vgazer \\\n"
" -v `pwd`/.vgazer-{triplet}:/mnt/vgazer_output \\\n"
" --entrypoint ./vgazer vgazer-deps:{harch}-{hos}-{hver} \\\n"
" version {targetArg} {software} | tee version.log\n"
"\n"
"sample-{harch}-{hos}-{hver}-install-{platform}:\n"
"\tdocker run --net=host -i -t \\\n"
" -v ~/.vgazer:/root/.vgazer \\\n"
" -v `pwd`:/mnt/vgazer \\\n"
" -v `pwd`/.vgazer-{triplet}:/mnt/vgazer_output \\\n"
" --entrypoint ./vgazer vgazer-deps:{harch}-{hos}-{hver} \\\n"
" install {targetArg} {software} | tee install.log\n"
"\n".format(
harch=hostPlatform.GetArch(),
hos=hostPlatform.GetOs(),
hver=hostPlatform.GetOsVersion(),
platform=targetInstallString,
software=software,
triplet=targetTriplet,
targetArg=targetArg
)
)
def GenerateSampleTargets(gazer, hostPlatformsList, targetPlatformsList,
installList):
with open("./sample_targets.mk", "w") as sampleTargetsFile:
for hostPlatform in hostPlatformsList:
imageLaunchTarget = GenerateImageLaunchTarget(hostPlatform)
sampleTargetsFile.write(imageLaunchTarget)
for installEntry in installList:
installTarget = GenerateInstallAndVersionTarget(installEntry)
sampleTargetsFile.write(installTarget)
def main():
gazer = Vgazer(supportOnly=True)
hostPlatformsList = [
Platform(arch=gazer.GetHostPlatform().GetArch(), os="amazonlinux",
osVersion="2", abi="gnu", suppressGenericFallback=True),
Platform(arch=gazer.GetHostPlatform().GetArch(), os="fedora",
osVersion="40", abi="gnu", suppressGenericFallback=True),
Platform(arch=gazer.GetHostPlatform().GetArch(), os="fedora",
osVersion="41", abi="gnu", suppressGenericFallback=True),
]
targetPlatformsList = [
Platform(arch="x86_64", os="linux", osVersion="any", abi="gnu"),
Platform(arch="x86_64", os="windows", osVersion="any", abi="mingw32"),
]
installList = CreateInstallList(gazer, hostPlatformsList,
targetPlatformsList)
GenerateSampleTargets(gazer, hostPlatformsList, targetPlatformsList,
installList)
if __name__ == "__main__":
main()