| 1 |
# This script checks that the Minimum Supported Rust Version (MSRV) has the same value |
| 2 |
# in several places throughout the source tree. |
| 3 |
|
| 4 |
import re |
| 5 |
import sys |
| 6 |
|
| 7 |
PLACES_WITH_RUST_VERSION = [ |
| 8 |
['meson.build', r"msrv = '(.*)'"], |
| 9 |
['Cargo.toml', r'rust-version\s*=\s*"(.*)"'], |
| 10 |
['ci/container_builds.yml', r'RUST_MINIMUM:\s*"(.*)"'], |
| 11 |
['devel-docs/_build_dependencies.rst', r'`rust .*`_ (.*) or later'], |
| 12 |
] |
| 13 |
|
| 14 |
PLACES_WITH_CARGO_CBUILD_VERSION = [ |
| 15 |
['meson.build', r"cargo_cbuild_version = '(.*)'"], |
| 16 |
['librsvg-c/Cargo.toml', r'min_version = "(.*)"'], |
| 17 |
] |
| 18 |
|
| 19 |
def check_versions(name, places): |
| 20 |
versions = [] |
| 21 |
|
| 22 |
for filename, regex in places: |
| 23 |
r = re.compile(regex) |
| 24 |
|
| 25 |
with open(filename) as f: |
| 26 |
matched = False |
| 27 |
for idx, line in enumerate(f.readlines()): |
| 28 |
matches = r.search(line) |
| 29 |
if matches is not None: |
| 30 |
matched = True |
| 31 |
line_number = idx + 1 |
| 32 |
versions.append([filename, line_number, matches.group(1), line]) |
| 33 |
|
| 34 |
if not matched: |
| 35 |
raise Exception(f'file {filename} does not have a line that matches {regex}') |
| 36 |
|
| 37 |
assert len(versions) > 0 |
| 38 |
|
| 39 |
all_the_same = True |
| 40 |
|
| 41 |
for filename, line_number, version, line in versions[1:]: |
| 42 |
if version != versions[0][2]: |
| 43 |
all_the_same = False |
| 44 |
|
| 45 |
if not all_the_same: |
| 46 |
print(f'{name}: Version numbers do not match in these lines, please fix them!\n', file=sys.stderr) |
| 47 |
|
| 48 |
for filename, line_number, version, line in versions: |
| 49 |
print(f' {filename}:{line_number}: {line}', file=sys.stderr) |
| 50 |
|
| 51 |
sys.exit(1) |
| 52 |
|
| 53 |
print(f'{name}: Versions number match. All good!', file=sys.stderr) |
| 54 |
|
| 55 |
def main(): |
| 56 |
check_versions('rustc', PLACES_WITH_RUST_VERSION) |
| 57 |
check_versions('cargo-cbuild', PLACES_WITH_CARGO_CBUILD_VERSION) |
| 58 |
|
| 59 |
if __name__ == "__main__": |
| 60 |
main() |