51 lines
1.3 KiB
Python
Executable File
51 lines
1.3 KiB
Python
Executable File
#!/usr/bin/python3
|
|
import os
|
|
import argparse
|
|
|
|
cli_args_parser = argparse.ArgumentParser(description="Bproto Compiler")
|
|
|
|
cli_args_parser.add_argument(
|
|
"-i", "--input",
|
|
help="Input file to compile",
|
|
required=True
|
|
)
|
|
cli_args_parser.add_argument(
|
|
"-o", "--output",
|
|
help="Output file to write compiled code to",
|
|
required=True
|
|
)
|
|
cli_args_parser.add_argument(
|
|
"-t", "--target",
|
|
help="Target language to compile to",
|
|
required=True,
|
|
choices=["python", "c", "txt"],
|
|
action="append"
|
|
)
|
|
|
|
args = cli_args_parser.parse_args()
|
|
|
|
targets = " ".join([
|
|
f"--target \"{i}\""
|
|
for i in args.target
|
|
])
|
|
|
|
input_basename = os.path.basename(args.input)
|
|
input_path = os.path.abspath(args.input)
|
|
output_path = os.path.abspath(args.output)
|
|
|
|
if not os.path.isfile(input_path):
|
|
print(f"{input_path} is not a file")
|
|
exit(-1)
|
|
|
|
if not os.path.isdir(output_path):
|
|
print(f"{output_path} is not folder")
|
|
exit(-1)
|
|
|
|
c = "docker pull alexanderhd27/bproto-compiler:latest"
|
|
print(f"RUN: {c}")
|
|
os.system(c)
|
|
|
|
c = f"docker run -v {output_path}:/compiler/data -v {input_path}:/compiler/{input_basename} --rm alexanderhd27/bproto-compiler:latest /compiler/src/main.py --output /compiler/data --input /compiler/{input_basename} {targets}"
|
|
print(f"RUN: {c}")
|
|
os.system(c)
|