Skip to content

Commit

Permalink
cptbox: let compilers specify required dirs
Browse files Browse the repository at this point in the history
Some compilers require directories to write to, specifically, ZIG and 
SWIFT require `.cache`
  • Loading branch information
Riolku committed Mar 5, 2022
1 parent f752724 commit 68713d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions dmoj/executors/RUST.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Executor(CompiledExecutor):
compiler_write_fs = [
RecursiveDir('~/.cargo'),
]
compiler_required_dirs = ['~/.cargo']

def create_files(self, problem_id, source_code, *args, **kwargs):
os.mkdir(self._file('src'))
Expand Down
1 change: 1 addition & 0 deletions dmoj/executors/SWIFT.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Executor(CompiledExecutor):
RecursiveDir('~/.cache'),
]
compiler_write_fs = compiler_read_fs
compiler_required_dirs = ['~/.cache']
test_program = 'print(readLine()!)'

def get_compile_args(self):
Expand Down
1 change: 1 addition & 0 deletions dmoj/executors/ZIG.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Executor(CompiledExecutor):
RecursiveDir('~/.cache'),
]
compiler_write_fs = compiler_read_fs
compiler_required_dirs = ['~/.cache']
test_program = """
const std = @import("std");
Expand Down
11 changes: 11 additions & 0 deletions dmoj/executors/compiled_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class CompiledExecutor(BaseExecutor, metaclass=_CompiledExecutorMeta):
compiler_read_fs: Sequence[FilesystemAccessRule] = []
compiler_write_fs: Sequence[FilesystemAccessRule] = []

# List of directories required by the compiler to be present, typically for writing to
compiler_required_dirs: List[str] = []

def __init__(self, problem_id: str, source_code: bytes, *args, **kwargs) -> None:
super().__init__(problem_id, source_code, **kwargs)
self.warning = None
Expand All @@ -95,6 +98,14 @@ def create_files(self, problem_id: str, source_code: bytes, *args, **kwargs) ->
with open(self._code, 'wb') as fo:
fo.write(utf8bytes(source_code))

for path in self.compiler_required_dirs:
path = os.path.expanduser(path)
assert path == os.path.abspath(path), 'paths in compiler_required_dirs must be absolute after expanding ~'
try:
os.mkdir(path, mode=0o775)
except FileExistsError:
pass

def get_compile_args(self) -> List[str]:
raise NotImplementedError()

Expand Down

0 comments on commit 68713d0

Please sign in to comment.