Skip to content

Commit 9b6846d

Browse files
committed
Add option to disable generating includes
1 parent 68363b8 commit 9b6846d

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

extract.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55

66
@click.command()
7+
@click.option('--format', type=click.Choice(['cpp', 'pointers_cpp'], case_sensitive=False), default='cpp')
8+
@click.option('--includes/--no-includes', default=True)
79
@click.argument('input', type=click.File('rb'))
8-
@click.option('--format', type=click.Choice(['cpp', 'pointers_cpp'], case_sensitive=False))
9-
def extract(input, format):
10+
def extract(input, format, includes):
11+
config = {
12+
'includes': includes
13+
}
14+
1015
result = process(input)
11-
output = convert(result, format)
16+
output = convert(result, format, config)
1217

1318
print(output)
1419

extractdebug/converters/converter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class Converter:
2-
def __init__(self, result):
2+
def __init__(self, result, config):
33
self.result = result
4+
self.config = config
45

56
@staticmethod
67
def name():

extractdebug/converters/original_cpp.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99

1010
class OriginalCPPConverter(Converter):
11-
def __init__(self, result, on_entry_render=None):
12-
super().__init__(result)
11+
def __init__(self, result, config, on_entry_render=None):
12+
super().__init__(result, config)
1313
self.includes = defaultdict(set)
14+
self.used_types = defaultdict(set)
1415
self.on_entry_render = on_entry_render
1516

1617
@staticmethod
@@ -28,17 +29,18 @@ def convert(self):
2829
file_output = f'// Source file: {file_relative_path}\n'
2930
file_output += f'#ifndef {simple_name}_H\n#define {simple_name}_H\n\n'
3031

31-
for included_file_path in self.includes[file_path]:
32-
if included_file_path.startswith(self.result.base_dir):
33-
included_relative_path = relative_path(file_path, included_file_path)
34-
include_name = included_relative_path.decode('utf-8')
35-
file_output += f'#include "{include_name}"\n'
36-
else:
37-
include_name = included_file_path.decode('utf-8')
38-
file_output += f'#include <{include_name}>\n'
39-
40-
if self.includes[file_path]:
41-
file_output += '\n'
32+
if self.config['includes']:
33+
for included_file_path in self.includes[file_path]:
34+
if included_file_path.startswith(self.result.base_dir):
35+
included_relative_path = relative_path(file_path, included_file_path)
36+
include_name = included_relative_path.decode('utf-8')
37+
file_output += f'#include "{include_name}"\n'
38+
else:
39+
include_name = included_file_path.decode('utf-8')
40+
file_output += f'#include <{include_name}>\n'
41+
42+
if self.includes[file_path]:
43+
file_output += '\n'
4244

4345
for entry in entries:
4446
if self.on_entry_render:

extractdebug/converters/pointers_cpp.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from extractdebug.converters import OriginalCPPConverter
22
from extractdebug.converters.original_cpp import CPPClass, CPPMethod, CPPNamespace, CPPField
3-
from extractdebug.extractors.extractor import Type, TypeModifier
3+
from extractdebug.extractors.extractor import Type
44

55

66
class PointersCPPConverter(OriginalCPPConverter):
7-
def __init__(self, result):
8-
super().__init__(result, on_entry_render=self.on_entry_render)
7+
def __init__(self, result, config):
8+
super().__init__(result, config, on_entry_render=self.on_entry_render)
99

1010
@staticmethod
1111
def name():

extractdebug/processor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ def process(file):
1111
return extractor.extract(file)
1212

1313

14-
def convert(result, format):
14+
def convert(result, format, config):
1515
converter = find_converter(format)
1616
if not converter:
1717
return None
1818

19-
return converter(result).convert()
19+
return converter(result, config).convert()
2020

2121

2222
def find_extractor(file):

0 commit comments

Comments
 (0)