mirror of
https://github.com/engineer-man/piston.git
synced 2025-05-06 20:06:27 +02:00
Merge pull request #382 from Brikaa/file
pkg(file-0.0.1): Run executable
This commit is contained in:
commit
d8b430654b
9 changed files with 43 additions and 12 deletions
|
@ -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}`;
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
3
packages/file/0.0.1/build.sh
vendored
Executable file
3
packages/file/0.0.1/build.sh
vendored
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Nothing to do here
|
3
packages/file/0.0.1/environment
vendored
Normal file
3
packages/file/0.0.1/environment
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
export PATH=$PWD:$PATH
|
5
packages/file/0.0.1/metadata.json
vendored
Normal file
5
packages/file/0.0.1/metadata.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"language": "file",
|
||||
"version": "0.0.1",
|
||||
"aliases": ["executable", "elf", "binary"]
|
||||
}
|
6
packages/file/0.0.1/run
vendored
Normal file
6
packages/file/0.0.1/run
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
filename="$1"
|
||||
chmod +x "$filename"
|
||||
shift
|
||||
./"$filename" "$@"
|
BIN
packages/file/0.0.1/test.file
vendored
Executable file
BIN
packages/file/0.0.1/test.file
vendored
Executable file
Binary file not shown.
|
@ -341,6 +341,7 @@ Content-Type: application/json
|
|||
`elixir`,
|
||||
`emacs`,
|
||||
`erlang`,
|
||||
`file`,
|
||||
`forte`,
|
||||
`fortran`,
|
||||
`freebasic`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue