File: smoke

package info (click to toggle)
bear 3.1.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,904 kB
  • sloc: cpp: 9,184; sh: 706; ansic: 497; python: 175; makefile: 29
file content (44 lines) | stat: -rwxr-xr-x 1,233 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright © 2019 Collabora Ltd.
# SPDX-License-Identifier: GPL-3.0-or-later

import json
import os
import subprocess
import tempfile

if __name__ == '__main__':
    with tempfile.TemporaryDirectory() as tmpdir:
        with open(os.path.join(tmpdir, 'Makefile'), 'w') as writer:
            writer.write('''\
hi: hi.c
\t$(CC) -DMAGIC=more_magic -o$@ $<
''')

        with open(os.path.join(tmpdir, 'hi.c'), 'w') as writer:
            writer.write('''\
#include <stdio.h>

int main (void)
{
  puts ("hi, world!");
  return 0;
}
''')

        # see d/rules
        env = dict(os.environ)
        if 'PATH' in env:
            env['PATH'] = ':'.join(p for p in env['PATH'].split(':') if not p.startswith('/usr/lib/ccache'))

        subprocess.check_call(['bear', '--', 'make'], cwd=tmpdir, env=env)

        with open(os.path.join(tmpdir, 'compile_commands.json')) as reader:
            commands = json.load(reader)

        assert len(commands) == 1, commands
        command = commands[0]
        assert '-DMAGIC=more_magic' in command['arguments'], command
        assert command['directory'] == tmpdir, command
        assert command['file'] == os.path.join(tmpdir, 'hi.c'), command