import argparse
import platform
import subprocess
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument(
"--flatc",
help="path of the Flat C compiler relative to the root directory",
)
parser.add_argument("--cpp-0x", action="store_true", help="use --cpp-std c++ox")
parser.add_argument(
"--skip-monster-extra",
action="store_true",
help="skip generating tests involving monster_extra.fbs",
)
parser.add_argument(
"--skip-gen-reflection",
action="store_true",
help="skip generating the reflection.fbs files",
)
args = parser.parse_args()
script_path = Path(__file__).parent.resolve()
root_path = script_path.parent.absolute()
tests_path = Path(root_path, "tests")
flatc_exe = Path(
("flatc" if not platform.system() == "Windows" else "flatc.exe")
if not args.flatc
else args.flatc
)
if root_path in flatc_exe.parents:
flatc_exe = flatc_exe.relative_to(root_path)
flatc_path = Path(root_path, flatc_exe)
assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path)
def flatc(options, schema, prefix=None, include=None, data=None, cwd=tests_path):
cmd = [str(flatc_path)] + options
if prefix:
cmd += ["-o"] + [prefix]
if include:
cmd += ["-I"] + [include]
cmd += [schema] if isinstance(schema, str) else schema
if data:
cmd += [data] if isinstance(data, str) else data
result = subprocess.run(cmd, cwd=str(cwd), check=True)