Fix re-arranging the *.ino/pde files when converting to *.cpp // Resolve #100

This commit is contained in:
Ivan Kravets committed 2015-03-20 21:55:08 +02:00
1 parent b4a253110d
commit a8a9451c73
2 files changed
+14 -13

No files matched your search

+8 -11
View File
@@ -176,7 +176,11 @@ def BuildDependentLibraries(env, src_dir): # pylint: disable=R0914
for ld in listdir(lsd_dir):
inc_path = normpath(join(lsd_dir, ld, self.name))
lib_dir = inc_path[:inc_path.index(sep, len(lsd_dir) + 1)]
try:
lib_dir = inc_path[:inc_path.index(
sep, len(lsd_dir) + 1)]
except ValueError:
continue
lib_name = basename(lib_dir)
# ignore user's specified libs
@@ -284,9 +288,6 @@ def ConvertInoToCpp(env):
continue
ino_contents = item.get_text_contents()
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
@@ -297,19 +298,15 @@ def ConvertInoToCpp(env):
ino_contents,
re.X | re.M | re.I
)
# print includes, prototypes
# disable previous includes
ino_contents = re_includes.sub(r"//\1", ino_contents)
prototypes = [p.strip() for p in prototypes]
# print prototypes
# create new temporary C++ valid file
with open(cppfile, "w") as f:
f.write("#include <Arduino.h>\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))
f.write('#line 1 "%s"\n' % basename(item.path))
f.write(ino_contents)
tmpcpp.append(cppfile)