From 021ec1aa9418b2bf860b36fe77efa05f4ea17f0b Mon Sep 17 00:00:00 2001 From: Hydrazer Date: Thu, 30 Dec 2021 11:12:20 -0700 Subject: [PATCH 1/4] pkg(MATL-22.5.0): added MATL 22.5.0 --- packages/MATL/22.5.0/build.sh | 9 +++++++++ packages/MATL/22.5.0/environment | 5 +++++ packages/MATL/22.5.0/metadata.json | 5 +++++ packages/MATL/22.5.0/run | 13 +++++++++++++ packages/MATL/22.5.0/test.matl | 1 + readme.md | 1 + 6 files changed, 34 insertions(+) create mode 100644 packages/MATL/22.5.0/build.sh create mode 100644 packages/MATL/22.5.0/environment create mode 100644 packages/MATL/22.5.0/metadata.json create mode 100644 packages/MATL/22.5.0/run create mode 100644 packages/MATL/22.5.0/test.matl diff --git a/packages/MATL/22.5.0/build.sh b/packages/MATL/22.5.0/build.sh new file mode 100644 index 0000000..ea2a376 --- /dev/null +++ b/packages/MATL/22.5.0/build.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +# build octave as dependency +source ../../octave/6.2.0/build.sh + +# curl MATL 22.5.0 +curl -L "https://github.com/lmendo/MATL/archive/refs/tags/22.5.0.tar.gz" -o MATL.tar.xz +tar xf MATL.tar.xz --strip-components=1 +rm MATL.tar.xz \ No newline at end of file diff --git a/packages/MATL/22.5.0/environment b/packages/MATL/22.5.0/environment new file mode 100644 index 0000000..015acc2 --- /dev/null +++ b/packages/MATL/22.5.0/environment @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +# Path to MATL binary +export PATH=$PWD/bin:$PATH +export MATL_PATH=$PWD \ No newline at end of file diff --git a/packages/MATL/22.5.0/metadata.json b/packages/MATL/22.5.0/metadata.json new file mode 100644 index 0000000..07cdc09 --- /dev/null +++ b/packages/MATL/22.5.0/metadata.json @@ -0,0 +1,5 @@ +{ + "language": "matl", + "version": "22.5.0", + "aliases": [] +} diff --git a/packages/MATL/22.5.0/run b/packages/MATL/22.5.0/run new file mode 100644 index 0000000..8576158 --- /dev/null +++ b/packages/MATL/22.5.0/run @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# get file as first argument +file="$1" + +# remove the file from $@ +shift + +# use the rest of the arguments as stdin +stdin=`printf "%s\n" "$@"` + +# pass stdin into octave which will run MATL +echo "$stdin" | octave -W -p "$MATL_PATH" --eval "matl -of '$file'" diff --git a/packages/MATL/22.5.0/test.matl b/packages/MATL/22.5.0/test.matl new file mode 100644 index 0000000..97791fa --- /dev/null +++ b/packages/MATL/22.5.0/test.matl @@ -0,0 +1 @@ +'OK' \ No newline at end of file diff --git a/readme.md b/readme.md index 0cc0fa4..cebde53 100644 --- a/readme.md +++ b/readme.md @@ -351,6 +351,7 @@ Content-Type: application/json `llvm_ir`, `lolcode`, `lua`, +`matl`, `nasm`, `nasm64`, `nim`, From f6fa9cb968b0b455942e1154130812862cffdd4d Mon Sep 17 00:00:00 2001 From: Shane Date: Sun, 2 Jan 2022 09:39:24 +0000 Subject: [PATCH 2/4] Make builder script run relative to directory it was called from --- builder/build.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/builder/build.sh b/builder/build.sh index 8559eaf..eaae21d 100755 --- a/builder/build.sh +++ b/builder/build.sh @@ -2,6 +2,9 @@ # Build a container using the spec file provided +START_DIR=$PWD +cd "$(dirname "$BASH_SOURCE[0]}")" + help_msg(){ echo "Usage: $0 [specfile] [tag]" echo @@ -37,14 +40,14 @@ fetch_packages(){ } build_container(){ - docker build -t $1 -f "$(dirname $0)/Dockerfile" "$PWD/build" + docker build -t $1 -f "Dockerfile" "$START_DIR/build" } -SPEC_FILE=$1 +SPEC_FILE=$START_DIR/$1 TAG=$2 -[ -z "$SPEC_FILE" ] && help_msg "specfile is required" +[ -z "$1" ] && help_msg "specfile is required" [ -z "$TAG" ] && help_msg "tag is required" [ -f "$SPEC_FILE" ] || help_msg "specfile does not exist" @@ -58,4 +61,4 @@ fetch_packages $SPEC_FILE build_container $TAG echo "Start your custom piston container with" -echo "$ docker run --tmpfs /piston/jobs -dit -p 2000:2000 $TAG" \ No newline at end of file +echo "$ docker run --tmpfs /piston/jobs -dit -p 2000:2000 $TAG" From fe7f66a7542ba488e18dfb4de78ab814c47b1963 Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Fri, 28 Jan 2022 11:43:56 +0200 Subject: [PATCH 3/4] Add .vscode to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index eb53d81..e82d86f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ data/ .piston_env node_modules +.vscode/ From 416ade1b76e8d6e641ed54fba9e8a7b69bccf873 Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Fri, 28 Jan 2022 17:58:00 +0200 Subject: [PATCH 4/4] Refactor config.js --- api/src/config.js | 170 ++++++++++++++++++++++++---------------------- 1 file changed, 88 insertions(+), 82 deletions(-) diff --git a/api/src/config.js b/api/src/config.js index 5324097..d207431 100644 --- a/api/src/config.js +++ b/api/src/config.js @@ -2,57 +2,6 @@ const fss = require('fs'); const Logger = require('logplease'); const logger = Logger.create('config'); -function parse_overrides(overrides) { - try { - return JSON.parse(overrides); - } catch (e) { - return null; - } -} - -function validate_overrides(overrides, options) { - for (const language in overrides) { - for (const key in overrides[language]) { - if ( - ![ - 'max_process_count', - 'max_open_files', - 'max_file_size', - 'compile_memory_limit', - 'run_memory_limit', - 'compile_timeout', - 'run_timeout', - 'output_max_size', - ].includes(key) - ) { - logger.error(`Invalid overridden option: ${key}`); - return false; - } - const option = options.find(o => o.key === key); - const parser = option.parser; - const raw = overrides[language][key]; - const value = parser(raw); - const validators = option.validators; - for (const validator of validators) { - const response = validator(value, raw); - if (response !== true) { - logger.error( - `Failed to validate overridden option: ${key}`, - response - ); - return false; - } - } - overrides[language][key] = value; - } - // Modifies the reference - options[ - options.index_of(options.find(o => o.key === 'limit_overrides')) - ] = overrides; - } - return true; -} - const options = [ { key: 'log_level', @@ -68,7 +17,7 @@ const options = [ { key: 'bind_address', desc: 'Address to bind REST API on', - default: `0.0.0.0:${process.env["PORT"] || 2000}`, + default: `0.0.0.0:${process.env['PORT'] || 2000}`, validators: [], }, { @@ -192,53 +141,110 @@ const options = [ default: {}, parser: parse_overrides, validators: [ - x => !!x || `Invalid JSON format for the overrides\n${x}`, - (overrides, _, options) => - validate_overrides(overrides, options) || - `Failed to validate the overrides`, + x => !!x || `Failed to parse the overrides\n${x}`, + validate_overrides, ], }, ]; -logger.info(`Loading Configuration from environment`); +Object.freeze(options); -let errored = false; +function apply_validators(validators, validator_parameters) { + for (const validator of validators) { + const validation_response = validator(...validator_parameters); + if (validation_response !== true) { + return validation_response; + } + } + return true; +} + +function parse_overrides(overrides_string) { + function get_parsed_json_or_null(overrides) { + try { + return JSON.parse(overrides); + } catch (e) { + return null; + } + } + + const overrides = get_parsed_json_or_null(overrides_string); + if (typeof overrides === null) { + return null; + } + const parsed_overrides = {}; + for (const language in overrides) { + parsed_overrides[language] = {}; + for (const key in overrides[language]) { + if ( + ![ + 'max_process_count', + 'max_open_files', + 'max_file_size', + 'compile_memory_limit', + 'run_memory_limit', + 'compile_timeout', + 'run_timeout', + 'output_max_size', + ].includes(key) + ) { + return null; + } + // Find the option for the override + const option = options.find(o => o.key === key); + const parser = option.parser; + const raw = overrides[language][key]; + const value = parser(raw); + parsed_overrides[language][key] = value; + } + } + return parsed_overrides; +} + +function validate_overrides(overrides) { + for (const language in overrides) { + for (const key in overrides[language]) { + const value = overrides[language][key]; + const option = options.find(o => o.key === key); + const validators = option.validators; + const validation_response = apply_validators(validators, [ + value, + value, + ]); + if (validation_response !== true) { + return `In overridden option ${key} for ${language}, ${validation_response}`; + } + } + } + return true; +} + +logger.info(`Loading Configuration from environment`); let config = {}; options.forEach(option => { const env_key = 'PISTON_' + option.key.to_upper_case(); - const parser = option.parser || (x => x); - const env_val = process.env[env_key]; - const parsed_val = parser(env_val); - const value = env_val === undefined ? option.default : parsed_val; - - option.validators.for_each(validator => { - let response = null; - if (env_val) response = validator(parsed_val, env_val, options); - else response = validator(value, value, options); - - if (response !== true) { - errored = true; - logger.error( - `Config option ${option.key} failed validation:`, - response - ); - return; - } - }); - + const validator_parameters = + env_val === undefined ? [value, value] : [parsed_val, env_val]; + const validation_response = apply_validators( + option.validators, + validator_parameters + ); + if (validation_response !== true) { + logger.error( + `Config option ${option.key} failed validation:`, + validation_response + ); + process.exit(1); + } config[option.key] = value; }); -if (errored) { - process.exit(1); -} - logger.info('Configuration successfully loaded'); module.exports = config;