forked from platformio/platformio-core
Improve handling of multi-file `*.ino/pde
` sketches // Resolve #130
This commit is contained in:
@ -1,6 +1,13 @@
|
|||||||
Release History
|
Release History
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
1.3.0 (2015-??-??)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
* Improved handling of multi-file ``*.ino/pde`` sketches
|
||||||
|
(`issue #130 <https://github.com/ivankravets/platformio/issues/130>`_)
|
||||||
|
|
||||||
|
|
||||||
1.2.0 (2015-03-20)
|
1.2.0 (2015-03-20)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
# See LICENSE for details.
|
# See LICENSE for details.
|
||||||
|
|
||||||
VERSION = (1, 2, 0)
|
VERSION = (1, 3, "0.dev0")
|
||||||
__version__ = ".".join([str(s) for s in VERSION])
|
__version__ = ".".join([str(s) for s in VERSION])
|
||||||
|
|
||||||
__title__ = "platformio"
|
__title__ = "platformio"
|
||||||
|
@ -275,43 +275,54 @@ def BuildDependentLibraries(env, src_dir): # pylint: disable=R0914
|
|||||||
|
|
||||||
def ConvertInoToCpp(env):
|
def ConvertInoToCpp(env):
|
||||||
|
|
||||||
def delete_tmpcpp(files):
|
PROTOTYPE_RE = re.compile(
|
||||||
for f in files:
|
r"""^(
|
||||||
remove(f)
|
(?:\s*[a-z_\d]+){1,2} # return type
|
||||||
|
\s+[a-z_\d]+\s* # name of prototype
|
||||||
|
\([a-z_,\.\*\&\[\]\s\d]*\) # arguments
|
||||||
|
)\s*\{ # must end with {
|
||||||
|
""",
|
||||||
|
re.X | re.M | re.I
|
||||||
|
)
|
||||||
|
|
||||||
tmpcpp = []
|
DETECTMAIN_RE = re.compile(r"void\s+(setup|loop)\s*\(", re.M | re.I)
|
||||||
items = (env.Glob(join("$PROJECTSRC_DIR", "*.ino")) +
|
|
||||||
env.Glob(join("$PROJECTSRC_DIR", "*.pde")))
|
|
||||||
for item in items:
|
|
||||||
cppfile = item.get_path()[:-3] + "cpp"
|
|
||||||
if isfile(cppfile):
|
|
||||||
continue
|
|
||||||
ino_contents = item.get_text_contents()
|
|
||||||
|
|
||||||
prototypes = re.findall(
|
def delete_tmpcpp_file(file_):
|
||||||
r"""^(
|
remove(file_)
|
||||||
(?:\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 = [p.strip() for p in prototypes]
|
|
||||||
# print prototypes
|
|
||||||
|
|
||||||
# create new temporary C++ valid file
|
def is_main_ino(contents):
|
||||||
with open(cppfile, "w") as f:
|
return DETECTMAIN_RE.search(contents)
|
||||||
f.write("#include <Arduino.h>\n")
|
|
||||||
if prototypes:
|
|
||||||
f.write("%s;\n" % ";\n".join(prototypes))
|
|
||||||
f.write('#line 1 "%s"\n' % basename(item.path))
|
|
||||||
f.write(ino_contents)
|
|
||||||
tmpcpp.append(cppfile)
|
|
||||||
|
|
||||||
if tmpcpp:
|
ino_nodes = (env.Glob(join("$PROJECTSRC_DIR", "*.ino")) +
|
||||||
atexit.register(delete_tmpcpp, tmpcpp)
|
env.Glob(join("$PROJECTSRC_DIR", "*.pde")))
|
||||||
|
prototypes = []
|
||||||
|
data = []
|
||||||
|
for node in ino_nodes:
|
||||||
|
ino_contents = node.get_text_contents()
|
||||||
|
prototypes += PROTOTYPE_RE.findall(ino_contents)
|
||||||
|
|
||||||
|
item = (basename(node.get_path()), ino_contents)
|
||||||
|
if is_main_ino(ino_contents):
|
||||||
|
data = [item] + data
|
||||||
|
else:
|
||||||
|
data.append(item)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return
|
||||||
|
|
||||||
|
# create new temporary C++ valid file
|
||||||
|
tmpcpp_file = join(env.subst("$PROJECTSRC_DIR"), "piomain.cpp")
|
||||||
|
with open(tmpcpp_file, "w") as f:
|
||||||
|
f.write("#include <Arduino.h>\n")
|
||||||
|
|
||||||
|
if prototypes:
|
||||||
|
f.write("%s;" % ";\n".join(prototypes))
|
||||||
|
|
||||||
|
for name, contents in data:
|
||||||
|
f.write('\n#line 1 "%s"\n' % name)
|
||||||
|
f.write(contents)
|
||||||
|
|
||||||
|
atexit.register(delete_tmpcpp_file, tmpcpp_file)
|
||||||
|
|
||||||
|
|
||||||
def exists(_):
|
def exists(_):
|
||||||
|
Reference in New Issue
Block a user