Skip to content

Commit 3e12738

Browse files
galpeterrerobika
authored andcommitted
Improve single-source generation (#2989)
Detected and fixed minor issues with the single-source generation: * On Windows the line info generation now correctly escapes the path separators. * Fixed an incorrect C file include order. Now the global object C file is force included to get all common headers at the start in the generated source file. * Added a missing colon which fixed the correct removal of the config.h include. * Fix the command line help. * Small typo fix. JerryScript-DCO-1.0-Signed-off-by: Peter Gal [email protected]
1 parent 6744376 commit 3e12738

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

tools/srcgenerator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ def generate_jerry_core(output_dir, verbose=False):
4848
'--input={}/api/jerry.c'.format(JERRY_CORE),
4949
'--output={}/jerryscript.c'.format(output_dir),
5050
'--append-c-files',
51+
# Add the global built-in by default to include some common items
52+
# to avoid problems with common built-in headers
53+
'--input={}/ecma/builtin-objects/ecma-builtins.c'.format(JERRY_CORE),
5154
'--remove-include=jerryscript.h',
5255
'--remove-include=jerryscript-port.h',
5356
'--remove-include=jerryscript-compiler.h',
5457
'--remove-include=jerryscript-core.h',
5558
'--remove-include=jerryscript-debugger.h',
5659
'--remove-include=jerryscript-debugger-transport.h',
5760
'--remove-include=jerryscript-port.h',
58-
'--remove-include=jerryscript-snapshot.h'
61+
'--remove-include=jerryscript-snapshot.h',
5962
'--remove-include=config.h',
6063
'--push-include=jerryscript.h',
6164
]

tools/srcmerger.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def _process_non_include(self, line, file_level):
6060
self._output.append(line)
6161

6262
def _emit_lineinfo(self, line_number, filename):
63-
line_info = '#line %d "%s"\n' % (line_number, filename)
63+
normalized_path = repr(os.path.normpath(filename))[1:-1]
64+
line_info = '#line %d "%s"\n' % (line_number, normalized_path)
6465

6566
if self._output and self._output[-1].startswith('#line'):
6667
# Avoid emitting multiple line infos in sequence, just overwrite the last one
@@ -73,6 +74,9 @@ def add_file(self, filename, file_level=0):
7374
self._log.warning('Tried to to process an already processed file: "%s"', filename)
7475
return
7576

77+
if not file_level:
78+
self._log.debug('Adding file: "%s"', filename)
79+
7680
file_level += 1
7781

7882
# mark the start of the new file in the output
@@ -138,7 +142,7 @@ def add_file(self, filename, file_level=0):
138142

139143
self._log.debug('[%d] Including: "%s"',
140144
file_level, self._h_files[name])
141-
self.add_file(self._h_files[name])
145+
self.add_file(self._h_files[name], file_level)
142146

143147
# mark the continuation of the current file in the output
144148
self._emit_lineinfo(line_idx + 1, filename)
@@ -207,17 +211,17 @@ def run_merger(args):
207211
h_files.pop(name, '')
208212

209213
merger = SourceMerger(h_files, args.push_include, args.remove_include)
210-
if args.input_file:
211-
merger.add_file(args.input_file)
214+
for input_file in args.input_files:
215+
merger.add_file(input_file)
212216

213217
if args.append_c_files:
214218
# if the input file is in the C files list it should be removed to avoid
215219
# double inclusion of the file
216-
if args.input_file:
217-
input_name = os.path.basename(args.input_file)
220+
for input_file in args.input_files:
221+
input_name = os.path.basename(input_file)
218222
c_files.pop(input_name, '')
219223

220-
# Add the C files in reverse the order to make sure that builtins are
224+
# Add the C files in reverse order to make sure that builtins are
221225
# not at the beginning.
222226
for fname in sorted(c_files.values(), reverse=True):
223227
merger.add_file(fname)
@@ -230,12 +234,12 @@ def main():
230234
parser = argparse.ArgumentParser(description='Merge source/header files.')
231235
parser.add_argument('--base-dir', metavar='DIR', type=str, dest='base_dir',
232236
help='', default=os.path.curdir)
233-
parser.add_argument('--input', metavar='FILE', type=str, dest='input_file',
234-
help='Main input source/header file')
237+
parser.add_argument('--input', metavar='FILES', type=str, action='append', dest='input_files',
238+
help='Main input source/header files', default=[])
235239
parser.add_argument('--output', metavar='FILE', type=str, dest='output_file',
236240
help='Output source/header file')
237241
parser.add_argument('--append-c-files', dest='append_c_files', default=False,
238-
action='store_true', help='das')
242+
action='store_true', help='Enable auto inclusion of c files under the base-dir')
239243
parser.add_argument('--remove-include', action='append', default=[])
240244
parser.add_argument('--push-include', action='append', default=[])
241245
parser.add_argument('--verbose', '-v', action='store_true', default=False)

0 commit comments

Comments
 (0)