diff options
author | Jean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com> | 2020-01-24 18:08:04 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-01-27 16:48:10 +0000 |
commit | bd184ea6ff09f9d5b47ac1b3d1140bc34aa420f2 (patch) | |
tree | 0afd98a67f2a697cd23cfe098f6bacc81b0d3666 /bitbake | |
parent | bdcd68f092bcd803f08524c30c99e2a082462fd1 (diff) | |
download | poky-bd184ea6ff09f9d5b47ac1b3d1140bc34aa420f2.tar.gz |
bitbake: utils: add is_semver function
This function checks if a string is a semantic version:
https://semver.org/spec/v2.0.0.html
The npm fetcher needs this function to validate its version parameter.
(Bitbake rev: 61ac4e825fa7afbb76282030586abc9ee4ac215c)
Signed-off-by: Jean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/utils.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 28368f0a60..47805d02cf 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -1611,3 +1611,29 @@ class LogCatcher(logging.Handler): | |||
1611 | self.messages.append(bb.build.logformatter.format(record)) | 1611 | self.messages.append(bb.build.logformatter.format(record)) |
1612 | def contains(self, message): | 1612 | def contains(self, message): |
1613 | return (message in self.messages) | 1613 | return (message in self.messages) |
1614 | |||
1615 | def is_semver(version): | ||
1616 | """ | ||
1617 | Is the version string following the semver semantic? | ||
1618 | |||
1619 | https://semver.org/spec/v2.0.0.html | ||
1620 | """ | ||
1621 | regex = re.compile( | ||
1622 | r""" | ||
1623 | ^ | ||
1624 | (0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*) | ||
1625 | (?:-( | ||
1626 | (?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*) | ||
1627 | (?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))* | ||
1628 | ))? | ||
1629 | (?:\+( | ||
1630 | [0-9a-zA-Z-]+ | ||
1631 | (?:\.[0-9a-zA-Z-]+)* | ||
1632 | ))? | ||
1633 | $ | ||
1634 | """, re.VERBOSE) | ||
1635 | |||
1636 | if regex.match(version) is None: | ||
1637 | return False | ||
1638 | |||
1639 | return True | ||