Skip to content

Commit

Permalink
compilation_db: test db regeneration on compile command change
Browse files Browse the repository at this point in the history
This commit adds a dummy '-g' option to the fake gcc so as to be able
to modify a compile command by adding flags.
  • Loading branch information
exg committed Jul 5, 2020
1 parent 1c20d10 commit eb669cb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
58 changes: 38 additions & 20 deletions test/CompilationDatabase/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@
import os.path
import TestSCons

def get_db(workdir, use_abspath, ccflags):
if use_abspath:
prefix = workdir
else:
prefix = ''
content = """[
{
"command": "%s mygcc.py cc -o test_main.o %s test_main.c",
"directory": "%s",
"file": "%s",
"output": "%s"
}
]""" % (sys.executable,
' '.join(['-c'] + ccflags),
workdir,
os.path.join(prefix, 'test_main.c'),
os.path.join(prefix, 'test_main.o'))
if sys.platform == 'win32':
content = content.replace('\\', '\\\\')
return content

test = TestSCons.TestSCons()

test.file_fixture('mylink.py')
Expand All @@ -56,35 +77,32 @@
'compile_commands_over_abs_1.json',
]

example_rel_file = """[
{
"command": "%s mygcc.py cc -o test_main.o -c test_main.c",
"directory": "%s",
"file": "test_main.c",
"output": "test_main.o"
}
]""" % (sys.executable, test.workdir)

if sys.platform == 'win32':
example_rel_file = example_rel_file.replace('\\', '\\\\')
example_rel_file = get_db(test.workdir, False, [])

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

example_abs_file = """[
{
"command": "%s mygcc.py cc -o test_main.o -c test_main.c",
"directory": "%s",
"file": "%s",
"output": "%s"
}
]""" % (sys.executable, test.workdir, os.path.join(test.workdir, 'test_main.c'), os.path.join(test.workdir, 'test_main.o'))

if sys.platform == 'win32':
example_abs_file = example_abs_file.replace('\\', '\\\\')
example_abs_file = get_db(test.workdir, True, [])

for f in abs_files:
test.must_exist(f)
test.must_match(f, example_abs_file, mode='r')


test.run(arguments='CCFLAGS=-g')

example_rel_file = get_db(test.workdir, False, ['-g'])

for f in rel_files:
test.must_exist(f)
test.must_match(f, example_rel_file, mode='r')


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

for f in abs_files:
test.must_exist(f)
Expand Down
1 change: 1 addition & 0 deletions test/CompilationDatabase/fixture/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ env = Environment(
LINKFLAGS=[],
CC='$PYTHON mygcc.py cc',
CXX='$PYTHON mygcc.py c++',
CCFLAGS=ARGUMENTS.get('CCFLAGS', ''),
tools=['gcc','g++','gnulink'],
)
env.Tool('compilation_db')
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/mygcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

0 comments on commit eb669cb

Please sign in to comment.