diff --git a/api/src/api/v2.js b/api/src/api/v2.js index c0526f4..4f0c3e2 100644 --- a/api/src/api/v2.js +++ b/api/src/api/v2.js @@ -87,15 +87,6 @@ function get_job(body) { } } - if ( - files.filter(file => !file.encoding || file.encoding === 'utf8') - .length === 0 - ) { - return reject({ - message: 'files must include at least one utf8 encoded file', - }); - } - const rt = runtime.get_latest_runtime_matching_language_version( language, version @@ -106,6 +97,15 @@ function get_job(body) { }); } + if ( + rt.language !== 'file' && + !files.some(file => !file.encoding || file.encoding === 'utf8') + ) { + return reject({ + message: 'files must include at least one utf8 encoded file', + }); + } + for (const constraint of ['memory_limit', 'timeout']) { for (const type of ['compile', 'run']) { const constraint_name = `${type}_${constraint}`; diff --git a/api/src/job.js b/api/src/job.js index 7acff22..ca95e6f 100644 --- a/api/src/job.js +++ b/api/src/job.js @@ -222,7 +222,9 @@ class Job { } runtime=${this.runtime.toString()}` ); - const code_files = this.files.filter(file => file.encoding == 'utf8'); + const code_files = + (this.runtime.language === 'file' && this.files) || + this.files.filter(file => file.encoding == 'utf8'); logger.debug('Compiling'); @@ -270,7 +272,9 @@ class Job { } gid=${this.gid} runtime=${this.runtime.toString()}` ); - const code_files = this.files.filter(file => file.encoding == 'utf8'); + const code_files = + (this.runtime.language === 'file' && this.files) || + this.files.filter(file => file.encoding == 'utf8'); if (this.runtime.compiled) { eventBus.emit('stage', 'compile'); diff --git a/cli/commands/execute.js b/cli/commands/execute.js index c69d3a0..0d906bc 100644 --- a/cli/commands/execute.js +++ b/cli/commands/execute.js @@ -245,9 +245,18 @@ async function run_non_interactively(files, argv) { exports.handler = async argv => { const files = [...(argv.files || []), argv.file].map(file_path => { + const buffer = fs.readFileSync(file_path); + const encoding = + (buffer + .toString() + .split('') + .some(x => x.charCodeAt(0) >= 128) && + 'base64') || + 'utf8'; return { name: path.basename(file_path), - content: fs.readFileSync(file_path).toString(), + content: buffer.toString(encoding), + encoding, }; }); diff --git a/packages/file/0.0.1/build.sh b/packages/file/0.0.1/build.sh new file mode 100755 index 0000000..d7ab47e --- /dev/null +++ b/packages/file/0.0.1/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +# Nothing to do here diff --git a/packages/file/0.0.1/environment b/packages/file/0.0.1/environment new file mode 100644 index 0000000..d5a7803 --- /dev/null +++ b/packages/file/0.0.1/environment @@ -0,0 +1,3 @@ +#!/bin/bash + +export PATH=$PWD:$PATH diff --git a/packages/file/0.0.1/metadata.json b/packages/file/0.0.1/metadata.json new file mode 100644 index 0000000..ae34ae9 --- /dev/null +++ b/packages/file/0.0.1/metadata.json @@ -0,0 +1,5 @@ +{ + "language": "file", + "version": "0.0.1", + "aliases": ["executable", "elf", "binary"] +} diff --git a/packages/file/0.0.1/run b/packages/file/0.0.1/run new file mode 100644 index 0000000..77ed0a6 --- /dev/null +++ b/packages/file/0.0.1/run @@ -0,0 +1,6 @@ +#!/bin/bash + +filename="$1" +chmod +x "$filename" +shift +./"$filename" "$@" diff --git a/packages/file/0.0.1/test.file b/packages/file/0.0.1/test.file new file mode 100755 index 0000000..8c7a67d Binary files /dev/null and b/packages/file/0.0.1/test.file differ diff --git a/readme.md b/readme.md index d2f2e75..1679568 100644 --- a/readme.md +++ b/readme.md @@ -341,6 +341,7 @@ Content-Type: application/json `elixir`, `emacs`, `erlang`, +`file`, `forte`, `fortran`, `freebasic`,