-
Notifications
You must be signed in to change notification settings - Fork 17
/
buildtool.py
101 lines (85 loc) · 3.9 KB
/
buildtool.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
#!/usr/bin/env python3
#
#
import argparse
import os
import projectLoader
def main(configfile, outputdir=None):
project = projectLoader.load(configfile)
# file structure
if outputdir:
project["OUTPUT_PATH"] = outputdir
else:
project[
"OUTPUT_PATH"
] = f"Output/{project['jdata']['name'].replace(' ', '_').replace('/', '_')}"
project["GATEWARE_PATH"] = f"{project['OUTPUT_PATH']}/Gateware"
project["SOURCE_PATH"] = f"{project['GATEWARE_PATH']}"
project["PINS_PATH"] = f"{project['GATEWARE_PATH']}"
project["LINUXCNC_PATH"] = f"{project['OUTPUT_PATH']}/LinuxCNC"
os.system(f"mkdir -p {project['OUTPUT_PATH']}")
os.system(f"mkdir -p {project['SOURCE_PATH']}")
os.system(f"mkdir -p {project['PINS_PATH']}")
os.system(f"mkdir -p {project['LINUXCNC_PATH']}")
os.system(f"mkdir -p {project['LINUXCNC_PATH']}/Components/")
os.system(f"mkdir -p {project['LINUXCNC_PATH']}/ConfigSamples/rio")
os.system(f"mkdir -p {project['LINUXCNC_PATH']}/ConfigSamples/rio/subroutines")
os.system(f"mkdir -p {project['LINUXCNC_PATH']}/ConfigSamples/rio/m_codes")
os.system(
f"cp -a files/subroutines/* {project['LINUXCNC_PATH']}/ConfigSamples/rio/subroutines"
)
if project["verilog_defines"]:
verilog_defines = []
for key, value in project["verilog_defines"].items():
verilog_defines.append(f"`define {key} {value}")
verilog_defines.append("")
open(f"{project['SOURCE_PATH']}/defines.v", "w").write(
"\n".join(verilog_defines)
)
project["verilog_files"].append("defines.v")
if project["gateware_extrafiles"]:
for filename, content in project["gateware_extrafiles"].items():
open(f"{project['SOURCE_PATH']}/{filename}", "w").write(content)
for plugin in project["plugins"]:
if hasattr(project["plugins"][plugin], "ips"):
for ipv in project["plugins"][plugin].ips():
ipv_name = ipv.split("/")[-1]
if ipv.endswith((".v", ".sv")):
if ipv_name not in project["verilog_files"]:
project["verilog_files"].append(ipv_name)
ipv_path = f"plugins/{plugin}/{ipv}"
if not os.path.isfile(ipv_path):
ipv_path = f"generators/gateware/{ipv}"
os.system(f"cp -a {ipv_path} {project['SOURCE_PATH']}/{ipv_name}")
"""
if ipv.endswith(".v") and not ipv.startswith("PLL_"):
os.system(
f"which verilator >/dev/null && cd {project['SOURCE_PATH']} && verilator --lint-only {ipv}"
)
"""
if hasattr(project["plugins"][plugin], "components"):
for component in project["plugins"][plugin].components():
project["component_files"].append(component)
component_path = f"plugins/{plugin}/{component}"
if not os.path.isfile(component_path):
component_path = f"generators/firmware/{component}"
os.system(
f"cp -a {component_path} {project['LINUXCNC_PATH']}/Components/{component}"
)
print(f"generating files in {project['OUTPUT_PATH']}")
for generator in project["generators"]:
if generator != "documentation":
project["generators"][generator].generate(project)
for generator in project["generators"]:
if generator == "documentation":
project["generators"][generator].generate(project)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"configfile", help="json config file", type=str, nargs="?", default=None
)
parser.add_argument(
"outputdir", help="output directory", type=str, nargs="?", default=None
)
args = parser.parse_args()
main(args.configfile, args.outputdir)