mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Fix bug with order for "includes" in conversation from INO/PDE to CPP
This commit is contained in:
@ -4,6 +4,8 @@ Release History
|
|||||||
0.8.0 (?)
|
0.8.0 (?)
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
* Fixed bug with order for includes in conversation from INO/PDE to CPP
|
||||||
|
|
||||||
|
|
||||||
0.7.0 (2014-09-24)
|
0.7.0 (2014-09-24)
|
||||||
------------------
|
------------------
|
||||||
|
@ -173,22 +173,29 @@ def ConvertInotoCpp(env):
|
|||||||
continue
|
continue
|
||||||
ino_contents = item.get_text_contents()
|
ino_contents = item.get_text_contents()
|
||||||
|
|
||||||
# fetch prototypes
|
re_includes = re.compile(r"^(#include\s+(?:\<|\")[^\r\n]+)",
|
||||||
regexp = re.compile(
|
re.M | re.I)
|
||||||
|
includes = re_includes.findall(ino_contents)
|
||||||
|
prototypes = re.findall(
|
||||||
r"""^(
|
r"""^(
|
||||||
(?:\s*[a-z_\d]+){1,2} # return type
|
(?:\s*[a-z_\d]+){1,2} # return type
|
||||||
\s+[a-z_\d]+\s* # name of prototype
|
\s+[a-z_\d]+\s* # name of prototype
|
||||||
\([a-z_,\.\*\&\[\]\s\d]*\) # args
|
\([a-z_,\.\*\&\[\]\s\d]*\) # args
|
||||||
)\s*\{ # must end with {
|
)\s*\{ # must end with {
|
||||||
""",
|
""",
|
||||||
|
ino_contents,
|
||||||
re.X | re.M | re.I
|
re.X | re.M | re.I
|
||||||
)
|
)
|
||||||
prototypes = regexp.findall(ino_contents)
|
# print includes, prototypes
|
||||||
# print prototypes
|
|
||||||
|
# disable previous includes
|
||||||
|
ino_contents = re_includes.sub("//\g<1>", ino_contents)
|
||||||
|
|
||||||
# create new temporary C++ valid file
|
# create new temporary C++ valid file
|
||||||
with open(cppfile, "w") as f:
|
with open(cppfile, "w") as f:
|
||||||
f.write("#include <Arduino.h>\n")
|
f.write("#include <Arduino.h>\n")
|
||||||
|
if includes:
|
||||||
|
f.write("%s\n" % "\n".join(includes))
|
||||||
if prototypes:
|
if prototypes:
|
||||||
f.write("%s;\n" % ";\n".join(prototypes))
|
f.write("%s;\n" % ";\n".join(prototypes))
|
||||||
f.write("#line 1 \"%s\"\n" % basename(item.path))
|
f.write("#line 1 \"%s\"\n" % basename(item.path))
|
||||||
|
Reference in New Issue
Block a user