Skip to content

Commit eb669cb

Browse files
committed
compilation_db: test db regeneration on compile command change
This commit adds a dummy '-g' option to the fake gcc so as to be able to modify a compile command by adding flags.
1 parent 1c20d10 commit eb669cb

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

test/CompilationDatabase/basic.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@
3131
import os.path
3232
import TestSCons
3333

34+
def get_db(workdir, use_abspath, ccflags):
35+
if use_abspath:
36+
prefix = workdir
37+
else:
38+
prefix = ''
39+
content = """[
40+
{
41+
"command": "%s mygcc.py cc -o test_main.o %s test_main.c",
42+
"directory": "%s",
43+
"file": "%s",
44+
"output": "%s"
45+
}
46+
]""" % (sys.executable,
47+
' '.join(['-c'] + ccflags),
48+
workdir,
49+
os.path.join(prefix, 'test_main.c'),
50+
os.path.join(prefix, 'test_main.o'))
51+
if sys.platform == 'win32':
52+
content = content.replace('\\', '\\\\')
53+
return content
54+
3455
test = TestSCons.TestSCons()
3556

3657
test.file_fixture('mylink.py')
@@ -56,35 +77,32 @@
5677
'compile_commands_over_abs_1.json',
5778
]
5879

59-
example_rel_file = """[
60-
{
61-
"command": "%s mygcc.py cc -o test_main.o -c test_main.c",
62-
"directory": "%s",
63-
"file": "test_main.c",
64-
"output": "test_main.o"
65-
}
66-
]""" % (sys.executable, test.workdir)
6780

68-
if sys.platform == 'win32':
69-
example_rel_file = example_rel_file.replace('\\', '\\\\')
81+
example_rel_file = get_db(test.workdir, False, [])
7082

7183
for f in rel_files:
7284
# print("Checking:%s" % f)
7385
test.must_exist(f)
7486
test.must_match(f, example_rel_file, mode='r')
7587

76-
example_abs_file = """[
77-
{
78-
"command": "%s mygcc.py cc -o test_main.o -c test_main.c",
79-
"directory": "%s",
80-
"file": "%s",
81-
"output": "%s"
82-
}
83-
]""" % (sys.executable, test.workdir, os.path.join(test.workdir, 'test_main.c'), os.path.join(test.workdir, 'test_main.o'))
8488

85-
if sys.platform == 'win32':
86-
example_abs_file = example_abs_file.replace('\\', '\\\\')
89+
example_abs_file = get_db(test.workdir, True, [])
90+
91+
for f in abs_files:
92+
test.must_exist(f)
93+
test.must_match(f, example_abs_file, mode='r')
94+
95+
96+
test.run(arguments='CCFLAGS=-g')
97+
98+
example_rel_file = get_db(test.workdir, False, ['-g'])
99+
100+
for f in rel_files:
101+
test.must_exist(f)
102+
test.must_match(f, example_rel_file, mode='r')
103+
87104

105+
example_abs_file = get_db(test.workdir, True, ['-g'])
88106

89107
for f in abs_files:
90108
test.must_exist(f)

test/CompilationDatabase/fixture/SConstruct

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env = Environment(
77
LINKFLAGS=[],
88
CC='$PYTHON mygcc.py cc',
99
CXX='$PYTHON mygcc.py c++',
10+
CCFLAGS=ARGUMENTS.get('CCFLAGS', ''),
1011
tools=['gcc','g++','gnulink'],
1112
)
1213
env.Tool('compilation_db')

test/fixture/mygcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
compiler = sys.argv[1]
55
clen = len(compiler) + 1
6-
opts, args = getopt.getopt(sys.argv[2:], 'co:xf:K:')
6+
opts, args = getopt.getopt(sys.argv[2:], 'co:xf:gK:')
77
for opt, arg in opts:
88
if opt == '-o':
99
out = arg

0 commit comments

Comments
 (0)