Compare commits

...

4 Commits

Author SHA1 Message Date
Jack Forden 858a853767
Merge 2a9de4d7b2 into 1d55a41a2d 2025-02-18 19:28:26 +01:00
Omar Brikaa 1d55a41a2d
Explicitly provide env vars instead of inheriting them from parent (#703) 2025-02-08 20:46:46 +02:00
Omar Brikaa 6ef0cdf7b4
Provide HOME in sandbox (#702) 2025-02-08 15:10:50 +02:00
Jack Forden 2a9de4d7b2
Change Java to compiled language to facilitate multi-file
Currently, Piston does not support multi-file Java submissions

This change turns Java into a compiled language, while still maintaining the flexibility of single file submissions.
2024-02-28 17:17:58 -06:00
3 changed files with 40 additions and 14 deletions

View File

@ -156,7 +156,11 @@ class Job {
'-s',
'-c',
'/box/submission',
'-e',
'-E',
'HOME=/tmp',
...this.runtime.env_vars.flat_map(v => ['-E', v]),
'-E',
`PISTON_LANGUAGE=${this.runtime.language}`,
`--dir=${this.runtime.pkgdir}`,
`--dir=/etc:noexec`,
`--processes=${this.runtime.max_process_count}`,
@ -175,10 +179,6 @@ class Job {
...args,
],
{
env: {
...this.runtime.env_vars,
PISTON_LANGUAGE: this.runtime.language,
},
stdio: 'pipe',
}
);

View File

@ -178,15 +178,7 @@ class Runtime {
const env_file = path.join(this.pkgdir, '.env');
const env_content = fss.read_file_sync(env_file).toString();
this._env_vars = {};
env_content
.trim()
.split('\n')
.map(line => line.split('=', 2))
.forEach(([key, val]) => {
this._env_vars[key.trim()] = val.trim();
});
this._env_vars = env_content.trim().split('\n');
}
return this._env_vars;

34
packages/java/15.0.2/compile vendored Normal file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# Check if exactly one argument is provided
if [ $# -eq 1 ]; then
mv $1 $1.java
filename=$1.java
shift
java $filename "$@"
else
# Initialize an empty array to hold the filenames
declare -a javaFiles
# Loop through each argument
for file in "$@"; do
# Check if the file already ends with .java
if [[ "$file" == *.java ]]; then
# If it does, add it directly to the array
javaFiles+=("$file")
else
# If it doesn't, add .java extension then add to the array
javaFiles+=("${file}.java")
fi
done
# Compile all Java files at once
javac "${javaFiles[@]}"
# Run the compiled Java classes
# Assuming the first argument is the main class file to run
# Remove .java extension from the main class name if present
mainClass="${1%.java}"
# Execute the main class
java "$mainClass"
fi