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 713d7f7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions dmoj/executors/base_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class BaseExecutor(metaclass=ExecutorMeta):
def __init__(
self,
problem_id: str,
storage_namespace: Optional[str],
source_code: bytes,
dest_dir: Optional[str] = None,
hints: Optional[List[str]] = None,
Expand All @@ -144,6 +145,7 @@ def __init__(
self._tempdir = dest_dir or env.tempdir
self._dir = None
self.problem = problem_id
self.storage_namespace = '' if storage_namespace is None else storage_namespace
self.source = source_code
self._hints = hints or []
self.unbuffered = unbuffered
Expand Down
5 changes: 4 additions & 1 deletion dmoj/executors/c_like_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion dmoj/executors/compiled_executor.py
Original file line number Diff line number Diff line change
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
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,
self.problem.storage_namespace,
entry,
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, self.problem.storage_namespace, entry, 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,
self.problem.storage_namespace,
entry,
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, self.problem.storage_namespace, entry, 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 @@ -109,6 +109,7 @@ def _interact_with_process(self, case: TestCase, result: Result, input: bytes) -
def _generate_binary(self) -> BaseExecutor:
return executors[self.language].Executor(
self.problem.id,
self.problem.storage_namespace,
self.source,
hints=self.problem.config.hints or [],
unbuffered=self.problem.config.unbuffered,
Expand Down

0 comments on commit 713d7f7

Please sign in to comment.