mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 01:57:13 +02:00
Fix INO to CPP converter when #define is used
This commit is contained in:
@ -53,6 +53,7 @@ class InoToCPPConverter(object):
|
||||
return self.process(contents)
|
||||
|
||||
def merge(self, nodes):
|
||||
assert nodes
|
||||
lines = []
|
||||
for node in nodes:
|
||||
contents = node.get_text_contents()
|
||||
@ -65,6 +66,9 @@ class InoToCPPConverter(object):
|
||||
else:
|
||||
lines.extend(_lines)
|
||||
|
||||
if not self._main_ino:
|
||||
self._main_ino = nodes[0].get_path()
|
||||
|
||||
return "\n".join(["#include <Arduino.h>"] + lines) if lines else None
|
||||
|
||||
def process(self, contents):
|
||||
@ -104,17 +108,20 @@ class InoToCPPConverter(object):
|
||||
|
||||
if line.endswith("\\"):
|
||||
if line.startswith('"'):
|
||||
newlines.append(line[:-1])
|
||||
stropen = True
|
||||
newlines.append(line[:-1])
|
||||
continue
|
||||
elif stropen:
|
||||
newlines[len(newlines) - 1] += line[:-1]
|
||||
continue
|
||||
elif stropen and line.endswith('";'):
|
||||
newlines[len(newlines) - 1] += line
|
||||
stropen = False
|
||||
newlines.append('#line %d "%s"' %
|
||||
(linenum, self._main_ino.replace("\\", "/")))
|
||||
else:
|
||||
newlines.append(line)
|
||||
continue
|
||||
|
||||
newlines.append(line)
|
||||
|
||||
return "\n".join(newlines)
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
#define SQR(a) \
|
||||
( a * a )
|
||||
|
||||
typedef struct Item item;
|
||||
struct Item {
|
||||
byte foo[50];
|
||||
@ -10,7 +13,7 @@ class Foo {
|
||||
|
||||
public:
|
||||
Foo(void (*function)()) {
|
||||
#warning "Line number is 13"
|
||||
#warning "Line number is 16"
|
||||
}
|
||||
|
||||
bool childFunc() {
|
||||
|
@ -40,7 +40,7 @@ def test_warning_line(clirunner, validate_cliresult):
|
||||
result = clirunner.invoke(cmd_ci,
|
||||
[join(INOTEST_DIR, "basic"), "-b", "uno"])
|
||||
validate_cliresult(result)
|
||||
assert ('basic.ino:13:14: warning: #warning "Line number is 13"' in
|
||||
assert ('basic.ino:16:14: warning: #warning "Line number is 16"' in
|
||||
result.output)
|
||||
result = clirunner.invoke(
|
||||
cmd_ci, [join(INOTEST_DIR, "strmultilines"), "-b", "uno"])
|
||||
|
Reference in New Issue
Block a user