Added support for build profiles

This commit is contained in:
nocturn9x 2021-02-03 20:12:00 +01:00
parent 95522cd3c7
commit 35cce3e2ea
10 changed files with 155 additions and 1 deletions

View File

@ -95,7 +95,7 @@ git clone https://github.com/japl-lang/japl
### Running the build script
As a next step, you need to run the build script. This will generate the required configuration files, compile the JAPL runtime and run tests (unless `--skip-tests` is used). There are some settings that can be tweaked with command-line options (or environment variables), for more information, run `python3 build.py --help`.
As a next step, you need to run JABT (YES, Just Another Build Tool). This will generate the required configuration files, compile the JAPL runtime and run tests (unless `--skip-tests` is used). There are some settings that can be tweaked with command-line options (or environment variables), for more information, run `python3 build.py --help`.
To compile the JAPL runtime, you'll first need to move into the project's directory you cloned before, so run `cd japl`, then `python3 build.py ./src` and wait for it to complete. You should now find an executable named `japl` (or `japl.exe` on windows) inside the `src` folder.
@ -151,3 +151,11 @@ the already existing data unless `--ignore-binary` is passed!
On both Windows and Linux, the build script supports reading parameters from environment variables if they are not specified via the command line.
All options follow the same naming scheme: `JAPL_OPTION_NAME=value` and will only be applied if no explicit override for them is passed
when running the script
### Build profiles
JABT comes with a handy `--profile` option that allows to pass a JSON file with
all the build arguments and flags. The JAPL toolsuite comes with some build profiles by default, they are
found inside the `resources/profiles` directory and are particularly useful to replicate common build options.

View File

@ -18,6 +18,7 @@
import os
import stat
import json
import shlex
import shutil
import logging
@ -161,6 +162,7 @@ def build(path: str, flags: Optional[Dict[str, str]] = {}, options: Optional[Dic
return
else:
logging.debug(f"Config file has been generated, compiling with options as follows: {''.join(listing.format(k, v) for k, v in options.items())}")
logging.debug(f"Nim compiler options: {''.join(listing.format(k, v) for k, v in flags.items())}")
logging.debug(f"Compiling '{main_path}'")
nim_flags = " ".join(f"-{name}:{value}" if len(name) == 1 else f"--{name}:{value}" for name, value in flags.items())
command = "nim {flags} compile {path}".format(flags=nim_flags, path=main_path)
@ -241,6 +243,7 @@ if __name__ == "__main__":
parser.add_argument("--skip-tests", help="Skips running the JAPL test suite, useful for debug builds", action="store_true", default=os.getenv("JAPL_SKIP_TESTS"))
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("--profile", help="The path to a json file specifying build options and arguments. Overrides ANY other option!", default=os.environ.get("JAPL_PROFILE"))
args = parser.parse_args()
flags = {
"gc": "refc",
@ -282,6 +285,31 @@ if __name__ == "__main__":
except Exception:
logging.error("Invalid parameter for --options")
exit()
if args.profile:
try:
with open(args.profile) as profile:
skip = 0
line = profile.readline()
while line.startswith("//"):
# We skip comments and keep track of
# where we should reset our buffer
skip = profile.tell()
line = profile.readline()
profile.seek(skip - 1)
data = json.load(profile)
if "options" in data:
for option, value in data["options"].items():
options[option] = value
if "flags" in data:
for flag, value in data["flags"].items():
flags[flag] = value
for arg in {"override_config", "skip_tests", "verbose", "install", "ignore_binary"}:
setattr(args, arg, data.get(arg, getattr(args, arg)))
except Exception as e:
logging.error(f"An error occurred while loading profile '{args.profile}' -> {type(e).__name__}: {e}")
exit()
else:
logging.info(f"Using profile '{args.profile}'")
build(args.path,
flags,
options,

View File

@ -0,0 +1,19 @@
// Debugs JAPL with both its internal tooling and help from the
// nim compiler itself (d:debug). The debug build is still optimized
// for speed with opt:speed
{"flags": {
"gc": "boehm",
"d": "debug",
"opt": "speed"
},
"verbose": true,
"override_config": true,
"install": true,
"ignore_binary": true,
"options": {
"debug_vm": "true",
"debug_gc": "true",
"debug_compiler": "true",
"debug_alloc": "true"
}
}

View File

@ -0,0 +1,15 @@
// Debugs JAPL's memory manager, without any help
// from nim itself (the nim compiler options are identical to those of
// production.json)
{"flags": {
"gc": "none",
"d": "danger"
},
"verbose": true,
"override_config": true,
"install": true,
"ignore_binary": true,
"options": {
"debug_alloc": "true"
}
}

View File

@ -0,0 +1,15 @@
// Debugs the JAPL compiler toolchain, without any help
// from nim itself (the nim compiler options are identical to those of
// production.json)
{"flags": {
"gc": "none",
"d": "danger"
},
"verbose": true,
"override_config": true,
"install": true,
"ignore_binary": true,
"options": {
"debug_compiler": "true",
}
}

View File

@ -0,0 +1,15 @@
// Debugs JAPL's garbage collector, without any help
// from nim itself (the nim compiler options are identical to those of
// production.json)
{"flags": {
"gc": "none",
"d": "danger"
},
"verbose": true,
"override_config": true,
"install": true,
"ignore_binary": true,
"options": {
"debug_gc": "true",
}
}

View File

@ -0,0 +1,18 @@
// Debugs JAPL with all flags turned on, but without any help
// from nim itself (the nim compiler options are identical to those of
// production.json)
{"flags": {
"gc": "none",
"d": "danger"
},
"verbose": true,
"override_config": true,
"install": true,
"ignore_binary": true,
"options": {
"debug_vm": "true",
"debug_gc": "true",
"debug_compiler": "true",
"debug_alloc": "true"
}
}

View File

@ -0,0 +1,15 @@
// Debugs the JAPL Virtual Machine, but without any help
// from nim itself (the nim compiler options are identical to those of
// production.json)
{"flags": {
"gc": "none",
"d": "danger"
},
"verbose": true,
"override_config": true,
"install": true,
"ignore_binary": true,
"options": {
"debug_vm": "true",
}
}

View File

@ -0,0 +1,11 @@
// Development build options
{"flags": {
"gc": "boehm",
"d": "debug",
"opt": "speed"
},
"verbose": true,
"override_config": true,
"install": true,
"ignore_binary": true
}

View File

@ -0,0 +1,10 @@
// Production build options
{"flags": {
"gc": "none",
"d": "danger"
},
"override_config": true,
"skip_tests": true,
"install": true,
"ignore_binary": true
}