Added --timeout option in build.py

This commit is contained in:
nocturn9x 2021-04-18 12:04:24 +02:00
parent f959693076
commit a767e44daa
4 changed files with 18 additions and 11 deletions

View File

@ -99,12 +99,12 @@ def run_command(command: str, mode: str = "Popen", **kwargs):
def build(path: str, flags: Optional[Dict[str, str]] = {}, options: Optional[Dict[str, bool]] = {}, def build(path: str, flags: Optional[Dict[str, str]] = {}, options: Optional[Dict[str, bool]] = {},
override: Optional[bool] = False, skip_tests: Optional[bool] = False, override: Optional[bool] = False, skip_tests: Optional[bool] = False,
install: Optional[bool] = False, ignore_binary: Optional[bool] = False, install: Optional[bool] = False, ignore_binary: Optional[bool] = False,
verbose: Optional[bool] = False): verbose: Optional[bool] = False, tests_timeout: Optional[int] = 10):
""" """
Builds the JAPL runtime. Builds the JAPL runtime.
This function generates the required configuration This function generates the required configuration
according to the user's choice, runs tests and according to the user's choice, runs tests and
performs installation when possible. performs installation when possible.
:param path: The path to JAPL's main source directory :param path: The path to JAPL's main source directory
@ -140,6 +140,10 @@ def build(path: str, flags: Optional[Dict[str, str]] = {}, options: Optional[Dic
:param verbose: This parameter tells the test suite to use verbose logs, :param verbose: This parameter tells the test suite to use verbose logs,
defaults to False defaults to False
:type verbose: bool, optional :type verbose: bool, optional
:param tests_timeout: The max. amount of seconds each test in the test
suite is allowed to run before being killed for taking too long, defaults
to 10 seconds
:type tests_timeout: int, optional
""" """
@ -196,7 +200,7 @@ def build(path: str, flags: Optional[Dict[str, str]] = {}, options: Optional[Dic
logging.debug("Running tests") logging.debug("Running tests")
start = time() start = time()
# TODO: Find a better way of running the test suite # TODO: Find a better way of running the test suite
process = run_command(f"{tests_path} {'--stdout' if verbose else ''}", mode="run", shell=True, stderr=PIPE) process = run_command(f"{tests_path} {'--stdout' if verbose else ''} --timeout={tests_timeout}", mode="run", shell=True, stderr=PIPE)
if status != 0: if status != 0:
logging.error(f"Command '{command}' exited with non-0 exit code {status}, output below:\n{stderr.decode()}") logging.error(f"Command '{command}' exited with non-0 exit code {status}, output below:\n{stderr.decode()}")
return False return False
@ -244,6 +248,7 @@ if __name__ == "__main__":
parser.add_argument("--install", help="Tries to move the compiled binary to PATH (this is always disabled on windows)", action="store_true", default=os.environ.get("JAPL_INSTALL")) parser.add_argument("--install", help="Tries to move the compiled binary to PATH (this is always disabled on windows)", action="store_true", default=os.environ.get("JAPL_INSTALL"))
parser.add_argument("--ignore-binary", help="Ignores an already existing 'jpl' binary in any installation directory and overwrites it, use (with care!) with --install", action="store_true", default=os.getenv("JAPL_IGNORE_BINARY")) parser.add_argument("--ignore-binary", help="Ignores an already existing 'jpl' binary in any installation directory and overwrites it, use (with care!) with --install", action="store_true", default=os.getenv("JAPL_IGNORE_BINARY"))
parser.add_argument("--profile", help="The path to a json file specifying build options and arguments. Overrides ANY other option!", default=os.environ.get("JAPL_PROFILE")) parser.add_argument("--profile", help="The path to a json file specifying build options and arguments. Overrides ANY other option!", default=os.environ.get("JAPL_PROFILE"))
parser.add_argument("--timeout", help="The max. amount of seconds each test in the test suite is allowed to run before being killed for taking too long, defaults to 10 seconds", default=os.environ.get("JAPL_TIMEOUT"), type=int)
args = parser.parse_args() args = parser.parse_args()
flags = { flags = {
"gc": "refc", "gc": "refc",
@ -258,7 +263,7 @@ if __name__ == "__main__":
"array_grow_factor": "2", "array_grow_factor": "2",
"frames_max": "800", "frames_max": "800",
} }
# We support environment variables! # We support environment variables for build options too!
for key, value in options.items(): for key, value in options.items():
if var := os.getenv(f"JAPL_{key.upper()}"): if var := os.getenv(f"JAPL_{key.upper()}"):
options[key] = var options[key] = var
@ -266,7 +271,7 @@ if __name__ == "__main__":
datefmt="%T", datefmt="%T",
level=logging.DEBUG if args.verbose else logging.INFO level=logging.DEBUG if args.verbose else logging.INFO
) )
logging.info("Just Another Build Tool, version 0.3.4") logging.info("Just Another Build Tool, version 0.3.5")
if args.flags: if args.flags:
try: try:
for value in args.flags.split(","): for value in args.flags.split(","):
@ -318,7 +323,8 @@ if __name__ == "__main__":
args.skip_tests, args.skip_tests,
args.install, args.install,
args.ignore_binary, args.ignore_binary,
args.verbose): args.verbose,
args.timeout):
logging.debug("Build tool exited successfully") logging.debug("Build tool exited successfully")
else: else:
logging.debug("Build tool exited with error") logging.debug("Build tool exited with error")

View File

@ -1,7 +1,7 @@
// Production build options // Production build options
{"flags": { {"flags": {
"gc": "none", "gc": "none",
"d": "danger" "d": "release"
}, },
"override_config": true, "override_config": true,
"install": true, "install": true,

View File

@ -65,7 +65,7 @@ proc repl(vmObj: Option[VM]) =
break break
elif source != "": elif source != "":
discard bytecodeVM.interpret(source, "stdin") discard bytecodeVM.interpret(source, "stdin")
if not bytecodeVM.lastPop.isNil(): if not bytecodeVM.lastPop.isJaplNil():
echo stringify(bytecodeVM.lastPop) echo stringify(bytecodeVM.lastPop)
bytecodeVM.lastPop = cast[ptr Nil](bytecodeVM.cached[2]) bytecodeVM.lastPop = cast[ptr Nil](bytecodeVM.cached[2])
bytecodeVM.freeVM() bytecodeVM.freeVM()

View File

@ -30,7 +30,8 @@ import strutils
import terminal import terminal
import re import re
type
type
Action {.pure.} = enum Action {.pure.} = enum
Run, Help, Version Run, Help, Version
## The action JATS takes. ## The action JATS takes.
@ -57,7 +58,7 @@ when isMainModule:
var testDir = "japl" var testDir = "japl"
proc evalKey(key: string) = proc evalKey(key: string) =
## Modifies the globals that define what JATS does based on the ## Modifies the globals that define what JATS does based on the
## provided key/flag ## provided key/flag
let key = key.toLower() let key = key.toLower()
if key == "h" or key == "help": if key == "h" or key == "help":
@ -101,7 +102,7 @@ when isMainModule:
# a round is 100 ms, so let's not get close to that # a round is 100 ms, so let's not get close to that
if timeoutSeconds < 0.3: if timeoutSeconds < 0.3:
timeoutSeconds = 0.3 timeoutSeconds = 0.3
# I don't want anything not nicely convertible to int, # I don't want anything not nicely convertible to int,
# so how about cut it off at 10 hours. Open an issue # so how about cut it off at 10 hours. Open an issue
# if that's not enough... or just tweak it you lunatic # if that's not enough... or just tweak it you lunatic
if timeoutSeconds > 36000.0: if timeoutSeconds > 36000.0: