def _compile(self): cmd = self._compile_cmd if not cmd: return self.request.result.compilation.status = ExecutorStatus.RUNNING self.request.event_compile.open_event.trigger(self.request.result.compilation) out = self.temp_dir / '.compile.log' logger.opt(ansi=True).info('<red>{}</red>: {}', 'COMPILING', cmd) with self.executor.set_streams(stdin=None, stdout=out, stderr=out) as ex: result = ex.run(cmd, Env.compile_timeout) self.request.result.compilation = add_cmd_to_result(result).register(ExecutorResult.COMPILATION) if result.failed(): if result.status is ExecutorStatus.GLOBAL_TIMEOUT: raise CompileException('Compilation was interrupted (did not finish in time)', details=result.read_stdout()) else: result.status = ExecutorStatus.COMPILATION_FAILED raise CompileException('Compilation failed', details=result.read_stdout()) self.request.event_compile.close_event.trigger(self.request.result.compilation) return result
def runCommandWithFlags(self): new_cmd = [self.name] + ADDED_FLAGS.split() + self.parameters try: cmdOutput = subprocess.run(' '.join(new_cmd), shell=True, check=True) except Exception as e: prRed(e) raise CompileException(new_cmd) from e
def compileInstrumentedFile(self): source = self.getCodeFileNameIfExists() # Copy original command new_cmd = [COMPILER_NAME, '-include', FPCHECKER_RUNTIME ] + self.parameters # Replace file by instrumented file for i in range(len(new_cmd)): p = new_cmd[i] if p == source: new_cmd[i] = self.instrumentedFile break # Change output file if not self.outputFile: fileName, ext = os.path.splitext(source) newOutputFile = fileName + '.o' new_cmd = new_cmd + ['-o', newOutputFile] # Compile try: if verbose(): prGreen('Compiling: ' + ' '.join(new_cmd)) cmdOutput = subprocess.run(' '.join(new_cmd), shell=True, check=True) except Exception as e: if verbose(): prRed(e) logMessage(str(e)) message = 'Could not compile instrumented file' logMessage(message) raise CompileException(message) from e
def take(self, token): if token.word == 'then': return False elif token.word == 'else': if not self.inbody: raise CompileException('Already in else block') self.inbody = False elif self.inbody: self.body.append(token) else: self.el.append(token) return True
def _compile_raw(cls, request: ProcessRequest, pipeline: list, executor: LocalExecutor, out_dir: typing.Union[str, pathlib.Path]): if not pipeline: return result_id = 'compilation' request._compile_result = ExecutorResult.empty_result( result_id, ExecutorStatus.RUNNING) request.event_compile.open_event.trigger(request, request._compile_result) inn = None out = pathlib.Path(out_dir).joinpath('.compile.log') err = subprocess.STDOUT cmd = pipeline logger.opt(ansi=True).info('<red>{}</red>: {}', 'COMPILING', cmd) with executor.set_streams(stdin=inn, stdout=out, stderr=err) as ex: result = ex.run(cmd) request._compile_result = add_cmd_to_result(result_id, result).register(result_id) if result.failed(): if result.status is ExecutorStatus.GLOBAL_TIMEOUT: raise CompileException( 'Compilation was interrupted (did not finish in time)', details=result.stdout) else: result.status = ExecutorStatus.COMPILATION_FAILED raise CompileException('Compilation failed', details=result.stdout) request.event_compile.close_event.trigger(request, request._compile_result) return result
def take(self, token): if not self.name: if token.isstringliteral: raise CompileException('Expected name, not string') self.name = token.word else: if token.word == 'if': self.tree = IfBlock(self.tree) elif token.word == 'do': self.tree = DoBlock(self.tree) elif token.word == 'begin': self.tree = BeginBlock(self.tree) elif self.tree: if not self.tree.take(token): if self.tree.parent: self.tree.finish() else: self.code.append(self.tree.finish()) self.tree = self.tree.parent else: self.code.append(token)
def error(self, expected_token): raise CompileException( '[Line: {}] Parsing error. Current token ({}) is not valid. Expected token should be: {} ' .format(self.lexer.line_counter, self.current_token, expected_token))
def error_message(self, line, message): raise CompileException(f"[Line: {line}] {message}")