Debian Codegraph @

debian/missing-sources/zerocopy/ci/check_msrv_is_minimal.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2 #
3 # Copyright 2025 The Fuchsia Authors
4 #
5 # Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
6 # <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
7 # license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
8 # This file may not be copied, modified, or distributed except according to
9 # those terms.
10
11 set -eo pipefail
12
13 read -r -d '' PYTHON_SCRIPT <<'EOF' || true
14 import sys
15 import json
16
17 def parse_version(v):
18 """Converts a version string to a tuple of integers."""
19 return tuple(map(int, v.split(".")))
20
21 def main():
22 """
23 Checks that the package's MSRV is strictly lower than any version
24 specified in `package.metadata.build-rs`.
25 """
26 try:
27 data = json.load(sys.stdin)
28 except json.JSONDecodeError as e:
29 print(f"Error parsing JSON from cargo metadata: {e}", file=sys.stderr)
30 sys.exit(1)
31
32 # Find the zerocopy package
33 try:
34 pkg = next(p for p in data["packages"] if p["name"] == "zerocopy")
35 except StopIteration:
36 print("Error: zerocopy package not found in metadata", file=sys.stderr)
37 sys.exit(1)
38
39 msrv_str = pkg.get("rust_version")
40 if not msrv_str:
41 print("Error: rust-version not found in Cargo.toml", file=sys.stderr)
42 sys.exit(1)
43
44 try:
45 msrv = parse_version(msrv_str)
46 except ValueError:
47 print(f"Error: Invalid MSRV format: {msrv_str}", file=sys.stderr)
48 sys.exit(1)
49
50 build_rs_versions = (pkg.get("metadata") or {}).get("build-rs", {})
51
52 failed = False
53 for name, ver_str in build_rs_versions.items():
54 try:
55 ver = parse_version(ver_str)
56 except ValueError:
57 print(f"Warning: Skipping invalid version format for {name}: {ver_str}", file=sys.stderr)
58 continue
59
60 # Check that MSRV < Version (strictly lower)
61 if not (msrv < ver):
62 print(f"Error: MSRV ({msrv_str}) is not strictly lower than {name} ({ver_str})", file=sys.stderr)
63 failed = True
64
65 if failed:
66 sys.exit(1)
67
68 if __name__ == "__main__":
69 main()
70 EOF
71
72 cargo metadata --format-version 1 --no-deps | python3 -c "$PYTHON_SCRIPT"