Exemplo n.º 1
0
    def Compile(self, *args, **kwargs):
        """Fail if the script is missing a shebang line."""
        try:
            interpreter = self.run_args[0]
        except IOError:
            yield codes.RunResult('File not found', None)
        if not interpreter:
            yield codes.RunResult('Script missing a shebang line', None)
        if not os.path.exists(interpreter):
            yield codes.RunResult('Interpreter not found: %s' % interpreter,
                                  None)

        # when using env, try to output more detailed error message
        if interpreter == '/bin/env' or interpreter == '/usr/bin/env':
            try:
                # if the command does not exist,
                # "which" return 1 as the status code
                interpreter = subprocess.check_output(
                    ['which', self.run_args[1]]).strip()
            except subprocess.CalledProcessError:
                yield codes.RunResult(
                    'Interpreter not installed: %s' % self.run_args[1], None)
            if not os.path.exists(interpreter):
                yield codes.RunResult(
                    'Interpreter not found: %s' % interpreter, None)

        yield (yield basic_codes.CodeBase.Compile(self, *args, **kwargs))
Exemplo n.º 2
0
 def Run(self, args, cwd, input, output, timeout, precise,
         redirect_error=False):
     parser = optparse.OptionParser()
     parser.add_option('-i', '--infile', dest='infile')
     parser.add_option('-d', '--difffile', dest='difffile')
     parser.add_option('-o', '--outfile', dest='outfile')
     (options, pos_args) = parser.parse_args([''] + list(args))
     run_args = ('diff', '-u', options.difffile, options.outfile)
     with open(input, 'r') as infile:
         with open(output, 'w') as outfile:
             if redirect_error:
                 errfile = subprocess.STDOUT
             else:
                 errfile = files.OpenNull()
             task = taskgraph.ExternalProcessTask(
                 run_args, cwd=cwd, stdin=infile, stdout=outfile,
                 stderr=errfile, timeout=timeout)
             try:
                 proc = yield task
             except OSError:
                 yield codes.RunResult(codes.RunResult.RE, None)
             ret = proc.returncode
             if ret == 0:
                 yield codes.RunResult(codes.RunResult.OK, task.time)
             if ret > 0:
                 yield codes.RunResult(codes.RunResult.NG, None)
             yield codes.RunResult(codes.RunResult.RE, None)
Exemplo n.º 3
0
 def Compile(self):
   """Compile the code and return RunResult."""
   try:
     if not self.compile_args:
       result = codes.RunResult(codes.RunResult.OK, None)
     else:
       result = yield self._ExecForCompile(args=self.compile_args)
   except Exception, e:
     result = codes.RunResult('On compiling: %s' % e, None)
Exemplo n.º 4
0
 def Compile(self, *args, **kwargs):
   """Fail if the script is missing a shebang line."""
   try:
     with open(os.path.join(self.src_dir, self.src_name)) as f:
       header = f.read(2)
   except IOError:
     yield codes.RunResult('File not found', None)
   if header != '#!':
     yield codes.RunResult('Script missing a shebang line', None)
   yield (yield super(ScriptCode, self).Compile(*args, **kwargs))
Exemplo n.º 5
0
 def Compile(self, *args, **kwargs):
     """Fail if the script is missing a shebang line."""
     try:
         interpreter = self._ReadAndParseShebangLine()
     except IOError:
         yield codes.RunResult('File not found', None)
     if not interpreter:
         yield codes.RunResult('Script missing a shebang line', None)
     if not os.path.exists(interpreter):
         yield codes.RunResult('Interpreter not found: %s' % interpreter,
                               None)
     yield (yield super(ScriptCode, self).Compile(*args, **kwargs))
Exemplo n.º 6
0
 def Compile(self):
     """Compile the code and return RunResult."""
     if self.testlib is not None:
         files.CopyFile(os.path.join(self.src_dir, self.testlib),
                        os.path.join(self.out_dir, 'testlib.h'))
     try:
         if not self.compile_args:
             result = codes.RunResult(codes.RunResult.OK, None)
         else:
             result = yield self._ExecForCompile(args=self.compile_args)
     except Exception as e:
         result = codes.RunResult('On compiling: %s' % e, None)
     yield result
Exemplo n.º 7
0
 def Compile(self, *args, **kwargs):
     """Fail if the script is missing a shebang line."""
     try:
         open(os.path.join(self.src_dir, self.src_name))
     except IOError:
         yield codes.RunResult('File not found', None)
     yield (yield super(JavaScriptCode, self).Compile(*args, **kwargs))
Exemplo n.º 8
0
 def Run(self, args, cwd, input, output, timeout, precise, redirect_error=False):
   """Run the code and return RunResult."""
   try:
     result = yield self._ExecForRun(
       args=tuple(list(self.run_args)+list(args)), cwd=cwd,
       input=input, output=output, timeout=timeout, precise=precise,
       redirect_error=redirect_error)
   except Exception, e:
     result = codes.RunResult('On execution: %s' % e, None)
Exemplo n.º 9
0
def _ExecInternal(self,
                  args,
                  cwd,
                  stdin,
                  stdout,
                  stderr,
                  timeout=None,
                  precise=False):
    task = taskgraph.ExternalProcessTask(args,
                                         cwd=cwd,
                                         stdin=stdin,
                                         stdout=stdout,
                                         stderr=stderr,
                                         timeout=timeout,
                                         exclusive=precise)
    proc = yield task
    code = proc.returncode
    # Retry if TLE.
    if not precise and code == -(signal.SIGXCPU):
        self._ResetIO(stdin, stdout, stderr)
        task = taskgraph.ExternalProcessTask(args,
                                             cwd=cwd,
                                             stdin=stdin,
                                             stdout=stdout,
                                             stderr=stderr,
                                             timeout=timeout,
                                             exclusive=precise)
        proc = yield task
        code = proc.returncode
    if code == 0:
        status = codes.RunResult.OK
    elif code == -(signal.SIGXCPU):
        status = codes.RunResult.TLE
    elif code < 0:
        status = codes.RunResult.RE
    else:
        status = codes.RunResult.NG
    yield codes.RunResult(status, task.time)