forked from platformio/platformio-core
Full support of CLion IDE including code auto-completion // Resolve #132
This commit is contained in:
1 parent
f758d8607a
commit
de2d6818c1
15 files changed
+105
-85
No files matched your search
@@ -1,7 +1,7 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
VERSION = (2, 3, "4.dev1")
|
||||
VERSION = (2, 3, "4.dev2")
|
||||
__version__ = ".".join([str(s) for s in VERSION])
|
||||
|
||||
__title__ = "platformio"
|
||||
|
||||
@@ -65,7 +65,7 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
click.style(project_dir, fg="cyan"))
|
||||
click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" %
|
||||
click.style("platformio.ini", fg="cyan"))
|
||||
click.echo("%s - Put your source code here" %
|
||||
click.echo("%s - Put your source files here" %
|
||||
click.style("src", fg="cyan"))
|
||||
click.echo("%s - Put here project specific (private) libraries" %
|
||||
click.style("lib", fg="cyan"))
|
||||
|
||||
@@ -7,6 +7,7 @@ import re
|
||||
from os.path import abspath, basename, expanduser, isdir, join, relpath
|
||||
|
||||
import bottle
|
||||
import click
|
||||
|
||||
from platformio import util
|
||||
|
||||
@@ -72,7 +73,7 @@ class ProjectGenerator(object):
|
||||
def get_project_name(self):
|
||||
return basename(self.project_dir)
|
||||
|
||||
def get_srcfiles(self):
|
||||
def get_src_files(self):
|
||||
result = []
|
||||
with util.cd(self.project_dir):
|
||||
for root, _, files in os.walk(util.get_projectsrc_dir()):
|
||||
@@ -80,6 +81,14 @@ class ProjectGenerator(object):
|
||||
result.append(relpath(join(root, f)))
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def get_main_src_file(src_files):
|
||||
for f in src_files:
|
||||
for ext in ("c", "cpp"):
|
||||
if f.endswith(".%s" % ext):
|
||||
return f
|
||||
return None
|
||||
|
||||
def get_tpls(self):
|
||||
tpls = []
|
||||
tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide)
|
||||
@@ -112,11 +121,23 @@ class ProjectGenerator(object):
|
||||
return bottle.template(content, **self._tplvars)
|
||||
|
||||
def _gather_tplvars(self):
|
||||
src_files = self.get_src_files()
|
||||
main_src_file = self.get_main_src_file(src_files)
|
||||
|
||||
if not main_src_file and self.ide == "clion":
|
||||
click.secho(
|
||||
"Warning! Can not find main source file (*.c, *.cpp). So, "
|
||||
"code auto-completion is disabled. Please add source files "
|
||||
"to `src` directory and re-initialize project or edit "
|
||||
"`CMakeLists.txt` file manually (`add_executable` command).",
|
||||
fg="yellow")
|
||||
|
||||
self._tplvars.update(self.get_project_env())
|
||||
self._tplvars.update(self.get_project_build_data())
|
||||
self._tplvars.update({
|
||||
"project_name": self.get_project_name(),
|
||||
"srcfiles": self.get_srcfiles(),
|
||||
"src_files": src_files,
|
||||
"main_src_file": main_src_file,
|
||||
"user_home_dir": abspath(expanduser("~")),
|
||||
"project_dir": self.project_dir,
|
||||
"systype": util.get_systype(),
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
% for file in srcfiles:
|
||||
% for file in src_files:
|
||||
<file leaf-file-name="{{file}}" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR/${{file}}">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
|
||||
@@ -8,7 +8,7 @@ set(PLATFORMIO_CMD "{{platformio_path}}")
|
||||
% if include.startswith(user_home_dir):
|
||||
include_directories("$ENV{HOME}{{include.replace(user_home_dir, '').replace("\\", "/")}}")
|
||||
% else:
|
||||
include_directories("{{include}}")
|
||||
include_directories("{{include.replace("\\", "/")}}")
|
||||
% end
|
||||
% end
|
||||
|
||||
@@ -32,4 +32,14 @@ add_custom_target(
|
||||
PLATFORMIO_CLEAN ALL
|
||||
COMMAND ${PLATFORMIO_CMD} -f -c clion run --target clean
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
)
|
||||
|
||||
% if main_src_file:
|
||||
add_executable({{project_name}} {{main_src_file}})
|
||||
% else:
|
||||
#
|
||||
# To enable code auto-completion, please specify path
|
||||
# to main source file (*.c, *.cpp) and uncomment line below
|
||||
#
|
||||
# add_executable({{project_name}} src/main_change_me.cpp)
|
||||
% end
|
||||
@@ -21,6 +21,6 @@ OTHER_FILES += \
|
||||
platformio.ini
|
||||
|
||||
SOURCES += \
|
||||
% for file in srcfiles:
|
||||
% for file in src_files:
|
||||
{{file}}
|
||||
% end
|
||||
@@ -13,7 +13,7 @@
|
||||
<ItemGroup>
|
||||
<None Include="platformio.ini" />
|
||||
</ItemGroup>
|
||||
% for file in srcfiles:
|
||||
% for file in src_files:
|
||||
<ItemGroup>
|
||||
% if any([file.endswith(".%s" % e) for e in ("h", "hh", "hpp", "inc")]):
|
||||
<ClInclude Include="{{file}}">
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<ItemGroup>
|
||||
<None Include="platformio.ini" />
|
||||
</ItemGroup>
|
||||
% for file in srcfiles:
|
||||
% for file in src_files:
|
||||
<ItemGroup>
|
||||
% if any([file.endswith(".%s" % e) for e in ("h", "hh", "hpp", "inc")]):
|
||||
<ClInclude Include="{{file}}">
|
||||
|
||||
Reference in new issue
Block a user