-
-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve #7: add auto-conversation from *.ino to valid *.cpp for Ardui…
…no/Energia frameworks
- Loading branch information
1 parent
1b75d3e
commit 00e5155
Showing
2 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# Copyright (C) Ivan Kravets <[email protected]> | ||
# See LICENSE for details. | ||
|
||
import atexit | ||
import re | ||
from os import getenv, listdir, walk | ||
from os.path import isdir, isfile, join | ||
from os import getenv, listdir, remove, walk | ||
from os.path import basename, isdir, isfile, join | ||
|
||
from SCons.Script import SConscript, SConscriptChdir | ||
|
||
|
@@ -19,6 +20,8 @@ def ProcessGeneral(env): | |
) | ||
|
||
if "FRAMEWORK" in env: | ||
if env['FRAMEWORK'] in ("arduino", "energia"): | ||
env.ConvertInotoCpp() | ||
SConscriptChdir(0) | ||
corelibs = SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", | ||
"frameworks", "${FRAMEWORK}.py")), | ||
|
@@ -79,11 +82,9 @@ def BuildDependentLibraries(env, src_dir): | |
|
||
def GetDependentLibraries(env, src_dir): | ||
includes = {} | ||
regexp = re.compile(r"^\s?#include\s+(?:\<|\"|\')([^\>\"\']+)(?:\>|\"|\')", | ||
re.M) | ||
regexp = re.compile(r"^\s*#include\s+(?:\<|\")([^\>\"\']+)(?:\>|\")", re.M) | ||
for node in env.GlobCXXFiles(src_dir): | ||
env.ParseIncludesRecurive(regexp, node, includes) | ||
|
||
includes = sorted(includes.items(), key=lambda s: s[0]) | ||
return set([(i[1][1], i[1][2]) for i in includes]) | ||
|
||
|
@@ -150,6 +151,46 @@ def ParseBoardOptions(env, path, name): | |
return data | ||
|
||
|
||
def ConvertInotoCpp(env): | ||
|
||
def delete_tmpcpp(files): | ||
for f in files: | ||
remove(f) | ||
|
||
tmpcpp = [] | ||
|
||
for item in env.Glob(join("$PROJECT_DIR", "src", "*.ino")): | ||
cppfile = item.get_path()[:-3] + "cpp" | ||
if isfile(cppfile): | ||
continue | ||
ino_contents = item.get_text_contents() | ||
|
||
# fetch prototypes | ||
regexp = re.compile( | ||
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 { | ||
""", | ||
re.X | re.M | re.I | ||
) | ||
prototypes = regexp.findall(ino_contents) | ||
# print prototypes | ||
|
||
# create new temporary C++ valid file | ||
with open(cppfile, "w") as f: | ||
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: | ||
atexit.register(delete_tmpcpp, tmpcpp) | ||
|
||
|
||
def exists(_): | ||
return True | ||
|
||
|
@@ -164,4 +205,5 @@ def generate(env): | |
env.AddMethod(ParseIncludesRecurive) | ||
env.AddMethod(VariantDirRecursive) | ||
env.AddMethod(ParseBoardOptions) | ||
env.AddMethod(ConvertInotoCpp) | ||
return env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters