blob: 5a59d4cd8649203629de3678437ccd0ed1aec2d1 [file] [log] [blame]
Pirmin Vogeled097cc2020-03-09 11:35:21 +01001#!/usr/bin/python3
2# Copyright lowRISC contributors.
3# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4# SPDX-License-Identifier: Apache-2.0
5
6from distutils.version import StrictVersion
7import logging as log
8import os
9import subprocess
10import sys
11
12# Display INFO log messages and up.
13log.basicConfig(level=log.INFO, format="%(levelname)s: %(message)s")
14
15# Populate __TOOL_REQUIREMENTS__
16topsrcdir = os.path.join(os.path.dirname(__file__), '..')
17exec(open(os.path.join(topsrcdir, 'tool_requirements.py')).read())
18
19def get_verilator_version():
20 try:
21 # Note: "verilator" needs to be called through a shell and with all
22 # arguments in a string, as it doesn't have a shebang, but instead
23 # relies on perl magic to parse command line arguments.
24 version_str = subprocess.run('verilator --version', shell=True,
25 check=True, stdout=subprocess.PIPE,
26 stderr=subprocess.STDOUT,
27 universal_newlines=True)
28 return version_str.stdout.split(' ')[1].strip()
29
30 except subprocess.CalledProcessError as e:
31 log.error("Unable to call Verilator to check version: " + str(e))
32 log.error(e.stdout)
33 return None
34
35def check_version(tool_name, required_version, actual_version):
36 if required_version is None or actual_version is None:
37 return False
38
39 if StrictVersion(actual_version) < StrictVersion(required_version):
40 log.error("%s is too old: found version %s, need at least %s",
41 tool_name, actual_version, required_version)
42 return False
43 else:
44 log.info("Found sufficiently recent version of %s (found %s, need %s)",
45 tool_name, actual_version, required_version)
46 return True
47
48
49def main():
50 any_failed = False
51
52 if not check_version('verilator', __TOOL_REQUIREMENTS__['verilator'],
53 get_verilator_version()):
54 any_failed = True
55
56 if any_failed:
57 log.error("Tool requirements not fulfilled. "
58 "Please update the tools and retry.")
59 return 1
60 return 0
61
62if __name__ == "__main__":
63 sys.exit(main())