OpenCores
URL https://opencores.org/ocsvn/radiohdl/radiohdl/trunk

Subversion Repositories radiohdl

[/] [radiohdl/] [trunk/] [base/] [check_config] - Rev 2

Compare with Previous | Blame | View Log

#!/usr/bin/env python
###############################################################################
#
# Copyright (C) 2018
# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# $Id: generate_ip_libs.py 18842 2018-08-29 10:47:05Z overeem $
#
###############################################################################

import os, sys
from os.path        import expandvars, isfile, isdir
from argparse       import ArgumentParser
from hdl_configfile import HdlBuildset, HdlTool

def _do_basic_key_checking(cfgfile, indent=""):
    # Check that all key references are solved
    print "{}Checking references...".format(indent),
    all_refs_solved = cfgfile.resolve_key_references()
    if all_refs_solved:
        print "OK"
    else:
        print "\n{}ERROR: The following reference cannot be solved: {}".format(indent, cfgfile.unresolved_refs)

    # Check that all key required keys contain values
    print "{}Checking required keys...".format(indent),
    empty_keys = []
    for key in cfgfile.required_keys:
        if cfgfile.content[key] == "":
            empty_keys.append(key)
    if not empty_keys:
        print "OK"
    else:
        print "\n{}ERROR: The following required keys don't have a value: {}".format(indent, empty_keys)

def _check_quartus_configfile(cfgfile, tool_types):
    # check required dirs
    for required_dir in [ "quartus_rootdir", "quartus_rootdir_override", "niosdir" ]:
        print "  Checking {}...".format(required_dir),
        if isdir(expandvars(cfgfile[required_dir])):
            print "OK"
        else:
            print "\n    ERROR: path {} does not exist!".format(cfgfile[required_dir])

    # check _paths variables
    required_paths = [ "{}_paths".format(tool) for tool in tool_types ]
    for path_key in [ key for key in cfgfile.content.keys() if key.endswith("_paths") ]:
        paths = [ expandvars(pathname) for pathname in cfgfile[path_key].replace("\t"," ").split(" ") if pathname != "" ]
        print "  Checking {}...".format(path_key)
        if not paths:
            print "    no paths defined."
        else:
            for path in paths:
                if isdir(path):
                    print "    {}: OK".format(path)
                else:
                    if path_key in required_paths:
                        print "    {}: DOES NOT EXIST!".format(path)
                    else:
                        print "    {}: does not exist but is not required".format(path)

    # check IP generation
    print "  Checking ip generation..."
    ip_tools = [ tool for tool in cfgfile.ip_tools.replace("\t"," ").split(" ") if tool != '' ]
    for ip_tool in ip_tools:
        opt_key = "{}_default_options".format(ip_tool)
        if not opt_key in cfgfile.content.keys():
            print "    {}: key is MISSING!".format(opt_key)
        else:
            print "    {}: OK".format(opt_key)
    
    # check environment variables
    for envvar_key in [ key for key in cfgfile.content.keys() if key.endswith("_environment_variables") ]:
        items = [ item for item in cfgfile[envvar_key].replace("\t"," ").split(" ") if item != "" ]
        print "  Checking {}...".format(envvar_key)
        if not items:
            print "    no variables defined."
        else:
            if len(items)%2 == 0:
                print "    number of values is correct"
            else:
                print "    expected even number of values (not {})".format(len(items))


if __name__ == '__main__':
    # setup parser and parse the arguments.
    argparser = ArgumentParser(description='Check to content of your hdl_buildset file and the corresponding hdl_tool file.')
    argparser.add_argument('buildset', help="Filename like 'hdl_buildset_<buildset>.cfg'")
    args = argparser.parse_args()

    # construct full name of buildsetfile and read the file
    full_buildsetfile_name = expandvars("${HDL_CONFIG_DIR}/hdl_buildset_%s.cfg" % (args.buildset))
    print "Reading {}...".format(full_buildsetfile_name)
    buildset_info = HdlBuildset(full_buildsetfile_name)

    _do_basic_key_checking(buildset_info)

    # check if lib_root_dirs exist
    print "Checking defined library directories...",
    lib_dirs = [ expandvars(libdir) for libdir in buildset_info.lib_root_dirs.replace("\t"," ").split(" ")
                  if libdir != '' ]
    wrong_dirs = []
    for libdir in lib_dirs:
        if not isdir(libdir):
            wrong_dirs.append(libdir)
    if not wrong_dirs:
        print "OK"
    else:
        print "\nERROR: The following library rootdir do not exist: ", wrong_dirs

    # Check tools
    subtoolnames = [ subtool for subtool in buildset_info.block_design_names.replace("\t"," ").split(" ") if subtool != '' ]
    toolnames = [ buildset_info.synth_tool_name, buildset_info.sim_tool_name ]
    for toolname in toolnames:
        print "Checking tool {}...".format(toolname),
        if not toolname in buildset_info.section_headers:
            print "\n  Warning: No sectionheader found.",
        tool_dir = "{}_dir".format(toolname)
        if not tool_dir in buildset_info.content.keys():
            print "\n  ERROR: Key {} is missing.".format(tool_dir),
        else:
            os.environ[tool_dir.upper()] = buildset_info[tool_dir]
        tool_configfile = expandvars("${HDL_CONFIG_DIR}/hdl_tool_%s.cfg" % (toolname))
        if not isfile(tool_configfile):
            print "\n  Warning: File {} is missing!".format(tool_configfile),
        else:
            try:
                print "\n  Reading {}...".format(tool_configfile)
                tool_info = HdlTool(tool_configfile)
                _do_basic_key_checking(tool_info, indent="  ")
            except ConfigFileException as excp:
                print "\n    ERROR: File contains an error: {}".format(excp)

        if toolname == "quartus":
            _check_quartus_configfile(tool_info, toolnames+subtoolnames)


Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2019 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.