Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check workspace script #105

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions check-workspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Fork from https://github.com/ggwpez/substrate-scripts/blob/91537c4088fc07da52b614e6b3f2f4c8ce8700d9/import-runtime-repos/check-deps.py

# Ensures that workspace dependencies are resolved via `path` and not something else.
# Also checks that all crates are part of the Rust workspace.

# Invocation:
# python3 check-deps.py polkadot-sdk/
# Example output:
# 🔎 Checking folder polkadot-sdk/
# 📜 Found workspace manifest
# 📜 Found 441 crates in the workspace
# ✅ All 5307 dependency links are correct

import os
import sys
import toml

DIR = sys.argv[1]
print("🔎 Checking folder %s" % DIR)

crates = []
manifests = []
in_workspace = []

for root, dirs, files in os.walk(DIR):
if "target" in root:
continue

for file in files:
if file != "Cargo.toml":
continue

path = os.path.join(root, file)
with open(path, "r") as f:
content = f.read()
manifest = toml.loads(content)

if 'workspace' in manifest:
for member in manifest['workspace']['members']:
in_workspace.append(member)
continue

manifests.append(manifest)

if len(in_workspace) != len(manifests):
print("💥 Crates are missing from the workspace Cargo.toml")
sys.exit(1)

for manifest in manifests:
name = manifest['package']['name']
crates.append(name)

links = []
git_links = []
broken = []
# Now check that all the deps are correct.
for manifest in manifests:
name = manifest['package']['name']

def check_deps(deps):
for dep in deps:
# Account for renames:
dep_name = dep
if 'package' in deps[dep]:
dep_name = deps[dep]['package']
if 'git' in deps[dep]:
git_links.append((name, dep_name))
if dep_name in crates:
links.append((name, dep_name))

if not 'path' in deps[dep]:
broken.append((name, dep_name))

if 'dependencies' in manifest:
check_deps(manifest['dependencies'])
if 'dev-dependencies' in manifest:
check_deps(manifest['dev-dependencies'])
if 'build-dependencies' in manifest:
check_deps(manifest['build-dependencies'])

crates.sort()
links.sort()
broken.sort()

print("📜 Found %d crates in the workspace" % len(crates))

for link in git_links:
print("❗ %s -> %s (uses Git)" % link)
for link in broken:
print("❌ %s -> %s" % link)

if len(broken) > 0:
print("💥 %d out of %d links are broken" % (len(broken), len(links)))
sys.exit(1)
else:
print("✅ All %d local links are correct." % len(links))