-
Notifications
You must be signed in to change notification settings - Fork 33
Build C test cases via Python script to target-specific dir #112
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.wasm | ||
.DS_Store | ||
.DS_Store | ||
/tests/c/testsuite/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/usr/bin/env python3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just looking at the https://github.com/WebAssembly/wasi-testsuite/pull/114/files and it seems a lot of duplication, I wonder if we can refactor it in a way that the common part can be reused across different languages? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think yes, but wdyt about me doing that in a followup? It's a bit easier when the three implementations are actually there in the source tree. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine by me. Could you open a tracking issue so we don't forget about this? Thanks |
||
|
||
import argparse | ||
import json | ||
import os | ||
import shlex | ||
import shutil | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
from math import inf | ||
|
||
# shlex.split() splits according to shell quoting rules | ||
CC = shlex.split(os.getenv("CC", "clang")) | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--dry-run", action="store_true") | ||
parser.add_argument("--verbose", action="store_true") | ||
|
||
args = parser.parse_args() | ||
|
||
SYSTEMS = ['wasm32'] | ||
VERSIONS = ['wasip1'] # + ['wasip2', 'wasip3'] | ||
|
||
def compute_target(system, version): | ||
return f"{system}-{version}" | ||
|
||
def compute_cc_target(system, version): | ||
if version == 'wasip3': | ||
# wasm32-wasip3 triple not yet supported. | ||
return compute_target(system, 'wasip2') | ||
return compute_target(system, version) | ||
|
||
BASE_DIR = Path(__file__).parent | ||
|
||
def maybe_stat(path, default): | ||
try: | ||
return path.stat().st_mtime | ||
except FileNotFoundError: | ||
return default | ||
|
||
def needs_rebuild(dst, src): | ||
if maybe_stat(dst, 0) < src.stat().st_mtime: | ||
return True | ||
return (maybe_stat(dst.with_suffix(".json"), -1) | ||
< maybe_stat(src.with_suffix(".json"), -inf)) | ||
|
||
def run(argv): | ||
if args.verbose: | ||
print(shlex.join([str(x) for x in argv])) | ||
if not args.dry_run: | ||
r = subprocess.run(argv) | ||
if r.returncode != 0: | ||
sys.exit(r.returncode) | ||
|
||
def cp(src, dst): | ||
if args.verbose: | ||
print(f"cp {src} {dst}") | ||
if not args.dry_run: | ||
shutil.copy(src, dst) | ||
|
||
def cp_R(src, dst): | ||
if args.verbose: | ||
print(f"cp -R {src} {dst}") | ||
if not args.dry_run: | ||
shutil.copytree(src, dst, dirs_exist_ok=True) | ||
|
||
def write_manifest(path, manifest): | ||
if args.verbose: | ||
print(f"writing {path}") | ||
if not args.dry_run: | ||
path.write_text(json.dumps(manifest)) | ||
|
||
def mkdir_p(path): | ||
if args.verbose: | ||
print(f"mkdir -p {path}") | ||
if not args.dry_run: | ||
path.mkdir(parents=True, exist_ok=True) | ||
|
||
for system in SYSTEMS: | ||
for version in VERSIONS: | ||
target = compute_target(system, version) | ||
generic_sources = list((BASE_DIR / "src").glob("*.c")) | ||
target_sources = list((BASE_DIR / "src" / target).glob("*.c")) | ||
|
||
target_dir = BASE_DIR / "testsuite" / target | ||
mkdir_p(target_dir) | ||
target_args = [f"--target={compute_cc_target(system, version)}"] | ||
|
||
write_manifest(target_dir / "manifest.json", | ||
{'name': f"WASI C tests [{target}]"}) | ||
|
||
for src in generic_sources + target_sources: | ||
dst = (target_dir / src.name).with_suffix(".wasm") | ||
if needs_rebuild(dst, src): | ||
print(f"building testsuite/{target}/{dst.name}") | ||
src_json = src.with_suffix(".json") | ||
if src_json.exists(): | ||
dst_json = dst.with_suffix(".json") | ||
with src_json.open() as f: | ||
for d in json.load(f).get('dirs', []): | ||
cp_R(src.parent / d, dst.parent / d) | ||
cp(src_json, dst_json) | ||
run(CC + target_args + [src] + ['-o'] + [dst]) |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps it's best to use relative path here?