Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 5405d62

Browse files
committed
Fixed bug caused by previous bug-fix regarding sketch conversion.
Refactored the sketch-to-source conversion model as well, optimizing and handling a few edge-cases.
1 parent b49c5a5 commit 5405d62

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

cmake/Platform/Sketches/SketchSourceConverter.cmake

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ endfunction()
3131
#=============================================================================#
3232
function(_get_matching_header_insertion_index _sketch_loc _active_index _return_var)
3333

34-
decrement_integer(_active_index 1)
34+
if (${_active_index} EQUAL 0) # First line in a file will always result in the 1st index
35+
set(${_return_var} 0 PARENT_SCOPE)
36+
return()
37+
else ()
38+
decrement_integer(_active_index 1)
39+
endif ()
3540

3641
list(GET _sketch_loc ${_active_index} previous_loc)
3742

@@ -81,6 +86,7 @@ function(convert_sketch_to_source _sketch_file _converted_source_path)
8186

8287
set(header_insert_pattern
8388
"${ARDUINO_CMAKE_HEADER_INCLUDE_REGEX_PATTERN}|${ARDUINO_CMAKE_FUNCTION_REGEX_PATTERN}")
89+
set(include_line "#include <${ARDUINO_CMAKE_PLATFORM_HEADER_NAME}>")
8490

8591
foreach (loc_index RANGE 0 ${num_of_loc})
8692

@@ -93,18 +99,26 @@ function(convert_sketch_to_source _sketch_file _converted_source_path)
9399
_get_matching_header_insertion_index("${sketch_loc}" ${loc_index} header_index)
94100

95101
if (${header_index} LESS ${loc_index})
96-
set(include_line "${ARDUINO_CMAKE_INCLUDE_PLATFORM_HEADER_STRING}\n\n")
102+
set(formatted_include_line ${include_line} "\n\n")
103+
104+
elseif (${header_index} EQUAL 0)
105+
set(formatted_include_line ${include_line} "\n")
106+
97107
else ()
98108

99-
set(include_line "\n${ARDUINO_CMAKE_INCLUDE_PLATFORM_HEADER_STRING}")
109+
set(formatted_include_line "\n" ${include_line})
110+
111+
if (${header_index} GREATER_EQUAL ${loc_index})
100112

101-
if (${header_index} GREATER 0 AND ${header_index} GREATER_EQUAL ${loc_index})
102113
decrement_integer(header_index 1)
114+
115+
string(APPEND formatted_include_line "\n")
116+
103117
endif ()
104118

105119
endif ()
106120

107-
list(INSERT refined_sketch ${header_index} ${include_line})
121+
list(INSERT refined_sketch ${header_index} ${formatted_include_line})
108122

109123
set(header_inserted TRUE)
110124

cmake/Platform/System/DefaultsManager.cmake

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
#=============================================================================#
2-
# Sets various patterns used internaly by the framework for all kinds of purposes.
3-
#=============================================================================#
4-
function(set_internal_patterns)
5-
6-
set(ARDUINO_CMAKE_INCLUDE_PLATFORM_HEADER_STRING
7-
"#include <${ARDUINO_CMAKE_PLATFORM_HEADER_NAME}>" CACHE STRING
8-
"Pattern to use in sketch-to-source conversion when inserting platform's header include")
9-
10-
endfunction()
11-
121
#=============================================================================#
132
# Sets search patterns used internaly by the framework for searching purposes.
143
#=============================================================================#
@@ -83,7 +72,6 @@ endfunction()
8372
#=============================================================================#
8473
function(set_arduino_cmake_defaults)
8574

86-
set_internal_patterns()
8775
set_internal_search_patterns()
8876
set_source_files_patterns()
8977
set_default_arduino_cmake_options()

0 commit comments

Comments
 (0)