Skip to content

Commit

Permalink
Add storage namespace to binary cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
hieplpvip committed Oct 4, 2024
1 parent 2ce35b4 commit 11d6e22
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 20 deletions.
4 changes: 2 additions & 2 deletions dmoj/executors/RUST.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class Executor(CompiledExecutor):
RecursiveDir('~/.cargo'),
]

def __init__(self, problem_id: str, source_code: bytes, **kwargs) -> None:
super().__init__(problem_id, source_code, **kwargs)
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.shared_target: Optional[str] = None

def create_files(self, problem_id, source_code, *args, **kwargs) -> None:
Expand Down
6 changes: 3 additions & 3 deletions dmoj/executors/SCRATCH.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import subprocess
from typing import List
from typing import List, Optional

from dmoj.cptbox import TracedPopen
from dmoj.cptbox.filesystem_policies import ExactFile, FilesystemAccessRule
Expand All @@ -22,8 +22,8 @@ class Executor(ScriptExecutor):
https://raw.githubusercontent.com/VNOI-Admin/judge-server/master/asset/scratch_test_program.sb3
"""

def __init__(self, problem_id: str, source_code: bytes, **kwargs) -> None:
super().__init__(problem_id, source_code, **kwargs)
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.meta = kwargs.get('meta', {})

def get_fs(self) -> List[FilesystemAccessRule]:
Expand Down
4 changes: 3 additions & 1 deletion dmoj/executors/base_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def __init__(
self,
problem_id: str,
source_code: bytes,
storage_namespace: Optional[str],
dest_dir: Optional[str] = None,
hints: Optional[List[str]] = None,
unbuffered: bool = False,
Expand All @@ -145,6 +146,7 @@ def __init__(
self._dir = None
self.problem = problem_id
self.source = source_code
self.storage_namespace = '' if storage_namespace is None else storage_namespace
self._hints = hints or []
self.unbuffered = unbuffered
self.meta: Dict[str, Any] = {}
Expand Down Expand Up @@ -381,7 +383,7 @@ def run_self_test(cls, output: bool = True, error_callback: Optional[Callable[[A
if output:
print_ansi(f'Self-testing #ansi[{cls.get_executor_name()}](|underline):'.ljust(39), end=' ')
try:
executor = cls(cls.test_name, utf8bytes(cls.test_program))
executor = cls(cls.test_name, utf8bytes(cls.test_program), None)
proc = executor.launch(
time=cls.test_time, memory=cls.test_memory, stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
Expand Down
9 changes: 6 additions & 3 deletions dmoj/executors/c_like_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class CLikeExecutor(SingleDigitVersionMixin, CompiledExecutor):

source_dict: Dict[str, bytes] = {}

def __init__(self, problem_id: str, source_code: bytes, **kwargs) -> None:
def __init__(self, problem_id: str, source_code: bytes, *args, **kwargs) -> None:
self.source_dict = kwargs.pop('aux_sources', {})
if source_code:
self.source_dict[problem_id + self.ext] = source_code
self.defines = kwargs.pop('defines', [])

super().__init__(problem_id, source_code, **kwargs)
super().__init__(problem_id, source_code, *args, **kwargs)

def create_files(self, problem_id: str, source_code: bytes, *args, **kwargs) -> None:
self.source_paths = []
Expand All @@ -51,7 +51,10 @@ def get_binary_cache_key(self) -> bytes:
command = self.get_command()
assert command is not None
key_components = (
[self.problem, command, self.get_march_flag()] + self.get_defines() + self.get_flags() + self.get_ldflags()
[self.storage_namespace, self.problem, command, self.get_march_flag()]
+ self.get_defines()
+ self.get_flags()
+ self.get_ldflags()
)
return utf8bytes(''.join(key_components)) + b''.join(self.source_dict.values())

Expand Down
6 changes: 3 additions & 3 deletions dmoj/executors/compiled_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class CompiledExecutor(BaseExecutor, metaclass=_CompiledExecutorMeta):
# 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)
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.warning = None
self._executable = None

Expand Down Expand Up @@ -213,7 +213,7 @@ def handle_compile_error(self, output: bytes) -> None:
raise CompileError(output)

def get_binary_cache_key(self) -> bytes:
return utf8bytes(self.problem) + self.source
return utf8bytes(self.storage_namespace) + utf8bytes(self.problem) + self.source

def compile(self) -> str:
process = self.create_compile_process(self.get_compile_args())
Expand Down
4 changes: 2 additions & 2 deletions dmoj/executors/java_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ class JavaExecutor(SingleDigitVersionMixin, CompiledExecutor):
jvm_regex: Optional[str] = None
_class_name: Optional[str]

def __init__(self, problem_id: str, source_code: bytes, **kwargs) -> None:
def __init__(self, problem_id: str, source_code: bytes, *args, **kwargs) -> None:
self._class_name = None
self._agent_file = JAVA_SANDBOX
self.source_dict = kwargs.pop('aux_sources', {})
if source_code:
self.source_dict[problem_id + '.' + self.ext] = source_code
super().__init__(problem_id, source_code, **kwargs)
super().__init__(problem_id, source_code, *args, **kwargs)

def get_compile_popen_kwargs(self) -> Dict[str, Any]:
return {'executable': utf8bytes(self.get_compiler())}
Expand Down
4 changes: 2 additions & 2 deletions dmoj/executors/script_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


class ScriptExecutor(BaseExecutor):
def __init__(self, problem_id: str, source_code: bytes, **kwargs) -> None:
super().__init__(problem_id, source_code, **kwargs)
def __init__(self, problem_id: str, source_code: bytes, *args, **kwargs) -> None:
super().__init__(problem_id, source_code, *args, **kwargs)
self._code = self._file(self.source_filename_format.format(problem_id=problem_id, ext=self.ext))
self.create_files(problem_id, source_code)

Expand Down
10 changes: 8 additions & 2 deletions dmoj/graders/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ def _generate_binary(self) -> BaseExecutor:
aux_sources[signature_data['header']] = header
entry = entry_point
return executors[self.language].Executor(
self.problem.id, entry, aux_sources=aux_sources, defines=['-DSIGNATURE_GRADER']
self.problem.id,
entry,
self.problem.storage_namespace,
aux_sources=aux_sources,
defines=['-DSIGNATURE_GRADER'],
)
elif self.language in java_siggraders:
aux_sources = {}
Expand All @@ -218,7 +222,9 @@ def _generate_binary(self) -> BaseExecutor:
entry = self.source
aux_sources[self.problem.id + '_lib'] = entry_point

return executors[self.language].Executor(self.problem.id, entry, aux_sources=aux_sources)
return executors[self.language].Executor(
self.problem.id, entry, self.problem.storage_namespace, aux_sources=aux_sources
)
else:
raise InternalError('no valid runtime for signature grading %s found' % self.language)

Expand Down
10 changes: 8 additions & 2 deletions dmoj/graders/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def _generate_binary(self) -> BaseExecutor:
aux_sources[handler_data['header']] = header
entry = entry_point
return executors[self.language].Executor(
self.problem.id, entry, aux_sources=aux_sources, defines=['-DSIGNATURE_GRADER']
self.problem.id,
entry,
self.problem.storage_namespace,
aux_sources=aux_sources,
defines=['-DSIGNATURE_GRADER'],
)
elif self.language in java_siggraders:
aux_sources = {}
Expand All @@ -43,6 +47,8 @@ def _generate_binary(self) -> BaseExecutor:
entry = self.source
aux_sources[self.problem.id + '_lib'] = entry_point

return executors[self.language].Executor(self.problem.id, entry, aux_sources=aux_sources)
return executors[self.language].Executor(
self.problem.id, entry, self.problem.storage_namespace, aux_sources=aux_sources
)
else:
raise InternalError('no valid runtime for signature grading %s found' % self.language)
1 change: 1 addition & 0 deletions dmoj/graders/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def _generate_binary(self) -> BaseExecutor:
return executors[self.language].Executor(
self.problem.id,
self.source,
self.problem.storage_namespace,
hints=self.problem.config.hints or [],
unbuffered=self.problem.config.unbuffered,
meta=self.problem.config.meta or {},
Expand Down

0 comments on commit 11d6e22

Please sign in to comment.