From 2a7e67b8e43a0908dbb5a1c345bb295e25272730 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 30 Sep 2014 20:55:08 +0300 Subject: [PATCH] Fix bug with order for "includes" in conversation from INO/PDE to CPP --- HISTORY.rst | 2 ++ platformio/builder/tools/platformio.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 98dc24a7..d27a2a72 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,8 @@ Release History 0.8.0 (?) --------- +* Fixed bug with order for includes in conversation from INO/PDE to CPP + 0.7.0 (2014-09-24) ------------------ diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index 5285309f..a8d19e9d 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -173,22 +173,29 @@ def ConvertInotoCpp(env): continue ino_contents = item.get_text_contents() - # fetch prototypes - regexp = re.compile( + re_includes = re.compile(r"^(#include\s+(?:\<|\")[^\r\n]+)", + re.M | re.I) + includes = re_includes.findall(ino_contents) + prototypes = re.findall( r"""^( (?:\s*[a-z_\d]+){1,2} # return type \s+[a-z_\d]+\s* # name of prototype \([a-z_,\.\*\&\[\]\s\d]*\) # args )\s*\{ # must end with { """, + ino_contents, re.X | re.M | re.I ) - prototypes = regexp.findall(ino_contents) - # print prototypes + # print includes, prototypes + + # disable previous includes + ino_contents = re_includes.sub("//\g<1>", ino_contents) # create new temporary C++ valid file with open(cppfile, "w") as f: f.write("#include \n") + if includes: + f.write("%s\n" % "\n".join(includes)) if prototypes: f.write("%s;\n" % ";\n".join(prototypes)) f.write("#line 1 \"%s\"\n" % basename(item.path))