def test_parse_with_non_build_cmd_entries():
    pwd = getcwd()
    build_log = [
        'random build log message..\n',
        'gcc -c valid.c\n',
        'some other random build log message with g++ or gcc included.\n',
        '\n',
        '',
        'g++ -c valid2.cc\n',
    ]
    # These ones will reach the bashlex parsing code and
    # would generate a parsing exception
    # https://github.com/nickdiego/compiledb-generator/issues/38
    build_log += [
        'checking for gcc... (cached) gcc\n',
        'checking whether gcc accepts -g... (cached) yes\n'
    ]
    result = parse_build_log(build_log,
                             proj_dir=pwd,
                             inc_prefix=None,
                             exclude_list=[],
                             verbose=False)

    assert result.count == 2
    assert result.skipped == 6
    assert len(result.compdb) == 2
    assert result.compdb == [{
        'directory': pwd,
        'file': 'valid.c',
        'arguments': ['cc', '-c', 'valid.c']
    }, {
        'directory': pwd,
        'file': 'valid2.cc',
        'arguments': ['c++', '-c', 'valid2.cc']
    }]
Exemple #2
0
def test_automake_command():
    pwd = getcwd()
    with input_file('autotools_simple') as build_log:
        result = parse_build_log(
            build_log,
            proj_dir=pwd,
            exclude_files=[],
            verbose=False)

    assert result.count == 1
    assert result.skipped == 0
    assert len(result.compdb) == 1
    assert result.compdb[0] == {
        'directory': pwd,
        'file': './main.c',
        'command': ' '.join([
            'gcc',
            '-DPACKAGE_NAME="hello"',
            '-DPACKAGE_VERSION="1.0.0"',
            '-DSTDC_HEADERS=1',
            '-I.',
            '-I../../src/libhello',
            '-c',
            '-o', 'hello_world1-main.o',
            './main.c'
        ])
    }
Exemple #3
0
def test_build_commands_with_wrapper():
    pwd = getcwd()
    build_log = [
        'ccache gcc -o hello.o -c hello.c\n'
        'icecc clang++ -c somefile.cpp\n'
        'icecc ccache arm1999-gnu-etc-g++ -c main.cpp -o main.o\n'
        'unknown-wrapper g++ -c main.cpp -o main.o\n'
    ]
    result = parse_build_log(
        build_log,
        proj_dir=pwd,
        exclude_files=[],
        verbose=True)

    assert result.count == 4
    assert result.skipped == 0
    assert len(result.compdb) == 4
    assert result.compdb == [{
        'directory': pwd,
        'file': 'hello.c',
        'command': 'gcc -o hello.o -c hello.c'
    }, {
        'directory': pwd,
        'file': 'somefile.cpp',
        'command': 'clang++ -c somefile.cpp'
    }, {
        'directory': pwd,
        'file': 'main.cpp',
        'command': 'arm1999-gnu-etc-g++ -c main.cpp -o main.o'
    }, {
        'directory': pwd,
        'file': 'main.cpp',
        'command': 'g++ -c main.cpp -o main.o'
    }]
Exemple #4
0
def test_multiple_commands_per_line_command_style():
    """Test the command_style option using the multiple_commands_oneline.txt build log.
    """
    cwd = getcwd()

    with input_file('multiple_commands_oneline.txt') as build_log:
        result = parse_build_log(
            build_log,
            proj_dir=cwd,
            exclude_files=[],
            command_style=True,
        )

    assert result.count == 2
    assert result.skipped == 0
    assert result.compdb == [
        {
            'command': 'g++ -c ./path/src/hein.cpp -o out.o',
            'directory': cwd,
            'file': './path/src/hein.cpp',
        },
        {
            'command': 'gcc -c -o main.o main.c',
            'directory': cwd,
            'file': 'main.c',
        }
    ]
Exemple #5
0
def generate_json_compdb(instream=None, proj_dir=os.getcwd(), verbose=False, exclude_files=[], absolute_paths=False):
    if not os.path.isdir(proj_dir):
        raise Error("Project dir '{}' does not exists!".format(proj_dir))

    print("## Processing build commands from {}".format(instream.name))
    result = parse_build_log(instream, proj_dir, exclude_files, verbose, absolute_paths)
    return result
Exemple #6
0
def generate_json_compdb(instream=None, proj_dir=os.getcwd(), exclude_files=[], add_predefined_macros=False,
                         use_full_path=False, command_style=False):
    if not os.path.isdir(proj_dir):
        raise Error("Project dir '{}' does not exists!".format(proj_dir))

    logger.info("## Processing build commands from {}".format(basename(instream)))
    result = parse_build_log(instream, proj_dir, exclude_files, add_predefined_macros=add_predefined_macros,
                             use_full_path=use_full_path, command_style=command_style)
    return result
Exemple #7
0
def test_empty():
    build_log = ''
    proj_dir = '/tmp'
    exclude_files = []

    result = parse_build_log(build_log, proj_dir, exclude_files)
    assert result.count == 0
    assert result.skipped == 0
    assert result.compdb is not None
    assert type(result.compdb) == list
    assert len(result.compdb) == 0
Exemple #8
0
def test_build_commands_with_version():
    pwd = getcwd()
    build_log = ['clang-5.0 -o hello.o -c hello.c']
    result = parse_build_log(build_log, proj_dir=pwd, exclude_files=[])

    assert result.count == 1
    assert result.skipped == 0
    assert len(result.compdb) == 1
    assert result.compdb[0] == {
        'directory': pwd,
        'file': 'hello.c',
        'arguments': ['clang-5.0', '-o', 'hello.o', '-c', 'hello.c']
    }
Exemple #9
0
def test_multiple_commands_per_line():
    pwd = getcwd()
    with input_file('multiple_commands_oneline.txt') as build_log:
        result = parse_build_log(build_log, proj_dir=pwd, exclude_files=[])

    assert result.count == 2
    assert result.skipped == 0
    assert len(result.compdb) == 2
    assert result.compdb[0] == {
        'directory': pwd,
        'file': './path/src/hein.cpp',
        'arguments': ['g++', '-c', './path/src/hein.cpp', '-o', 'out.o']
    }
def test_empty():
    build_log = ''
    proj_dir = '/tmp'
    incpath_prefix = proj_dir
    exclude_list = []
    verbose = False

    result = parse_build_log(build_log, proj_dir, incpath_prefix, exclude_list,
                             verbose)
    assert result.count == 0
    assert result.skipped == 0
    assert result.compdb is not None
    assert type(result.compdb) == list
    assert len(result.compdb) == 0
Exemple #11
0
def test_trivial_build_command():
    pwd = getcwd()
    build_log = ['gcc -o hello.o -c hello.c']
    result = parse_build_log(build_log,
                             proj_dir=pwd,
                             exclude_files=[],
                             verbose=False)

    assert result.count == 1
    assert result.skipped == 0
    assert len(result.compdb) == 1
    assert result.compdb[0] == {
        'directory': pwd,
        'file': 'hello.c',
        'arguments': ['gcc', '-o', 'hello.o', '-c', 'hello.c']
    }
Exemple #12
0
def test_parse_file_extensions():
    pwd = getcwd()
    build_log = [
        'gcc -c somefile.cpp\n'
        'gcc -c main.cxx -o main.o\n'
        'gcc -c main.cc -o main.o\n'
        'gcc -c -o swtch.o swtch.S\n'
        'gcc -c -o what.o what.s\n'
    ]
    result = parse_build_log(build_log,
                             proj_dir=pwd,
                             exclude_files=[],
                             verbose=True)

    assert result.count == 5
    assert result.skipped == 0
    assert len(result.compdb) == 5
    assert result.compdb == [{
        'directory': pwd,
        'file': 'somefile.cpp',
        'arguments': ['gcc', '-c', 'somefile.cpp']
    }, {
        'directory':
        pwd,
        'file':
        'main.cxx',
        'arguments': ['gcc', '-c', 'main.cxx', '-o', 'main.o']
    }, {
        'directory':
        pwd,
        'file':
        'main.cc',
        'arguments': ['gcc', '-c', 'main.cc', '-o', 'main.o']
    }, {
        'directory':
        pwd,
        'file':
        'swtch.S',
        'arguments': ['gcc', '-c', '-o', 'swtch.o', 'swtch.S']
    }, {
        'directory':
        pwd,
        'file':
        'what.s',
        'arguments': ['gcc', '-c', '-o', 'what.o', 'what.s']
    }]
def test_automake_command():
    pwd = getcwd()
    with input_file('autotools_simple') as build_log:
        result = parse_build_log(build_log,
                                 proj_dir=pwd,
                                 inc_prefix=None,
                                 exclude_list=[],
                                 verbose=False)

    assert result.count == 1
    assert result.skipped == 0
    assert len(result.compdb) == 1
    assert result.compdb[0] == {
        'directory':
        pwd,
        'file':
        './main.c',
        'arguments': [
            'cc', '-DPACKAGE_NAME="hello"', '-DPACKAGE_VERSION="1.0.0"',
            '-DSTDC_HEADERS=1', '-I.', '-I../../src/libhello', '-c', './main.c'
        ]
    }