Skip to content

Commit 322b798

Browse files
committed
Rewrite load_database to use CompileCommand
More refactoring is possible here, but deferred until 2.0.0. Signed-off-by: John Pennycook <john.pennycook@intel.com>
1 parent e4ca7a9 commit 322b798

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

codebasin/config.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
import logging
1212
import os
1313
import re
14-
import shlex
1514
import warnings
1615

1716
import yaml
1817

19-
from codebasin import util
18+
from codebasin import CompileCommand, util
2019

2120
log = logging.getLogger("codebasin")
2221

@@ -418,11 +417,10 @@ def load_database(dbpath, rootdir):
418417

419418
configuration = []
420419
for e in db:
421-
# Database may not have tokenized arguments
422-
if "command" in e:
423-
argv = shlex.split(e["command"])
424-
elif "arguments" in e:
425-
argv = e["arguments"]
420+
command = CompileCommand.from_json(e)
421+
if not command.is_supported():
422+
continue
423+
argv = command.arguments
426424

427425
# Extract defines, include paths and include files
428426
# from command-line arguments
@@ -444,19 +442,19 @@ def load_database(dbpath, rootdir):
444442
# - relative to a directory
445443
# - as an absolute path
446444
filedir = rootdir
447-
if "directory" in e:
448-
if os.path.isabs(e["directory"]):
449-
filedir = e["directory"]
445+
if command.directory is not None:
446+
if os.path.isabs(command.directory):
447+
filedir = command.directory
450448
else:
451449
filedir = os.path.realpath(
452450
rootdir,
453-
os.path.join(e["directory"]),
451+
os.path.join(command.directory),
454452
)
455453

456-
if os.path.isabs(e["file"]):
457-
path = os.path.realpath(e["file"])
454+
if os.path.isabs(command.filename):
455+
path = os.path.realpath(command.filename)
458456
else:
459-
path = os.path.realpath(os.path.join(filedir, e["file"]))
457+
path = os.path.realpath(os.path.join(filedir, command.filename))
460458

461459
# Compilation database may contain files that don't
462460
# exist without running make

0 commit comments

Comments
 (0)