compiler_cmdline()   D
last analyzed

Complexity

Conditions 9

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 4.7088
cc 9
1
'''
2
Functions dealing with the compilation of code.
3
'''
4
5
from .exceptions import ValidatorBrokenException
6
7
import logging
8
logger = logging.getLogger('opensubmitexec')
9
10
GCC = ['gcc', '-o', '{output}', '{inputs}']
11
GPP = ['g++', '-pthread', '-o', '{output}', '{inputs}']
12
13
14
def compiler_cmdline(compiler=GCC, output=None, inputs=None):
15
    cmdline = []
16
    for element in compiler:
17
        if element == '{output}':
18
            if output:
19
                cmdline.append(output)
20
            else:
21
                logger.error('Compiler output name is needed, but not given.')
22
                raise ValidatorBrokenException("You need to declare the output name for this compiler.")
23
        elif element == '{inputs}':
24
            if inputs:
25
                for fname in inputs:
26
                    if compiler in [GCC, GPP] and fname.endswith('.h'):
27
                        logger.debug('Omitting {0} in the compiler call.'.format(fname))
28
                    else:
29
                        cmdline.append(fname)
30
            else:
31
                logger.error('Input file names for compiler are not given.')
32
                raise ValidatorBrokenException('You need to declare input files for this compiler.')
33
        else:
34
            cmdline.append(element)
35
    return cmdline[0], cmdline[1:]
36