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

Update source compatibility suite for latest cadence v1.0.1 #3616

Merged
merged 8 commits into from
Oct 18, 2024
114 changes: 36 additions & 78 deletions compat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import html
import json
import logging
import os
import os, stat
turbolent marked this conversation as resolved.
Show resolved Hide resolved
import re
import shlex
import shutil
Expand Down Expand Up @@ -76,17 +76,6 @@ def replace(pattern, replacement):
with path.open(mode="w") as f:
f.write(source)

@classmethod
def parse(cls, path: Path, use_json: bool, bench: bool) -> (bool, Optional):
return cls._run(PARSER_PATH, "Parsing", path, use_json, bench)

def check(self, path: Path, use_json: bool, bench: bool) -> (bool, Optional):
extra_args = [
f"-memberAccountAccess=S.{path}:S.{(path.parent / Path(other_path)).resolve()}"
for other_path in self.member_account_access
]
return self._run(CHECKER_PATH, "Checking", path, use_json, bench, extra_args)

@staticmethod
def _run(
tool_path: Path,
Expand Down Expand Up @@ -122,17 +111,17 @@ class GoTest:
path: str
command: str

def run(self, working_dir: Path, prepare: bool, go_test_ref: Optional[str]) -> bool:
if go_test_ref:
replacement = f'github.com/onflow/cadence@{go_test_ref}'
else:
replacement = shlex.quote(str(Path.cwd().parent.absolute()))
def run(self, working_dir: Path, prepare: bool, cadence_version: str, flowgo_version: str) -> bool:
turbolent marked this conversation as resolved.
Show resolved Hide resolved
cadence_replacement = f'github.com/onflow/cadence@{cadence_version}'
flowgo_replacement = f'github.com/onflow/flow-go@{flowgo_version}'

with cwd(working_dir / self.path):
if prepare:
logger.info("Editing dependencies")
turbolent marked this conversation as resolved.
Show resolved Hide resolved
subprocess.run([
"go", "mod", "edit", "-replace", f'github.com/onflow/cadence={replacement}',
"go", "mod", "edit", "-replace", f'github.com/onflow/flow-go={flowgo_replacement}',
])
logger.info("Downloading dependencies")
subprocess.run([
"go", "get", "-t", ".",
])
Expand Down Expand Up @@ -200,6 +189,11 @@ def from_dict(cls, data: Dict):

def _clone(self, working_dir: Path):
if working_dir.exists():
for root, dirs, files in os.walk(working_dir):
for dir in dirs:
os.chmod(os.path.join(root, dir), stat.S_IRWXU)
for file in files:
os.chmod(os.path.join(root, file), stat.S_IRWXU)
turbolent marked this conversation as resolved.
Show resolved Hide resolved
shutil.rmtree(working_dir)

logger.info(f"Cloning {self.url} ({self.branch})")
Expand All @@ -214,7 +208,8 @@ def run(
bench: bool,
check: bool,
go_test: bool,
go_test_ref: Optional[str],
cadence_version: str,
flowgo_version: str,
) -> (bool, List[Result]):

working_dir = SUITE_PATH / name
Expand All @@ -223,57 +218,16 @@ def run(
self._clone(working_dir)

results: List[Result] = []
check_succeeded = True
if check:
check_succeeded, results = self.check(working_dir, prepare=prepare, use_json=use_json, bench=bench)

go_tests_succeeded = True
if go_test:
for test in self.go_tests:
if not test.run(working_dir, prepare=prepare, go_test_ref=go_test_ref):
if not test.run(working_dir, prepare=prepare, cadence_version=cadence_version, flowgo_version=flowgo_version):
go_tests_succeeded = False

succeeded = check_succeeded and go_tests_succeeded
succeeded = go_tests_succeeded

return succeeded, results

def check(self, working_dir: Path, prepare: bool, use_json: bool, bench: bool) -> (bool, List[Result]):

run_succeeded = True

results: List[Result] = []

for file in self.files:
path = working_dir.joinpath(file.path)

if prepare:
file.rewrite(path)

parse_succeeded, parse_results = \
File.parse(path, use_json=use_json, bench=bench)
result = Result(
path=str(path),
parse_result=ParseResult.from_dict(parse_results[0]) if parse_results else None
)
if not parse_succeeded:
run_succeeded = False
if use_json:
results.append(result)
continue

check_succeeded, check_results = \
file.check(path, use_json=use_json, bench=bench)
if check_results:
result.check_result = CheckResult.from_dict(check_results[0])
if use_json:
results.append(result)
if not check_succeeded:
run_succeeded = False
continue

return run_succeeded, results


class Git:

@staticmethod
Expand Down Expand Up @@ -659,12 +613,6 @@ def _category(self) -> BenchCategory:
def json_serialize(data) -> str:
return json.dumps(data, indent=4, cls=EnhancedJSONEncoder)


def build_all():
for name in ("parse", "check"):
build(name)


@click.command()
@click.option(
"--rerun",
Expand Down Expand Up @@ -693,13 +641,18 @@ def build_all():
@click.option(
"--go-test/--no-go-test",
is_flag=True,
default=False,
default=True,
help="Run the suite Go tests"
)
@click.option(
"--go-test-ref",
default=None,
help="Git ref of Cadence for Go tests"
"--cadence-version",
default="v1.0.1",
help="version of Cadence for Go tests"
)
@click.option(
"--flowgo-version",
default="v0.37.17",
help="version of flow-go for Go tests"
)
@click.option(
"--output",
Expand Down Expand Up @@ -728,7 +681,8 @@ def main(
bench: bool,
check: bool,
go_test: bool,
go_test_ref: Optional[str],
cadence_version: str,
flowgo_version: str,
output: Optional[LazyFile],
other_ref: Optional[str],
delta_threshold: float,
Expand All @@ -753,7 +707,8 @@ def main(
bench=bench,
check=check,
go_test=go_test,
go_test_ref=go_test_ref,
cadence_version=cadence_version,
flowgo_version=flowgo_version,
names=names
)

Expand Down Expand Up @@ -804,14 +759,16 @@ def run(
bench: bool,
check: bool,
go_test: bool,
go_test_ref: Optional[str],
cadence_version: str,
flowgo_version: str,
names: Collection[str]
) -> (bool, List[Result]):

build_all()

all_succeeded = True

# only flow-go version has an impact, cadence version will be upgraded to match flow-go version
logger.info(f'Chosen versions: cadence@{cadence_version}, flow-go@{flowgo_version}')

if not names:
names = load_index(SUITE_PATH / "index.yaml")

Expand All @@ -828,7 +785,8 @@ def run(
bench=bench,
check=check,
go_test=go_test,
go_test_ref=go_test_ref,
cadence_version=cadence_version,
flowgo_version=flowgo_version,
)

if not run_succeeded:
Expand Down
Loading