1 |
2 |
danv |
#!/usr/bin/env python
|
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, sys
|
26 |
|
|
from os.path import expandvars, isfile, isdir
|
27 |
|
|
from argparse import ArgumentParser
|
28 |
|
|
from hdl_configfile import HdlBuildset, HdlTool
|
29 |
|
|
|
30 |
|
|
def _do_basic_key_checking(cfgfile, indent=""):
|
31 |
|
|
# Check that all key references are solved
|
32 |
|
|
print "{}Checking references...".format(indent),
|
33 |
|
|
all_refs_solved = cfgfile.resolve_key_references()
|
34 |
|
|
if all_refs_solved:
|
35 |
|
|
print "OK"
|
36 |
|
|
else:
|
37 |
|
|
print "\n{}ERROR: The following reference cannot be solved: {}".format(indent, cfgfile.unresolved_refs)
|
38 |
|
|
|
39 |
|
|
# Check that all key required keys contain values
|
40 |
|
|
print "{}Checking required keys...".format(indent),
|
41 |
|
|
empty_keys = []
|
42 |
|
|
for key in cfgfile.required_keys:
|
43 |
|
|
if cfgfile.content[key] == "":
|
44 |
|
|
empty_keys.append(key)
|
45 |
|
|
if not empty_keys:
|
46 |
|
|
print "OK"
|
47 |
|
|
else:
|
48 |
|
|
print "\n{}ERROR: The following required keys don't have a value: {}".format(indent, empty_keys)
|
49 |
|
|
|
50 |
|
|
def _check_quartus_configfile(cfgfile, tool_types):
|
51 |
|
|
# check required dirs
|
52 |
|
|
for required_dir in [ "quartus_rootdir", "quartus_rootdir_override", "niosdir" ]:
|
53 |
|
|
print " Checking {}...".format(required_dir),
|
54 |
|
|
if isdir(expandvars(cfgfile[required_dir])):
|
55 |
|
|
print "OK"
|
56 |
|
|
else:
|
57 |
|
|
print "\n ERROR: path {} does not exist!".format(cfgfile[required_dir])
|
58 |
|
|
|
59 |
|
|
# check _paths variables
|
60 |
|
|
required_paths = [ "{}_paths".format(tool) for tool in tool_types ]
|
61 |
|
|
for path_key in [ key for key in cfgfile.content.keys() if key.endswith("_paths") ]:
|
62 |
|
|
paths = [ expandvars(pathname) for pathname in cfgfile[path_key].replace("\t"," ").split(" ") if pathname != "" ]
|
63 |
|
|
print " Checking {}...".format(path_key)
|
64 |
|
|
if not paths:
|
65 |
|
|
print " no paths defined."
|
66 |
|
|
else:
|
67 |
|
|
for path in paths:
|
68 |
|
|
if isdir(path):
|
69 |
|
|
print " {}: OK".format(path)
|
70 |
|
|
else:
|
71 |
|
|
if path_key in required_paths:
|
72 |
|
|
print " {}: DOES NOT EXIST!".format(path)
|
73 |
|
|
else:
|
74 |
|
|
print " {}: does not exist but is not required".format(path)
|
75 |
|
|
|
76 |
|
|
# check IP generation
|
77 |
|
|
print " Checking ip generation..."
|
78 |
|
|
ip_tools = [ tool for tool in cfgfile.ip_tools.replace("\t"," ").split(" ") if tool != '' ]
|
79 |
|
|
for ip_tool in ip_tools:
|
80 |
|
|
opt_key = "{}_default_options".format(ip_tool)
|
81 |
|
|
if not opt_key in cfgfile.content.keys():
|
82 |
|
|
print " {}: key is MISSING!".format(opt_key)
|
83 |
|
|
else:
|
84 |
|
|
print " {}: OK".format(opt_key)
|
85 |
|
|
|
86 |
|
|
# check environment variables
|
87 |
|
|
for envvar_key in [ key for key in cfgfile.content.keys() if key.endswith("_environment_variables") ]:
|
88 |
|
|
items = [ item for item in cfgfile[envvar_key].replace("\t"," ").split(" ") if item != "" ]
|
89 |
|
|
print " Checking {}...".format(envvar_key)
|
90 |
|
|
if not items:
|
91 |
|
|
print " no variables defined."
|
92 |
|
|
else:
|
93 |
|
|
if len(items)%2 == 0:
|
94 |
|
|
print " number of values is correct"
|
95 |
|
|
else:
|
96 |
|
|
print " expected even number of values (not {})".format(len(items))
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
if __name__ == '__main__':
|
100 |
|
|
# setup parser and parse the arguments.
|
101 |
|
|
argparser = ArgumentParser(description='Check to content of your hdl_buildset file and the corresponding hdl_tool file.')
|
102 |
|
|
argparser.add_argument('buildset', help="Filename like 'hdl_buildset_.cfg'")
|
103 |
|
|
args = argparser.parse_args()
|
104 |
|
|
|
105 |
|
|
# construct full name of buildsetfile and read the file
|
106 |
|
|
full_buildsetfile_name = expandvars("${HDL_CONFIG_DIR}/hdl_buildset_%s.cfg" % (args.buildset))
|
107 |
|
|
print "Reading {}...".format(full_buildsetfile_name)
|
108 |
|
|
buildset_info = HdlBuildset(full_buildsetfile_name)
|
109 |
|
|
|
110 |
|
|
_do_basic_key_checking(buildset_info)
|
111 |
|
|
|
112 |
|
|
# check if lib_root_dirs exist
|
113 |
|
|
print "Checking defined library directories...",
|
114 |
|
|
lib_dirs = [ expandvars(libdir) for libdir in buildset_info.lib_root_dirs.replace("\t"," ").split(" ")
|
115 |
|
|
if libdir != '' ]
|
116 |
|
|
wrong_dirs = []
|
117 |
|
|
for libdir in lib_dirs:
|
118 |
|
|
if not isdir(libdir):
|
119 |
|
|
wrong_dirs.append(libdir)
|
120 |
|
|
if not wrong_dirs:
|
121 |
|
|
print "OK"
|
122 |
|
|
else:
|
123 |
|
|
print "\nERROR: The following library rootdir do not exist: ", wrong_dirs
|
124 |
|
|
|
125 |
|
|
# Check tools
|
126 |
|
|
subtoolnames = [ subtool for subtool in buildset_info.block_design_names.replace("\t"," ").split(" ") if subtool != '' ]
|
127 |
|
|
toolnames = [ buildset_info.synth_tool_name, buildset_info.sim_tool_name ]
|
128 |
|
|
for toolname in toolnames:
|
129 |
|
|
print "Checking tool {}...".format(toolname),
|
130 |
|
|
if not toolname in buildset_info.section_headers:
|
131 |
|
|
print "\n Warning: No sectionheader found.",
|
132 |
|
|
tool_dir = "{}_dir".format(toolname)
|
133 |
|
|
if not tool_dir in buildset_info.content.keys():
|
134 |
|
|
print "\n ERROR: Key {} is missing.".format(tool_dir),
|
135 |
|
|
else:
|
136 |
|
|
os.environ[tool_dir.upper()] = buildset_info[tool_dir]
|
137 |
|
|
tool_configfile = expandvars("${HDL_CONFIG_DIR}/hdl_tool_%s.cfg" % (toolname))
|
138 |
|
|
if not isfile(tool_configfile):
|
139 |
|
|
print "\n Warning: File {} is missing!".format(tool_configfile),
|
140 |
|
|
else:
|
141 |
|
|
try:
|
142 |
|
|
print "\n Reading {}...".format(tool_configfile)
|
143 |
|
|
tool_info = HdlTool(tool_configfile)
|
144 |
|
|
_do_basic_key_checking(tool_info, indent=" ")
|
145 |
|
|
except ConfigFileException as excp:
|
146 |
|
|
print "\n ERROR: File contains an error: {}".format(excp)
|
147 |
|
|
|
148 |
|
|
if toolname == "quartus":
|
149 |
|
|
_check_quartus_configfile(tool_info, toolnames+subtoolnames)
|
150 |
|
|
|
151 |
|
|
|