1 |
4 |
danv |
#!/usr/bin/env python3
|
2 |
|
|
###############################################################################
|
3 |
|
|
#
|
4 |
|
|
# Copyright (C) 2018
|
5 |
|
|
# ASTRON (Netherlands Institute for Radio Astronomy)
|
6 |
|
|
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
7 |
|
|
#
|
8 |
|
|
# This program is free software: you can redistribute it and/or modify
|
9 |
|
|
# it under the terms of the GNU General Public License as published by
|
10 |
|
|
# the Free Software Foundation, either version 3 of the License, or
|
11 |
|
|
# (at your option) any later version.
|
12 |
|
|
#
|
13 |
|
|
# This program is distributed in the hope that it will be useful,
|
14 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
# GNU General Public License for more details.
|
17 |
|
|
#
|
18 |
|
|
# You should have received a copy of the GNU General Public License
|
19 |
|
|
# along with this program. If not, see .
|
20 |
|
|
#
|
21 |
|
|
# $Id: generate_ip_libs.py 18842 2018-08-29 10:47:05Z overeem $
|
22 |
|
|
#
|
23 |
|
|
###############################################################################
|
24 |
|
|
|
25 |
|
|
import os
|
26 |
|
|
from os.path import expandvars, isfile, isdir
|
27 |
|
|
from argparse import ArgumentParser
|
28 |
|
|
from hdl_configfile import HdlBuildset, HdlTool
|
29 |
|
|
from configfile import ConfigFileException
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
def _do_basic_key_checking(cfgfile, indent=""):
|
33 |
|
|
# Check that all key references are solved
|
34 |
|
|
print("{}Checking references...".format(indent), end=' ')
|
35 |
|
|
all_refs_solved = cfgfile.resolve_key_references()
|
36 |
|
|
if all_refs_solved:
|
37 |
|
|
print("OK")
|
38 |
|
|
else:
|
39 |
|
|
print("\n{}ERROR: The following reference cannot be solved: {}".format(indent, cfgfile.unresolved_refs))
|
40 |
|
|
|
41 |
|
|
# Check that all key required keys contain values
|
42 |
|
|
print("{}Checking required keys...".format(indent), end=' ')
|
43 |
|
|
empty_keys = []
|
44 |
|
|
for key in cfgfile.required_keys:
|
45 |
|
|
if cfgfile.content[key] == "":
|
46 |
|
|
empty_keys.append(key)
|
47 |
|
|
if not empty_keys:
|
48 |
|
|
print("OK")
|
49 |
|
|
else:
|
50 |
|
|
print("\n{}ERROR: The following required keys don't have a value: {}".format(indent, empty_keys))
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
def expand_all_vars(dir_name):
|
54 |
|
|
_dirname = dir_name
|
55 |
|
|
while '$' in _dirname:
|
56 |
|
|
# print(_dirname)
|
57 |
|
|
_dirname = expandvars(_dirname)
|
58 |
|
|
return _dirname
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
def _check_quartus_configfile(cfgfile, tool_types):
|
62 |
|
|
# check required dirs
|
63 |
|
|
for required_dir in ["quartus_rootdir", "quartus_rootdir_override", "niosdir"]:
|
64 |
|
|
print(" Checking {}...".format(required_dir), end=' ')
|
65 |
|
|
|
66 |
|
|
if isdir(expand_all_vars(cfgfile[required_dir])):
|
67 |
|
|
print("OK")
|
68 |
|
|
else:
|
69 |
|
|
print("\n ERROR: path {} does not exist!".format(cfgfile[required_dir]))
|
70 |
|
|
|
71 |
|
|
# check _paths variables
|
72 |
|
|
required_paths = ["{}_paths".format(tool) for tool in tool_types]
|
73 |
|
|
for path_key in [key for key in list(cfgfile.content.keys()) if key.endswith("_paths")]:
|
74 |
|
|
paths = [expand_all_vars(pathname) for pathname in cfgfile[path_key].replace("\t", " ").split(" ") if pathname != ""]
|
75 |
|
|
print(" Checking {}...".format(path_key))
|
76 |
|
|
if not paths:
|
77 |
|
|
print(" no paths defined.")
|
78 |
|
|
else:
|
79 |
|
|
for path in paths:
|
80 |
|
|
if isdir(path):
|
81 |
|
|
print(" {}: OK".format(path))
|
82 |
|
|
else:
|
83 |
|
|
if path_key in required_paths:
|
84 |
|
|
print(" {}: DOES NOT EXIST!".format(path))
|
85 |
|
|
else:
|
86 |
|
|
print(" {}: does not exist but is not required".format(path))
|
87 |
|
|
|
88 |
|
|
# check IP generation
|
89 |
|
|
print(" Checking ip generation...")
|
90 |
|
|
ip_tools = [tool for tool in cfgfile.ip_tools.replace("\t", " ").split(" ") if tool != '']
|
91 |
|
|
for ip_tool in ip_tools:
|
92 |
|
|
opt_key = "{}_default_options".format(ip_tool)
|
93 |
|
|
if opt_key not in list(cfgfile.content.keys()):
|
94 |
|
|
print(" {}: key is MISSING!".format(opt_key))
|
95 |
|
|
else:
|
96 |
|
|
print(" {}: OK".format(opt_key))
|
97 |
|
|
|
98 |
|
|
# check environment variables
|
99 |
|
|
for envvar_key in [key for key in list(cfgfile.content.keys()) if key.endswith("_environment_variables")]:
|
100 |
|
|
items = [item for item in cfgfile[envvar_key].replace("\t", " ").split(" ") if item != ""]
|
101 |
|
|
print(" Checking {}...".format(envvar_key))
|
102 |
|
|
if not items:
|
103 |
|
|
print(" no variables defined.")
|
104 |
|
|
else:
|
105 |
|
|
if len(items) % 2 == 0:
|
106 |
|
|
print(" number of values is correct")
|
107 |
|
|
else:
|
108 |
|
|
print(" expected even number of values (not {})".format(len(items)))
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
if __name__ == '__main__':
|
112 |
|
|
|
113 |
|
|
keys = ['QUARTUS_DIR', 'ALTERA_DIR', 'MENTOR_DIR', 'MODELSIM_ALTERA_LIBS_DIR']
|
114 |
|
|
for key in keys:
|
115 |
|
|
if key not in os.environ:
|
116 |
|
|
print("{} not in os.environ".format(key))
|
117 |
|
|
|
118 |
|
|
# setup parser and parse the arguments.
|
119 |
|
|
argparser = ArgumentParser(description='Check to content of your hdl_buildset file and the corresponding hdl_tool file.')
|
120 |
|
|
argparser.add_argument('buildset', help="Filename like 'hdl_buildset_.cfg'")
|
121 |
|
|
args = argparser.parse_args()
|
122 |
|
|
|
123 |
|
|
# construct full name of buildsetfile and read the file
|
124 |
|
|
full_buildsetfile_name = expandvars("${RADIOHDL_CONFIG}/hdl_buildset_%s.cfg" % (args.buildset))
|
125 |
|
|
print("Reading {}...".format(full_buildsetfile_name))
|
126 |
|
|
buildset_info = HdlBuildset(full_buildsetfile_name)
|
127 |
|
|
|
128 |
|
|
_do_basic_key_checking(buildset_info)
|
129 |
|
|
|
130 |
|
|
# check if lib_root_dirs exist
|
131 |
|
|
print("Checking defined library directories...", end=' ')
|
132 |
|
|
lib_dirs = [expand_all_vars(libdir) for libdir in buildset_info.lib_root_dirs.replace("\t", " ").split(" ")
|
133 |
|
|
if libdir != '']
|
134 |
|
|
wrong_dirs = []
|
135 |
|
|
for libdir in lib_dirs:
|
136 |
|
|
if not isdir(libdir):
|
137 |
|
|
wrong_dirs.append(libdir)
|
138 |
|
|
if not wrong_dirs:
|
139 |
|
|
print("OK")
|
140 |
|
|
else:
|
141 |
|
|
print("\nERROR: The following library rootdir do not exist: ", wrong_dirs)
|
142 |
|
|
|
143 |
|
|
# Check tools
|
144 |
|
|
subtoolnames = [subtool for subtool in buildset_info.block_design_names.replace("\t", " ").split(" ") if subtool != '']
|
145 |
|
|
toolnames = [buildset_info.synth_tool_name, buildset_info.sim_tool_name]
|
146 |
|
|
for toolname in toolnames:
|
147 |
|
|
print("Checking tool {}...".format(toolname), end=' ')
|
148 |
|
|
if toolname not in buildset_info.section_headers:
|
149 |
|
|
print("\n Warning: No sectionheader found.", end=' ')
|
150 |
|
|
tool_dir = "{}_dir".format(toolname)
|
151 |
|
|
if tool_dir not in list(buildset_info.content.keys()):
|
152 |
|
|
print("\n ERROR: Key {} is missing.".format(tool_dir), end=' ')
|
153 |
|
|
else:
|
154 |
|
|
os.environ[tool_dir.upper()] = buildset_info[tool_dir]
|
155 |
|
|
tool_configfile = expandvars("${RADIOHDL_CONFIG}/hdl_tool_%s.cfg" % (toolname))
|
156 |
|
|
if not isfile(tool_configfile):
|
157 |
|
|
print("\n Warning: File {} is missing!".format(tool_configfile), end=' ')
|
158 |
|
|
else:
|
159 |
|
|
try:
|
160 |
|
|
print("\n Reading {}...".format(tool_configfile))
|
161 |
|
|
tool_info = HdlTool(tool_configfile)
|
162 |
|
|
_do_basic_key_checking(tool_info, indent=" ")
|
163 |
|
|
except ConfigFileException as excp:
|
164 |
|
|
print("\n ERROR: File contains an error: {}".format(excp))
|
165 |
|
|
|
166 |
|
|
if toolname == "quartus":
|
167 |
|
|
_check_quartus_configfile(tool_info, toolnames+subtoolnames)
|