parameters: (function)
docstring: Implements compiler wrapper base functionality.
  
      A compiler wrapper executes the real compiler, then implement some
      functionality, then returns with the real compiler exit code.
  
      :param function: the extra functionality what the wrapper want to
      do on top of the compiler call. If it throws exception, it will be
      caught and logged.
      :return: the exit code of the real compiler.
  
      The :param function: will receive the following arguments:
  
      :param result:       the exit code of the compilation.
      :param execution:    the command executed by the wrapper.
docstring_summary: Implements compiler wrapper base functionality.
docstring_tokens: Implements compiler wrapper base functionality .
function: def compiler_wrapper(function):
      """ Implements compiler wrapper base functionality.
  
      A compiler wrapper executes the real compiler, then implement some
      functionality, then returns with the real compiler exit code.
  
      :param function: the extra functionality what the wrapper want to
      do on top of the compiler call. If it throws exception, it will be
      caught and logged.
      :return: the exit code of the real compiler.
  
      The :param function: will receive the following arguments:
  
      :param result:       the exit code of the compilation.
      :param execution:    the command executed by the wrapper. """
  
      def is_cxx_compiler():
          """ Find out was it a C++ compiler call. Compiler wrapper names
          contain the compiler type. C++ compiler wrappers ends with `c++`,
          but might have `.exe` extension on windows. """
  
          wrapper_command = os.path.basename(sys.argv[0])
          return re.match(r'(.+)c\+\+(.*)', wrapper_command)
  
      def run_compiler(executable):
          """ Execute compilation with the real compiler. """
  
          command = executable + sys.argv[1:]
          logging.debug('compilation: %s', command)
          result = subprocess.call(command)
          logging.debug('compilation exit code: %d', result)
          return result
  
      # Get relevant parameters from environment.
      parameters = json.loads(os.environ[ENVIRONMENT_KEY])
      reconfigure_logging(parameters['verbose'])
      # Execute the requested compilation. Do crash if anything goes wrong.
      cxx = is_cxx_compiler()
      compiler = parameters['cxx'] if cxx else parameters['cc']
      result = run_compiler(compiler)
      # Call the wrapped method and ignore it's return value.
      try:
          call = Execution(
              pid=os.getpid(),
              cwd=os.getcwd(),
              cmd=['c++' if cxx else 'cc'] + sys.argv[1:])
          function(result, call)
      except:
          logging.exception('Compiler wrapper failed complete.')
      finally:
          # Always return the real compiler exit code.
          return result
function_tokens: def compiler_wrapper ( function ) : def is_cxx_compiler ( ) : """ Find out was it a C++ compiler call. Compiler wrapper names
          contain the compiler type. C++ compiler wrappers ends with `c++`,
          but might have `.exe` extension on windows. """ wrapper_command = os . path . basename ( sys . argv [ 0 ] ) return re . match ( r'(.+)c\+\+(.*)' , wrapper_command ) def run_compiler ( executable ) : """ Execute compilation with the real compiler. """ command = executable + sys . argv [ 1 : ] logging . debug ( 'compilation: %s' , command ) result = subprocess . call ( command ) logging . debug ( 'compilation exit code: %d' , result ) return result # Get relevant parameters from environment. parameters = json . loads ( os . environ [ ENVIRONMENT_KEY ] ) reconfigure_logging ( parameters [ 'verbose' ] ) # Execute the requested compilation. Do crash if anything goes wrong. cxx = is_cxx_compiler ( ) compiler = parameters [ 'cxx' ] if cxx else parameters [ 'cc' ] result = run_compiler ( compiler ) # Call the wrapped method and ignore it's return value. try : call = Execution ( pid = os . getpid ( ) , cwd = os . getcwd ( ) , cmd = [ 'c++' if cxx else 'cc' ] + sys . argv [ 1 : ] ) function ( result , call ) except : logging . exception ( 'Compiler wrapper failed complete.' ) finally : # Always return the real compiler exit code. return result