Skip to content

Commit

Permalink
replace Meson version check with a specification-compliant version co…
Browse files Browse the repository at this point in the history
…mparator

The current check compares the integers split out from `meson --version`
one by one. This is an ad-hoc version comparison algorithm with a few
flaws, notably that it doesn't truly understand how version components
fit together, and that broke once Meson bumped the major version. There
are other potential issues that could show up but haven't yet, such as
versions with words in them (release candidates).

The packaging module is a high-quality library that provides a standard
version parsing algorithm, with which you can simply say "is this
version object greater than that one". Use it instead.

Fixes enjoy-digital#1545
  • Loading branch information
eli-schwartz committed Jan 4, 2023
1 parent 19e0e2f commit c4ec49e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
20 changes: 10 additions & 10 deletions litex/soc/integration/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import struct
import shutil

from packaging.version import Version

from litex import get_data_mod
from litex.gen import colorer

Expand Down Expand Up @@ -253,20 +255,18 @@ def _generate_csr_map(self):
def _check_meson(self):
# Check Meson install/version.
meson_present = (shutil.which("meson") is not None)
meson_version = [0, 0, 0]
meson_major_min = 0
meson_minor_min = 59
meson_req = '0.59'
if meson_present:
meson_version = subprocess.check_output(["meson", "-v"]).decode("utf-8").split(".")
if (not meson_present):
meson_version = subprocess.check_output(["meson", "-v"]).decode("utf-8")
if not Version(meson_version) >= Version(meson_req):
msg = f"Meson version to old. Found: {meson_version}. Required: {meson_req}.\n"
msg += "Try updating with:\n"
msg += "- pip3 install -U meson.\n"
raise OSError(msg)
else:
msg = "Unable to find valid Meson build system, please install it with:\n"
msg += "- pip3 install meson.\n"
raise OSError(msg)
if (int(meson_version[0]) < meson_major_min) or (int(meson_version[0]) == meson_major_min and int(meson_version[1]) < meson_minor_min):
msg = f"Meson version to old. Found: {meson_version[0]}.{meson_version[1]}. Required: {meson_major_min}.{meson_minor_min}.\n"
msg += "Try updating with:\n"
msg += "- pip3 install -U meson.\n"
raise OSError(msg)

def _prepare_rom_software(self):
# Create directories for all software packages.
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
license="BSD",
python_requires="~=3.6",
install_requires=[
"packaging",
"pyserial",
"requests",
],
Expand Down

0 comments on commit c4ec49e

Please sign in to comment.