def test_languages(self): # All languages are described. for lang in LANGUAGES: assert lang in LANGUAGE_NAMES assert lang in LANGUAGE_TO_SOURCE_EXT_MAP # This isn't true, as not all languages need headers. # assert lang in LANGUAGE_TO_HEADER_EXT_MAP # All default languages are languages. for lang in DEFAULT_LANGUAGES: assert lang in LANGUAGES # All keys are languages. for lang in LANGUAGE_TO_SOURCE_EXT_MAP.iterkeys(): assert lang in LANGUAGES for lang in LANGUAGE_TO_HEADER_EXT_MAP.iterkeys(): assert lang in LANGUAGES # All values are languages. for lang in SOURCE_EXT_TO_LANGUAGE_MAP.itervalues(): assert lang in LANGUAGES # Extensions are sane. for lang in LANGUAGES: assert LANGUAGE_TO_SOURCE_EXT_MAP[lang][0] == "." assert lang == \ SOURCE_EXT_TO_LANGUAGE_MAP[LANGUAGE_TO_SOURCE_EXT_MAP[lang]] for ext in SOURCE_EXT_TO_LANGUAGE_MAP: assert ext[0] == "."
def compile(self, job, file_cacher): """See TaskType.compile.""" # Detect the submission's language. The checks about the # formal correctedness of the submission are done in CWS, # before accepting it. language = job.language source_ext = LANGUAGE_TO_SOURCE_EXT_MAP[language] # Create the sandbox sandbox = create_sandbox(file_cacher) job.sandboxes.append(sandbox.path) # Prepare the source files in the sandbox files_to_get = {} source_filenames = [] # Stub. stub_filename = "stub%s" % source_ext source_filenames.append(stub_filename) files_to_get[stub_filename] = job.managers[stub_filename].digest # User's submission. for filename, fileinfo in job.files.iteritems(): source_filename = filename.replace(".%l", source_ext) source_filenames.append(source_filename) files_to_get[source_filename] = fileinfo.digest # Also copy all managers that might be useful during compilation. for filename in job.managers.iterkeys(): if any(filename.endswith(header) for header in LANGUAGE_TO_HEADER_EXT_MAP.itervalues()): files_to_get[filename] = \ job.managers[filename].digest elif any(filename.endswith(source) for source in LANGUAGE_TO_SOURCE_EXT_MAP.itervalues()): files_to_get[filename] = \ job.managers[filename].digest elif any(filename.endswith(obj) for obj in LANGUAGE_TO_OBJ_EXT_MAP.itervalues()): files_to_get[filename] = \ job.managers[filename].digest for filename, digest in files_to_get.iteritems(): sandbox.create_file_from_storage(filename, digest) # Prepare the compilation command executable_filename = \ "_".join(pattern.replace(".%l", "") for pattern in job.files.keys()) commands = get_compilation_commands(language, source_filenames, executable_filename) # Run the compilation operation_success, compilation_success, text, plus = \ compilation_step(sandbox, commands) # Retrieve the compiled executables job.success = operation_success job.compilation_success = compilation_success job.plus = plus job.text = text if operation_success and compilation_success: digest = sandbox.get_file_to_storage( executable_filename, "Executable %s for %s" % (executable_filename, job.info)) job.executables[executable_filename] = \ Executable(executable_filename, digest) # Cleanup delete_sandbox(sandbox)
def compile(self, job, file_cacher): """See TaskType.compile.""" # Detect the submission's language. The checks about the # formal correctedness of the submission are done in CWS, # before accepting it. language = job.language source_ext = LANGUAGE_TO_SOURCE_EXT_MAP[language] # TODO: here we are sure that submission.files are the same as # task.submission_format. The following check shouldn't be # here, but in the definition of the task, since this actually # checks that task's task type and submission format agree. if len(job.files) != 1: job.success = True job.compilation_success = False job.text = [N_("Invalid files in submission")] logger.error("Submission contains %d files, expecting 1", len(job.files), extra={"operation": job.info}) return True # Create the sandbox sandbox = create_sandbox(file_cacher) job.sandboxes.append(sandbox.path) # Prepare the source files in the sandbox files_to_get = {} format_filename = job.files.keys()[0] source_filenames = [] # Stub. source_filenames.append("stub%s" % source_ext) files_to_get[source_filenames[-1]] = \ job.managers["stub%s" % source_ext].digest # User's submission. source_filenames.append(format_filename.replace(".%l", source_ext)) files_to_get[source_filenames[-1]] = \ job.files[format_filename].digest # Also copy all managers that might be useful during compilation. for filename in job.managers.iterkeys(): if any( filename.endswith(header) for header in LANGUAGE_TO_HEADER_EXT_MAP.itervalues()): files_to_get[filename] = \ job.managers[filename].digest elif any( filename.endswith(source) for source in LANGUAGE_TO_SOURCE_EXT_MAP.itervalues()): files_to_get[filename] = \ job.managers[filename].digest elif any( filename.endswith(obj) for obj in LANGUAGE_TO_OBJ_EXT_MAP.itervalues()): files_to_get[filename] = \ job.managers[filename].digest for filename, digest in files_to_get.iteritems(): sandbox.create_file_from_storage(filename, digest) # Prepare the compilation command executable_filename = format_filename.replace(".%l", "") commands = get_compilation_commands(language, source_filenames, executable_filename) # Run the compilation operation_success, compilation_success, text, plus = \ compilation_step(sandbox, commands) # Retrieve the compiled executables job.success = operation_success job.compilation_success = compilation_success job.plus = plus job.text = text if operation_success and compilation_success: digest = sandbox.get_file_to_storage( executable_filename, "Executable %s for %s" % (executable_filename, job.info)) job.executables[executable_filename] = \ Executable(executable_filename, digest) # Cleanup delete_sandbox(sandbox)
def compile(self, job, file_cacher): """See TaskType.compile.""" # Detect the submission's language. The checks about the # formal correctedness of the submission are done in CWS, # before accepting it. language = job.language source_ext = LANGUAGE_TO_SOURCE_EXT_MAP[language] # TODO: here we are sure that submission.files are the same as # task.submission_format. The following check shouldn't be # here, but in the definition of the task, since this actually # checks that task's task type and submission format agree. if len(job.files) != 1: job.success = True job.compilation_success = False job.text = [N_("Invalid files in submission")] logger.error("Submission contains %d files, expecting 1", len(job.files), extra={"operation": job.info}) return True # Create the sandbox sandbox = create_sandbox(file_cacher) job.sandboxes.append(sandbox.path) # Prepare the source files in the sandbox files_to_get = {} format_filename = job.files.keys()[0] source_filenames = [] # Stub. source_filenames.append("stub%s" % source_ext) files_to_get[source_filenames[-1]] = job.managers["stub%s" % source_ext].digest # User's submission. source_filenames.append(format_filename.replace(".%l", source_ext)) files_to_get[source_filenames[-1]] = job.files[format_filename].digest # Also copy all managers that might be useful during compilation. # We likely want to compile with .cpp or .o files, so add them to our # command line for filename in job.managers.iterkeys(): if any(filename.endswith(header) for header in LANGUAGE_TO_HEADER_EXT_MAP.itervalues()): files_to_get[filename] = job.managers[filename].digest elif any(filename.endswith(source) for source in LANGUAGE_TO_SOURCE_EXT_MAP.itervalues()): files_to_get[filename] = job.managers[filename].digest if filename not in source_filenames: source_filenames.insert(1, filename) elif any(filename.endswith(obj) for obj in LANGUAGE_TO_OBJ_EXT_MAP.itervalues()): files_to_get[filename] = job.managers[filename].digest if filename not in source_filenames: source_filenames.insert(1, filename) for filename, digest in files_to_get.iteritems(): sandbox.create_file_from_storage(filename, digest) # Prepare the compilation command executable_filename = format_filename.replace(".%l", "") commands = get_compilation_commands(language, source_filenames, executable_filename) # Run the compilation operation_success, compilation_success, text, plus = compilation_step(sandbox, commands) # Retrieve the compiled executables job.success = operation_success job.compilation_success = compilation_success job.plus = plus job.text = text if operation_success and compilation_success: digest = sandbox.get_file_to_storage( executable_filename, "Executable %s for %s" % (executable_filename, job.info) ) job.executables[executable_filename] = Executable(executable_filename, digest) # Cleanup delete_sandbox(sandbox)
def compile(self, job, file_cacher): """See TaskType.compile.""" # Detect the submission's language. The checks about the # formal correctedness of the submission are done in CWS, # before accepting it. language = job.language source_ext = LANGUAGE_TO_SOURCE_EXT_MAP[language] # Create the sandbox sandbox = create_sandbox(file_cacher) job.sandboxes.append(sandbox.path) # Prepare the source files in the sandbox files_to_get = {} source_filenames = [] # Stub. stub_filename = "stub%s" % source_ext source_filenames.append(stub_filename) files_to_get[stub_filename] = job.managers[stub_filename].digest # User's submission. for filename, fileinfo in job.files.iteritems(): source_filename = filename.replace(".%l", source_ext) source_filenames.append(source_filename) files_to_get[source_filename] = fileinfo.digest # Also copy all managers that might be useful during compilation. for filename in job.managers.iterkeys(): if any( filename.endswith(header) for header in LANGUAGE_TO_HEADER_EXT_MAP.itervalues()): files_to_get[filename] = \ job.managers[filename].digest elif any( filename.endswith(source) for source in LANGUAGE_TO_SOURCE_EXT_MAP.itervalues()): files_to_get[filename] = \ job.managers[filename].digest elif any( filename.endswith(obj) for obj in LANGUAGE_TO_OBJ_EXT_MAP.itervalues()): files_to_get[filename] = \ job.managers[filename].digest for filename, digest in files_to_get.iteritems(): sandbox.create_file_from_storage(filename, digest) # Prepare the compilation command executable_filename = \ "_".join(pattern.replace(".%l", "") for pattern in job.files.keys()) commands = get_compilation_commands(language, source_filenames, executable_filename) # Run the compilation operation_success, compilation_success, text, plus = \ compilation_step(sandbox, commands) # Retrieve the compiled executables job.success = operation_success job.compilation_success = compilation_success job.plus = plus job.text = text if operation_success and compilation_success: digest = sandbox.get_file_to_storage( executable_filename, "Executable %s for %s" % (executable_filename, job.info)) job.executables[executable_filename] = \ Executable(executable_filename, digest) # Cleanup delete_sandbox(sandbox)