mirror of
https://github.com/servo/servo.git
synced 2025-06-08 00:23:30 +00:00
Auto merge of #7438 - Wafflespeanut:cargo-tidy, r=jdm
Tidy can now check for version conflicts... fixes #7133 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7438) <!-- Reviewable:end -->
This commit is contained in:
commit
8b5418f58f
2 changed files with 44 additions and 4 deletions
|
@ -16,7 +16,7 @@ import StringIO
|
|||
import sys
|
||||
from licenseck import licenses
|
||||
|
||||
filetypes_to_check = [".rs", ".rc", ".cpp", ".c", ".h", ".py", ".toml", ".webidl"]
|
||||
filetypes_to_check = [".rs", ".rc", ".cpp", ".c", ".h", ".lock", ".py", ".toml", ".webidl"]
|
||||
reftest_dir = "./tests/ref"
|
||||
reftest_filetype = ".list"
|
||||
python_dependencies = [
|
||||
|
@ -70,7 +70,7 @@ VIM_HEADER = "/* vim:"
|
|||
|
||||
|
||||
def check_license(file_name, contents):
|
||||
if file_name.endswith(".toml"):
|
||||
if file_name.endswith(".toml") or file_name.endswith(".lock"):
|
||||
raise StopIteration
|
||||
while contents.startswith(EMACS_HEADER) or contents.startswith(VIM_HEADER):
|
||||
_, _, contents = contents.partition("\n")
|
||||
|
@ -148,6 +148,46 @@ def check_flake8(file_name, contents):
|
|||
yield line_num, message.strip()
|
||||
|
||||
|
||||
def check_lock(file_name, contents):
|
||||
if not file_name.endswith(".lock"):
|
||||
raise StopIteration
|
||||
contents = contents.splitlines(True)
|
||||
idx = 1
|
||||
packages = {}
|
||||
exceptions = ["glutin", "wayland-kbd"] # package names to be neglected (as named by cargo)
|
||||
|
||||
while idx < len(contents):
|
||||
content = contents[idx].strip()
|
||||
if 'name' in content:
|
||||
base_name = content.split('"')[1]
|
||||
# we need the base package because some other package might demand a new version in the following lines
|
||||
packages[base_name] = contents[idx + 1].split('"')[1], idx + 2, base_name
|
||||
if 'dependencies' in content:
|
||||
idx += 1
|
||||
while contents[idx].strip() != ']':
|
||||
package = contents[idx].strip().strip('",').split()
|
||||
name, version = package[0], package[1]
|
||||
if name not in packages: # store the line number & base package name for future comparison
|
||||
packages[name] = (version, idx + 1, base_name)
|
||||
elif all([packages[name][0] != version, name not in exceptions, base_name not in exceptions]):
|
||||
line = idx + 1
|
||||
version_1 = tuple(map(int, packages[name][0].split('.')))
|
||||
version_2 = tuple(map(int, version.split('.')))
|
||||
if version_1 < version_2: # get the line & base package containing the older version
|
||||
packages[name], (version, line, base_name) = (version, line, base_name), packages[name]
|
||||
|
||||
message = 'conflicting versions for package "%s"' % name
|
||||
error = '\n\t\033[93mexpected maximum version "{}"\033[0m'.format(packages[name][0]) + \
|
||||
'\n\t\033[91mbut, "{}" demands "{}"\033[0m' \
|
||||
.format(base_name, version)
|
||||
suggest = "\n\t\033[93mtry upgrading with\033[0m " + \
|
||||
"\033[96m./mach cargo-update -p {}:{}\033[0m" \
|
||||
.format(name, version)
|
||||
yield (line, message + error + suggest)
|
||||
idx += 1
|
||||
idx += 1
|
||||
|
||||
|
||||
def check_toml(file_name, contents):
|
||||
if not file_name.endswith(".toml"):
|
||||
raise StopIteration
|
||||
|
@ -433,7 +473,7 @@ def scan():
|
|||
files_to_check = filter(should_check, all_files)
|
||||
|
||||
checking_functions = [check_license, check_by_line, check_flake8, check_toml,
|
||||
check_rust, check_webidl_spec, check_spec]
|
||||
check_lock, check_rust, check_webidl_spec, check_spec]
|
||||
errors = collect_errors_for_files(files_to_check, checking_functions)
|
||||
|
||||
reftest_files = (os.path.join(r, f) for r, _, files in os.walk(reftest_dir) for f in files)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue