Package qm :: Package test :: Package classes :: Module compiler :: Class Compiler
[hide private]
[frames] | no frames]

Class Compiler

source code

A 'Compiler' compiles and links source files.

Instance Methods [hide private]
 
__init__(self, path, options=None, ldflags=None)
Construct a new 'Compiler'.
source code
 
Compile(self, mode, files, dir, options=[], ldflags=[], output=None, timeout=-1)
Compile the 'files'.
source code
 
ExecuteCommand(self, dir, command, timeout=-1)
Execute 'command' in 'dir'.
source code
 
GetCompilationCommand(self, mode, files, options=[], ldflags=[], output=None)
Return the appropriate command for compiling 'files'.
source code
 
ParseOutput(self, output, ignore_regexps=())
Turn the 'output' into a sqeuence of 'Diagnostic's.
source code
 
GetPath(self)
Return the location of the executable.
source code
 
GetOptions(self)
Return the list of compilation options.
source code
 
SetOptions(self, options)
Reset the list of compiler options.
source code
 
GetLDFlags(self)
Return the list of link options.
source code
 
SetLDFlags(self, ldflags)
Reset the list of link options.
source code
 
GetExecutableExtension(self)
Return the extension for executables.
source code
 
GetObjectExtension(self)
Return the extension for object files.
source code
 
_GetModeSwitches(self, mode)
Return the compilation switches for the compilation 'mode'.
source code
Class Variables [hide private]
  MODE_PREPROCESS = 'preprocess'
Preprocess the source files, but do not compile them.
  MODE_COMPILE = 'compile'
Compile the source files, but do not assemble them.
  MODE_ASSEMBLE = 'assemble'
Compile the source files, but do not link them.
  MODE_LINK = 'link'
Compile and link the source files.
  modes = [MODE_COMPILE, MODE_ASSEMBLE, MODE_LINK, MODE_PREPROCESS]
The available compilation modes.
Method Details [hide private]

__init__(self, path, options=None, ldflags=None)
(Constructor)

source code 

Construct a new 'Compiler'.

'path' -- A string giving the location of the compiler executable.

'options' -- A list of strings indicating options to the compiler, or 'None' if there are no options.

'ldflags' -- A list of strings indicating ld flags to the compiler, or 'None' if there are no flags.

Compile(self, mode, files, dir, options=[], ldflags=[], output=None, timeout=-1)

source code 

Compile the 'files'.

'mode' -- The compilation mode (one of the 'Compiler.modes') that should be used to compile the 'files'.

'files' -- A sequence of strings giving the names of source files (including, in general, assembly files, object files, and libraries) that should be compiled.

'dir' -- The directory in which to run the compiler.

'options' -- A sequence of strings indicating additional options that should be provided to the compiler.

'ldflags' -- A sequence of strings indicating additional linker flags that should be provided to the compiler, if linking is done.

'output' -- The name of the file should be created by the compilation. If 'None', the compiler will use a default value.

'timeout' -- The maximum number of seconds the compiler is permitted to run. If 'timeout' is -1, the compiler is permitted to run forever.

returns -- A tuple '(status, output)'. The 'status' is the exit status returned by the compiler, as indicated by 'waitpid'. The 'output' is a string containing the standard outpt and standard errror generated by the compiler.

ExecuteCommand(self, dir, command, timeout=-1)

source code 

Execute 'command' in 'dir'.

'dir' -- The directory in which to execute the command.

'command' -- A sequence of strings, as returned by 'GetCompilationCommand'.

'timeout' -- The maximum number of seconds the compiler is permitted to run. If 'timeout' is -1, the compiler is permitted to run forever.

returns -- A tuple '(status, output)'. The 'status' is the exit status returned by the compiler, as indicated by 'waitpid'. The 'output' is a string containing the standard output and standard errror generated by the compiler.

GetCompilationCommand(self, mode, files, options=[], ldflags=[], output=None)

source code 

Return the appropriate command for compiling 'files'.

'mode' -- The compilation mode (one of the 'Compiler.modes') that should be used to compile the 'files'.

'files' -- A sequence of strings giving the names of source files (including, in general, assembly files, object files, and libraries) that should be compiled.

'options' -- A sequence of strings indicating additional options that should be provided to the compiler.

'ldflags' -- A sequence of strings indicating additional linker flags that should be provided to the compiler, if linking is done.

'output' -- The name of the file should be created by the compilation. If 'None', the compiler will use a default value. (In some cases there may be multiple outputs. For example, when generating multiple object files from multiple source files, the compiler will create a variety of objects.)

returns -- A sequence of strings indicating the arguments, including 'argv[0]', for the compilation command.

ParseOutput(self, output, ignore_regexps=())

source code 

Turn the 'output' into a sqeuence of 'Diagnostic's.

'output' -- A string containing the compiler's output.

'ignore_regexps' -- A sequence of regular expressions. If a diagnostic message matches one of these regular expressions, it will be ignored.

returns -- A list of 'Diagnostic's corresponding to the messages indicated in 'output', in the order that they were emitted.

GetPath(self)

source code 

Return the location of the executable.

returns -- A string giving the location of the executable. This location is the one that was specified as the 'path' argument to '__init__'.

GetOptions(self)

source code 

Return the list of compilation options.

returns -- A list of strings giving the compilation options specified when the 'Compiler' was constructed.

SetOptions(self, options)

source code 

Reset the list of compiler options.

'options' -- A list of strings indicating options to the compiler, or 'None' if there are no options.

GetLDFlags(self)

source code 

Return the list of link options.

returns -- A list of strings giving the link options specified when the 'Compiler' was constructed.

SetLDFlags(self, ldflags)

source code 

Reset the list of link options.

'ldflags' -- A list of strings indicating options to the linker, or 'None' if there are no flags.

GetExecutableExtension(self)

source code 

Return the extension for executables.

returns -- The extension (including leading '.', if applicable) for executable files created by this compiler.

GetObjectExtension(self)

source code 

Return the extension for object files.

returns -- The extension (including leading '.', if applicable) for object files created by this compiler.

_GetModeSwitches(self, mode)

source code 

Return the compilation switches for the compilation 'mode'.

'mode' -- The compilation mode (one of 'Compiler.modes').

returns -- A sequence of strings indicating the switches that are used to indicate the compilation mode.