Skip to content

Commit 20a929a

Browse files
committed
rename CompileCommand.{command => arguments}
1 parent a6ed511 commit 20a929a

File tree

5 files changed

+66
-64
lines changed

5 files changed

+66
-64
lines changed

compdb/backend/json.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ def _data(self):
5050
return self.__data
5151

5252

53-
def command_to_json(commands):
53+
def arguments_to_json(arguments):
5454
cmd_line = '"'
55-
for i, command in enumerate(commands):
55+
for i, argument in enumerate(arguments):
5656
if i != 0:
5757
cmd_line += ' '
58-
has_space = re.search(r"\s", command) is not None
58+
has_space = re.search(r"\s", argument) is not None
5959
# reader now accepts simple quotes, so we need to support them here too
60-
has_simple_quote = "'" in command
60+
has_simple_quote = "'" in argument
6161
need_quoting = has_space or has_simple_quote
6262
if need_quoting:
6363
cmd_line += r'\"'
64-
cmd_line += command.replace("\\", r'\\\\').replace(r'"', r'\\\"')
64+
cmd_line += argument.replace("\\", r'\\\\').replace(r'"', r'\\\"')
6565
if need_quoting:
6666
cmd_line += r'\"'
6767
return cmd_line + '"'
@@ -78,7 +78,7 @@ def compile_command_to_json(compile_command):
7878
"file": {}
7979
}}'''.format(
8080
str_to_json(compile_command.directory),
81-
command_to_json(compile_command.command),
81+
arguments_to_json(compile_command.arguments),
8282
str_to_json(compile_command.file))
8383

8484

compdb/complementer/headerdb.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@ def sanitize_compile_options(compile_command):
1313
file_norm = compile_command.normfile
1414
adjusted = []
1515
i = 0
16-
command = compile_command.command
17-
while i < len(command):
16+
arguments = compile_command.arguments
17+
while i < len(arguments):
1818
# end of options, skip all positional arguments (source files)
19-
if command[i] == "--":
19+
if arguments[i] == "--":
2020
break
2121
# strip -c
22-
if command[i] == "-c":
22+
if arguments[i] == "-c":
2323
i += 1
2424
continue
2525
# strip -o <output-file> and -o<output-file>
26-
if command[i].startswith("-o"):
27-
if command[i] == "-o":
26+
if arguments[i].startswith("-o"):
27+
if arguments[i] == "-o":
2828
i += 2
2929
else:
3030
i += 1
3131
continue
3232
# skip input file
33-
if command[i].endswith(filename):
33+
if arguments[i].endswith(filename):
3434
arg_norm = os.path.normpath(
35-
os.path.join(compile_command.directory, command[i]))
35+
os.path.join(compile_command.directory, arguments[i]))
3636
if file_norm == arg_norm:
3737
i += 1
3838
continue
39-
adjusted.append(command[i])
39+
adjusted.append(arguments[i])
4040
i += 1
4141
return adjusted
4242

@@ -58,7 +58,7 @@ def derive_compile_command(header_file, reference):
5858
directory=reference.directory,
5959
file=mimic_path_relativity(header_file, reference.file,
6060
reference.directory),
61-
command=sanitize_compile_options(reference))
61+
arguments=sanitize_compile_options(reference))
6262

6363

6464
def get_file_includes(path):
@@ -85,15 +85,15 @@ def get_file_includes(path):
8585
def extract_include_dirs(compile_command):
8686
header_search_path = []
8787
i = 0
88-
command = sanitize_compile_options(compile_command)
89-
while i < len(command):
88+
arguments = sanitize_compile_options(compile_command)
89+
while i < len(arguments):
9090
# -I <dir> and -I<dir>
91-
if command[i].startswith("-I"):
92-
if command[i] == "-I":
91+
if arguments[i].startswith("-I"):
92+
if arguments[i] == "-I":
9393
i += 1
94-
header_search_path.append(command[i])
94+
header_search_path.append(arguments[i])
9595
else:
96-
header_search_path.append(command[i][2:])
96+
header_search_path.append(arguments[i][2:])
9797
i += 1
9898
return [
9999
os.path.join(compile_command.directory, p) for p in header_search_path

compdb/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ def __init__(self, message, cause=None):
1515

1616

1717
class CompileCommand:
18-
def __init__(self, directory, file, command):
18+
def __init__(self, directory, file, arguments):
1919
self.directory = directory
2020
self.file = file
21-
self.command = command
21+
self.arguments = arguments
2222

2323
def __repr__(self):
24-
return "{{directory: {},\nfile: {},\n command: ".format(
25-
self.directory, self.file) + pprint.pformat(self.command) + "}\n\n"
24+
return "{{directory: {},\nfile: {},\n arguments: {}}}\n\n".format(
25+
self.directory, self.file, pprint.pformat(self.arguments))
2626

2727
def __str__(self):
2828
return self.__repr__()

tests/unit/test_dump.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from io import StringIO
99

1010
from compdb.backend.json import (
11-
command_to_json,
11+
arguments_to_json,
1212
compile_commands_to_json, )
1313
from compdb.models import CompileCommand
1414

@@ -20,7 +20,7 @@
2020
#
2121
# -- http://clang.llvm.org/docs/JSONCompilationDatabase.html
2222

23-
COMMAND_TO_JSON_DATA = [
23+
ARGUMENTS_TO_JSON_DATA = [
2424
(['clang++'], r'"clang++"'),
2525
(['clang++', '-std=c++11'], r'"clang++ -std=c++11"'),
2626
(['clang++', '-DFOO=a b'], r'"clang++ \"-DFOO=a b\""'),
@@ -34,7 +34,7 @@
3434

3535
COMPILE_COMMANDS_TO_JSON_DATA = ([
3636
CompileCommand("/tmp", "foo.cpp", ["clang++"]),
37-
CompileCommand("/tmp/bar", "bar.cpp", ["clang++", "-std=c++11"])
37+
CompileCommand("/tmp/bar", "bar.cpp", ["clang++", "-std=c++11"]),
3838
], r"""[
3939
{
4040
"directory": "/tmp",
@@ -52,9 +52,9 @@
5252

5353

5454
class ToJSON(unittest.TestCase):
55-
def test_command_to_json(self):
56-
for tpl in COMMAND_TO_JSON_DATA:
57-
self.assertEqual(tpl[1], command_to_json(tpl[0]))
55+
def test_arguments_to_json(self):
56+
for tpl in ARGUMENTS_TO_JSON_DATA:
57+
self.assertEqual(tpl[1], arguments_to_json(tpl[0]))
5858

5959
def test_compile_commands_to_json(self):
6060
output = StringIO()

tests/unit/test_headerdb.py

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,145 +46,147 @@ def srcdir(self, dirname):
4646
def complement(self, compile_commands):
4747
'''
4848
The output is returned sorted in the following order: file, directory,
49-
command.
49+
arguments.
5050
'''
5151
database = InMemoryCompilationDatabase(compile_commands)
5252
result = list(Complementer().complement([[database]])[0]
5353
.get_all_compile_commands())
54-
result.sort(key=operator.attrgetter('file', 'directory', 'command'))
54+
result.sort(key=operator.attrgetter('file', 'directory', 'arguments'))
5555
return result
5656

5757
def test_01(self):
5858
test_srcdir = self.srcdir('test_01')
5959
result = self.complement([
6060
CompileCommand(
6161
directory=test_srcdir,
62-
command=['clang++', '-DA=1'],
62+
arguments=['clang++', '-DA=1'],
6363
file='a.cpp'),
6464
CompileCommand(
6565
directory=test_srcdir,
66-
command=['clang++', '-DB=1'],
66+
arguments=['clang++', '-DB=1'],
6767
file='b.cpp'),
6868
])
6969

7070
self.assertEqual(1, len(result))
7171
self.assertEqual('a.hpp', result[0].file)
72-
self.assertEqual(['clang++', '-DA=1'], result[0].command)
72+
self.assertEqual(['clang++', '-DA=1'], result[0].arguments)
7373

7474
def test_02(self):
7575
test_srcdir = self.srcdir('test_02')
7676
result = self.complement([
7777
CompileCommand(
7878
directory=test_srcdir,
79-
command=['clang++', '-Iinclude', '-DA=1'],
79+
arguments=['clang++', '-Iinclude', '-DA=1'],
8080
file='src/a.cpp'),
8181
CompileCommand(
8282
directory=test_srcdir,
83-
command=['clang++', '-Iinclude', '-DB=1'],
83+
arguments=['clang++', '-Iinclude', '-DB=1'],
8484
file='src/b.cpp'),
8585
])
8686
self.assertEqual(2, len(result))
8787
self.assertEqual('include/a/a.hpp', result[0].file)
88-
self.assertEqual(['clang++', '-Iinclude', '-DA=1'], result[0].command)
88+
self.assertEqual(['clang++', '-Iinclude', '-DA=1'],
89+
result[0].arguments)
8990
self.assertEqual('include/b/b.hpp', result[1].file)
90-
self.assertEqual(['clang++', '-Iinclude', '-DB=1'], result[1].command)
91+
self.assertEqual(['clang++', '-Iinclude', '-DB=1'],
92+
result[1].arguments)
9193

9294
def test_03(self):
9395
test_srcdir = self.srcdir('test_03')
9496
result = self.complement([
9597
CompileCommand(
9698
directory=test_srcdir,
97-
command=['clang++', '-DAB=1'],
99+
arguments=['clang++', '-DAB=1'],
98100
file='a_b.cpp'),
99101
CompileCommand(
100102
directory=test_srcdir,
101-
command=['clang++', '-DA=1'],
103+
arguments=['clang++', '-DA=1'],
102104
file='a.cpp'),
103105
CompileCommand(
104106
directory=test_srcdir,
105-
command=['clang++', '-DB=1'],
107+
arguments=['clang++', '-DB=1'],
106108
file='b.cpp'),
107109
])
108110
self.assertEqual(4, len(result))
109111
self.assertEqual('a.hpp', result[0].file)
110-
self.assertEqual(['clang++', '-DA=1'], result[0].command)
112+
self.assertEqual(['clang++', '-DA=1'], result[0].arguments)
111113
self.assertEqual('a_private.hpp', result[1].file)
112-
self.assertEqual(['clang++', '-DA=1'], result[1].command)
114+
self.assertEqual(['clang++', '-DA=1'], result[1].arguments)
113115
self.assertEqual('b.hpp', result[2].file)
114-
self.assertEqual(['clang++', '-DB=1'], result[2].command)
116+
self.assertEqual(['clang++', '-DB=1'], result[2].arguments)
115117
self.assertEqual('b_private.hpp', result[3].file)
116-
self.assertEqual(['clang++', '-DB=1'], result[3].command)
118+
self.assertEqual(['clang++', '-DB=1'], result[3].arguments)
117119

118120
def test_04(self):
119121
test_srcdir = self.srcdir('test_04')
120122
result = self.complement([
121123
CompileCommand(
122124
directory=test_srcdir,
123-
command=['clang++', '-DA=1'],
125+
arguments=['clang++', '-DA=1'],
124126
file='a.cpp'),
125127
CompileCommand(
126128
directory=test_srcdir,
127-
command=['clang++', '-DB=1'],
129+
arguments=['clang++', '-DB=1'],
128130
file='b.cpp'),
129131
])
130132
self.assertEqual(4, len(result))
131133
self.assertEqual('a.hpp', result[0].file)
132-
self.assertEqual(['clang++', '-DA=1'], result[0].command)
134+
self.assertEqual(['clang++', '-DA=1'], result[0].arguments)
133135
self.assertEqual('a.ipp', result[1].file)
134-
self.assertEqual(['clang++', '-DA=1'], result[1].command)
136+
self.assertEqual(['clang++', '-DA=1'], result[1].arguments)
135137
self.assertEqual('b.hpp', result[2].file)
136-
self.assertEqual(['clang++', '-DB=1'], result[2].command)
138+
self.assertEqual(['clang++', '-DB=1'], result[2].arguments)
137139
self.assertEqual('b.ipp', result[3].file)
138-
self.assertEqual(['clang++', '-DB=1'], result[3].command)
140+
self.assertEqual(['clang++', '-DB=1'], result[3].arguments)
139141

140142
def test_05(self):
141143
test_srcdir = self.srcdir('test_05')
142144
result = self.complement([
143145
CompileCommand(
144146
directory=test_srcdir,
145-
command=['clang++', '-DLATIN=1'],
147+
arguments=['clang++', '-DLATIN=1'],
146148
file='latin-1-á.cpp'),
147149
CompileCommand(
148150
directory=test_srcdir,
149-
command=['clang++', '-DUTF=8'],
151+
arguments=['clang++', '-DUTF=8'],
150152
file='utf-8-á.cpp'),
151153
])
152154
self.assertEqual(2, len(result))
153155
self.assertEqual('latin-1-á.hpp', result[0].file)
154-
self.assertEqual(['clang++', '-DLATIN=1'], result[0].command)
156+
self.assertEqual(['clang++', '-DLATIN=1'], result[0].arguments)
155157
self.assertEqual('utf-8-á.hpp', result[1].file)
156-
self.assertEqual(['clang++', '-DUTF=8'], result[1].command)
158+
self.assertEqual(['clang++', '-DUTF=8'], result[1].arguments)
157159

158160
def test_06(self):
159161
test_srcdir = self.srcdir('test_06')
160162
result = self.complement([
161163
CompileCommand(
162164
directory=test_srcdir,
163-
command=['clang++', '-Iinclude', '-Iinclude/a'],
165+
arguments=['clang++', '-Iinclude', '-Iinclude/a'],
164166
file='a.cpp'),
165167
])
166168
self.assertEqual(1, len(result))
167169
self.assertEqual('include/a/a', result[0].file)
168170
self.assertEqual(['clang++', '-Iinclude', '-Iinclude/a'],
169-
result[0].command)
171+
result[0].arguments)
170172

171173
def test_07(self):
172174
test_srcdir = self.srcdir('test_07')
173175
result = self.complement([
174176
CompileCommand(
175177
directory=test_srcdir,
176-
command=['clang++', '-DA=1', '-I.'],
178+
arguments=['clang++', '-DA=1', '-I.'],
177179
file='a.cpp'),
178180
CompileCommand(
179181
directory=test_srcdir,
180-
command=['clang++', '-DB=1', '-I.'],
182+
arguments=['clang++', '-DB=1', '-I.'],
181183
file='b.cpp'),
182184
])
183185
self.assertEqual(2, len(result))
184186
self.assertEqual('a.hpp', result[0].file)
185-
self.assertEqual(['clang++', '-DB=1', '-I.'], result[0].command)
187+
self.assertEqual(['clang++', '-DB=1', '-I.'], result[0].arguments)
186188
self.assertEqual('quoted_a.hpp', result[1].file)
187-
self.assertEqual(['clang++', '-DB=1', '-I.'], result[1].command)
189+
self.assertEqual(['clang++', '-DB=1', '-I.'], result[1].arguments)
188190

189191

190192
if __name__ == "__main__":

0 commit comments

Comments
 (0)