Skip to content

Commit 2e92011

Browse files
author
Vano
committed
extension-agnostic parsing
1 parent 053fc95 commit 2e92011

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ git submodule update --init external/cppscript
7878
7979
# ...
8080
81-
# Get list of headers (*.hpp only)
81+
# Get list of headers (Prefer *.hpp files)
8282
scripts = GlobRecursive('src', '*.hpp')
8383
8484
# Create target, returns generated .cpp files list
@@ -143,7 +143,7 @@ git submodule update --init external/cppscript
143143
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/external/cppscript")
144144
include(godot-cppscript)
145145
146-
# Get header files (.hpp only)
146+
# Get header files (Prefer .hpp files)
147147
file(GLOB_RECURSE CPPSCRIPT_HEADERS src/*.hpp)
148148
149149
# Call function to configure your target

cppscript.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,20 @@ class CppScriptException(Exception):
7171
pass
7272

7373

74+
def replace_extension(filename, new_ext):
75+
idx = filename.rfind('.')
76+
if idx == -1:
77+
return filename + new_ext
78+
else:
79+
return filename[:idx] + new_ext
80+
81+
7482
def resolve_path(path, cwd):
7583
return path if os.path.isabs(path) else os.path.abspath(os.path.join(cwd, path))
7684

7785

7886
def filename_to_gen_filename(name, env):
79-
return os.path.join(env['gen_dir'], os.path.relpath(name.replace('.hpp', '.gen.cpp'), env['header_dir']))
87+
return os.path.join(env['gen_dir'], os.path.relpath(replace_extension(name, '.gen.cpp'), env['header_dir']))
8088

8189

8290
def collapse_list(list, key, action):
@@ -270,7 +278,7 @@ def generate_header(source, env, get_file):
270278
return 0
271279

272280
def parse_header(index, filename, filecontent, env):
273-
translation_unit = index.parse(filename, args=env['parser_args'], unsaved_files=[(filename, filecontent)], options=TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD)
281+
translation_unit = index.parse(filename, args=env['parser_args'] + ['-x', 'c++'], unsaved_files=[(filename, filecontent)], options=TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD)
274282

275283
if not translation_unit:
276284
raise CppScriptException("{filename}: failed to create translation unit")

godot-cppscript.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function(create_cppscript_target TARGET_NAME HEADERS_LIST HEADER_NAME HEADERS_DI
2121

2222
foreach(PATH ${HEADERS_LIST})
2323
file(RELATIVE_PATH PATH "${HEADERS_DIR}" "${PATH}")
24-
string(REGEX REPLACE "\.hpp$" ".gen.cpp" relative_path "${PATH}")
24+
string(REGEX REPLACE "\.[^./\\]+$" ".gen.cpp" relative_path "${PATH}")
2525
list(APPEND SOURCES_LIST "${GEN_DIR}/${relative_path}")
2626
endforeach()
2727

0 commit comments

Comments
 (0)