-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimsoc-prebuilt-deploy.py
executable file
·127 lines (104 loc) · 3.91 KB
/
optimsoc-prebuilt-deploy.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
#!/usr/bin/python
from optparse import OptionParser
import subprocess, os, sys
if sys.version_info.major == 3:
from urllib.request import urlretrieve
else:
from urllib import urlretrieve
prebuilts = {
"or1kelf": {
"name": "or1k-elf-multicore",
"tgz": "or1k-elf-multicore_gcc5.3.0_binutils2.26_newlib2.3.0-1_gdb7.11.tgz",
"url": "https://github.com/openrisc/newlib/releases/download/v2.3.0-1/",
"dest": "toolchains",
"env": [
{ "var": "PATH",
"type": "list-prepend",
"value": "{base}/bin" }
]
},
"verilator": {
"name": "verilator-3.902",
"tgz": "verilator-3.902.tgz",
"url": "https://github.com/optimsoc/prebuilts/releases/download/v2016.1/",
"dest": "prebuilt",
"relocate": "relocate.sh",
"env": [
{ "var": "VERILATOR_ROOT",
"value": "{base}" },
{ "var": "PATH",
"type": "list-prepend",
"value": "{base}/bin" },
{ "var": "PKG_CONFIG_PATH",
"type": "list-prepend",
"value": "{base}/share/pkgconfig" }
]
}
}
if __name__ == '__main__':
usage = "usage: %prog [options] <prebuilt list>"
epilog = "<prebuilt list> is either 'all' or a list of:"
for p in prebuilts:
epilog += " {}".format(p)
parser = OptionParser(usage=usage, epilog=epilog)
parser.add_option("-d", "--destination", dest="dest",
help="destination folder", default="/opt/optimsoc")
(options, args) = parser.parse_args()
options.dest = os.path.abspath(options.dest)
print("Installing OpTiMSoC prebuilts to {}".format(options.dest))
if "all" not in args:
for p in list(prebuilts):
if p not in args:
prebuilts.pop(p)
if len(prebuilts) == 0:
print("No prebuilts given.")
parser.print_help()
exit(0)
setup_sh = [ "# Auto-generated, do not change" ]
for key in prebuilts:
print("Install {}".format(key))
p = prebuilts[key]
print(" + Download")
tgz = p["tgz"]
url = "{}/{}".format(p["url"], tgz)
tmp = "/tmp/{}".format(tgz)
urlretrieve(url, tmp)
print(" + Extract")
out = os.path.join(options.dest, p["dest"])
try:
os.makedirs(out)
except OSError as e:
if e.errno != 17:
print("Cannot make output dir {}: {}", out, e)
tar_extra = ""
if "tar_extra" in p:
tar_extra = p["tar_extra"]
cmd = "tar -xzf {} {} -C {}".format(tmp, tar_extra, out)
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError as e:
print("tar error: {}\n{}".format(e, e.output))
exit(1)
if "relocate" in p:
cmd = "{}/{}/{}".format(out, p["name"], p["relocate"])
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError as e:
print("relocate error: {}\n{}".format(e, e.output))
exit(1)
base = "{}/{}".format(out, p["name"])
if "env" in p:
setup_sh.append("")
setup_sh.append("# {}".format(p["name"]))
for env in p["env"]:
value = env["value"].format(base=base)
if "type" in env:
if env["type"] == "list-prepend":
value = "{}:${}".format(value, env["var"])
line = "export {}={}".format(env["var"], value)
setup_sh.append(line)
envscript_file = os.path.join(options.dest, 'setup_prebuilt.sh')
print("Write "+envscript_file)
with open("{}/setup_prebuilt.sh".format(options.dest), "w") as envscript:
envscript.write("\n".join(setup_sh) + "\n")
print("Done")