Skip to content

Normalize relative paths in compile_commands.json #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lint4jsondb.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ def finish(self):

continue

# apply the directory to relative paths if needed
self.file = os.path.normpath(os.path.join(self.directory, self.file))
self.invocation.includes = [
os.path.normpath(os.path.join(self.directory, inc))
for inc in self.invocation.includes]


class Lint4JsonCompilationDb:
def __init__(self, compilation_db, include_only=set(), exclude_all=set()):
Expand Down Expand Up @@ -317,7 +323,8 @@ def execute_with(self, arg, json_db):

class ExecuteLintForAllFilesInOneInvocation:
def __init__(self):
self._tmp_file = tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.lnt')
self._tmp_file = tempfile.NamedTemporaryFile(
mode='w+', delete=False, suffix='.lnt')
self._last_invocation = None

def _create_temporary_lint_config(self, json_db):
Expand Down
9 changes: 7 additions & 2 deletions test_lint4jsondb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def tearDown(self):
os.remove(self._json_tested)

def __create_temp_json(self, content):
with tempfile.TemporaryFile('wb', delete=False) as f:
with tempfile.NamedTemporaryFile('wb', delete=False) as f:
self._json_tested = f.name
f.write(content)

Expand Down Expand Up @@ -264,7 +264,8 @@ def test_invocation(self, mock_call, mock_os_path_exists, mock_os_makedirs):
'stderr': -2, 'stdout': -1})

# ensure lint is called
self.assertEqual(args.pop(0), os.path.join("<lint-path>", "<lint-exe>"))
self.assertEqual(args.pop(0), os.path.join(
"<lint-path>", "<lint-exe>"))
# ensure lint suppresses the banner line
self.assertEqual(args.pop(0), '-b')
# ensure lint's "lnt" directory was added
Expand All @@ -280,3 +281,7 @@ def test_invocation(self, mock_call, mock_os_path_exists, mock_os_makedirs):
self.assertEqual(args.pop(0), '-i"i2"')
# ensure that the file to check is passed finally
self.assertEqual(args.pop(0), "<file>")


if __name__ == "__main__":
unittest.main()