From 190d9fb931fdce2cfc6c466b7d83d3f147c89b93 Mon Sep 17 00:00:00 2001 From: Pawel Szostek <pawel.szostek@gmail.com> Date: Thu, 1 Aug 2013 10:29:14 +0200 Subject: [PATCH] add stubs for tool version detection --- hdlmake/env.py | 40 ++++++++------------------------------ hdlmake/manifest_parser.py | 3 +++ hdlmake/tools/ise.py | 32 ++++++++++++++++++++++++++++++ hdlmake/tools/isim.py | 4 ++++ hdlmake/tools/iverilog.py | 13 +++++++++++++ hdlmake/tools/modelsim.py | 5 +++++ hdlmake/tools/quartus.py | 4 ++++ 7 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 hdlmake/tools/iverilog.py diff --git a/hdlmake/env.py b/hdlmake/env.py index 3727e943..49617fdb 100644 --- a/hdlmake/env.py +++ b/hdlmake/env.py @@ -29,6 +29,7 @@ import logging import os.path from util import path from util.termcolor import colored +from tools.ise import detect_ise_version _plain_print = print @@ -118,8 +119,9 @@ class Env(dict): print("ise_version set in the manifest: %s.%s" % (ise_version[0], ise_version[1])) self["ise_version"] = ise_version elif self["ise_version"] is not None: - print("syn_ise_version not set in the manifest," - " guessed ISE version: %s.%s." % (ise_version[0], ise_version[1])) + iv = self["ise_version"] + print("syn_ise_version not set in the manifest," + " guessed ISE version: %s.%s." % (iv[0], iv[1])) def check_env(self, verbose=False): print.set_verbose(verbose) @@ -173,15 +175,17 @@ class Env(dict): if self["ise_path"] is not None: if self._is_in_path("ise", self["ise_path"]): print(("ISE " + _green("found") + " in HDLMAKE_ISE_PATH: %s.") % self["ise_path"]) - self["ise_version"] = self._guess_ise_version(self["ise_path"]) + self["ise_version"] = detect_ise_version(self["ise_path"]) else: print(("ISE " + _red("not found") + " in HDLMAKE_ISE_PATH: %s.") % self["ise_path"]) else: if self._is_in_path("ise"): print(("ISE " + _green("found") + " in PATH: %s.") % self._get_path("ise")) - self["ise_version"] = self._guess_ise_version(self._get_path("ise")) + self["ise_version"] = detect_ise_version(self._get_path("ise")) else: print("ISE " + _red("not found")) + if self["ise_version"] is not None: + print("Detected ISE version %s.%s." % (self["ise_version"][0], self["ise_version"][1])) # determine modelsim path print("\n### Modelsim simulation ###") @@ -266,35 +270,7 @@ class Env(dict): else: print("To use screen, set it to '1'.") - def _guess_ise_version(self, ise_path): - xst = Popen('which xst', shell=True, stdin=PIPE, - stdout=PIPE, close_fds=True) - lines = xst.stdout.readlines() - if not lines: - return None - - xst = str(lines[0].strip()) - version_pattern = re.compile('.*?(?P<major>\d|\d\d)[^\d](?P<minor>\d|\d\d).*') - # First check if we have version in path - - match = re.match(version_pattern, xst) - if match: - ise_version = (match.group('major'), match.group('minor')) - else: # If it is not the case call the "xst -h" to get version - xst_output = Popen('xst -h', shell=True, stdin=PIPE, - stdout=PIPE, close_fds=True) - xst_output = xst_output.stdout.readlines()[0] - xst_output = xst_output.strip() - version_pattern = re.compile('Release\s(?P<major>\d|\d\d)[^\d](?P<minor>\d|\d\d)\s.*') - match = re.match(version_pattern, xst_output) - if match: - ise_version = (match.group('major'), match.group('minor')) - else: - logging.error("xst output is not in expected format: %s\n" % xst_output + - "Can't determine ISE version") - return None - return ise_version def _get(self, name): assert not name.startswith("HDLMAKE_") diff --git a/hdlmake/manifest_parser.py b/hdlmake/manifest_parser.py index b0af7061..eda28627 100644 --- a/hdlmake/manifest_parser.py +++ b/hdlmake/manifest_parser.py @@ -64,6 +64,9 @@ class ManifestParser(ConfigParser): self.add_option('top_module', default=None, help="Top level entity for synthesis and simulation", type='') + self.add_delimiter() + self.add_option('force_tool', default=None, help="Force certain version of a tool, e.g. 'ise-13.2'") + self.add_delimiter() self.add_option('include_dirs', default=None, help="Include dirs for Verilog sources", type=[]) self.add_type('include_dirs', type="") diff --git a/hdlmake/tools/ise.py b/hdlmake/tools/ise.py index 33bf0653..fd8176c9 100644 --- a/hdlmake/tools/ise.py +++ b/hdlmake/tools/ise.py @@ -29,6 +29,8 @@ import logging import re import global_mod import os +from subprocess import Popen, PIPE + XmlImpl = xml.dom.minidom.getDOMImplementation() @@ -45,6 +47,36 @@ FAMILY_NAMES = { "XC7A": "Artix7"} +def detect_ise_version(path): + xst = Popen('which xst', shell=True, stdin=PIPE, + stdout=PIPE, close_fds=True) + lines = xst.stdout.readlines() + if not lines: + return None + + xst = str(lines[0].strip()) + version_pattern = re.compile('.*?(?P<major>\d|\d\d)[^\d](?P<minor>\d|\d\d).*') + # First check if we have version in path + + match = re.match(version_pattern, xst) + if match: + ise_version = (match.group('major'), match.group('minor')) + else: # If it is not the case call the "xst -h" to get version + xst_output = Popen('xst -h', shell=True, stdin=PIPE, + stdout=PIPE, close_fds=True) + xst_output = xst_output.stdout.readlines()[0] + xst_output = xst_output.strip() + version_pattern = re.compile('Release\s(?P<major>\d|\d\d)[^\d](?P<minor>\d|\d\d)\s.*') + match = re.match(version_pattern, xst_output) + if match: + ise_version = (match.group('major'), match.group('minor')) + else: + logging.error("xst output is not in expected format: %s\n" % xst_output + + "Can't determine ISE version") + return None + + return ise_version + class ISEProjectProperty: def __init__(self, name, value, is_default=False): self.name = name diff --git a/hdlmake/tools/isim.py b/hdlmake/tools/isim.py index 128cf033..56e402ae 100644 --- a/hdlmake/tools/isim.py +++ b/hdlmake/tools/isim.py @@ -3,3 +3,7 @@ ISIM_STARDAND_LIBS = ['std', 'ieee', 'ieee_proposed', 'vl', 'synopsys', 'pls', 'xilinxcorelib', 'aim_ver', 'cpld_ver', 'simprims_ver', 'unisims_ver', 'uni9000_ver', 'unimacro_ver', 'xilinxcorelib_ver', 'secureip'] + + +def detect_isim_version(path): + pass diff --git a/hdlmake/tools/iverilog.py b/hdlmake/tools/iverilog.py new file mode 100644 index 00000000..87acfe1a --- /dev/null +++ b/hdlmake/tools/iverilog.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +from subprocess import Popen, PIPE + + +def detect_iverilog_version(path): + iverilog = Popen("iverilog -v 2>/dev/null| awk '{if(NR==1) print $4}'", + shell=True, + stdin=PIPE, + stdout=PIPE, + close_fds=True) + version = iverilog.stdout.readlines()[0].stripe() + return version diff --git a/hdlmake/tools/modelsim.py b/hdlmake/tools/modelsim.py index 1b6148d5..5e79c7e8 100644 --- a/hdlmake/tools/modelsim.py +++ b/hdlmake/tools/modelsim.py @@ -33,6 +33,11 @@ XmlImpl = xml.dom.minidom.getDOMImplementation() MODELSIM_STANDARD_LIBS = ['ieee', 'std'] +def detect_modelsim_version(path): + pass + + + class ModelsiminiReader(object): def __init__(self, path=None): if path is None: diff --git a/hdlmake/tools/quartus.py b/hdlmake/tools/quartus.py index d10f3af2..17c4c932 100644 --- a/hdlmake/tools/quartus.py +++ b/hdlmake/tools/quartus.py @@ -24,6 +24,10 @@ QUARTUS_STANDARD_LIBS = ['altera', 'altera_mf', 'lpm', 'ieee', 'std'] +def detect_quartus_version(path): + pass + + class _QuartusProjectProperty: SET_GLOBAL_INSTANCE, SET_INSTANCE_ASSIGNMENT, SET_LOCATION_ASSIGNMENT, SET_GLOBAL_ASSIGNMENT = range(4) t = {"set_global_instance": SET_GLOBAL_INSTANCE, -- GitLab