From fd924f29f3ac9ca783ca3d8cb0d798cfd4d25cd8 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 6 Jul 2016 15:28:39 +0300 Subject: [PATCH 1/7] Update examples --- examples | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples b/examples index ed668f6e..6c0a7e44 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit ed668f6e31d2f99736b10cac209bd59318aa6ecb +Subproject commit 6c0a7e4458056fa04657a14422aeae277560341d From f767feeef9cd93f9a30d1611d74e7a3c99d86708 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 7 Jul 2016 00:26:33 +0300 Subject: [PATCH 2/7] Add new articles --- docs/articles.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/articles.rst b/docs/articles.rst index 3dbe604c..3ceb7fce 100644 --- a/docs/articles.rst +++ b/docs/articles.rst @@ -23,6 +23,9 @@ Here are recent articles about PlatformIO: 2016 ^^^^ +* Jul 5, 2016 - **Ivan Kravets, Ph.D.** - `Explore the new development instruments for Arduino with PlatformIO ecosystem `_ +* Jul 5, 2016 - **Belinda** - `Monte Bianco Arduino Developer Summit `_ +* Jul 1, 2016 - **Tam Hanna** - `Mikrocontroller-Gipfel in den Alpen: Arduino Developer Summit, Tag eins (Microcontroller peaks in the Alps: Arduino Developer Summit, Day One, German) `_ * Jun 14, 2016 - **Glyn Hudson** - `OpenEnergyMonitor Part 2/3: Firmware Continuous Test & Build `_ * Jun 13, 2016 - **Daniel Eichhorn** - `New Weather Station Demo on Github `_ * Jun 12, 2016 - **Glyn Hudson** - `OpenEnergyMonitor Part 1/3: PlatformIO open-source embedded development ecosystem `_ From e33e950712eac0f1314a9f90d689c2786a5e8cbc Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 9 Jul 2016 14:38:49 +0300 Subject: [PATCH 3/7] Add example dynamic `build_flags` --- docs/projectconf.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/projectconf.rst b/docs/projectconf.rst index f7dbc86c..f340833b 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -351,6 +351,10 @@ Example: [env:specific_ld_script] build_flags = -Wl,-T/path/to/ld_script.ld + [env:exec_command] + # get VCS revision "on-the-fly" + build_flags = !echo "-DPIO_SRC_REV="$(git rev-parse HEAD) + For more detailed information about available flags/options go to: From a73a710364a7f16ee1b96d1d4111a431c77ff0b8 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 9 Jul 2016 15:16:42 +0300 Subject: [PATCH 4/7] Iterating the dictionary directly instead of calling .keys() --- platformio/builder/scripts/frameworks/mbed.py | 2 +- platformio/builder/tools/platformio.py | 2 +- platformio/commands/lib.py | 2 +- platformio/maintenance.py | 4 ++-- platformio/telemetry.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/platformio/builder/scripts/frameworks/mbed.py b/platformio/builder/scripts/frameworks/mbed.py index 3c7dc2e0..16503122 100644 --- a/platformio/builder/scripts/frameworks/mbed.py +++ b/platformio/builder/scripts/frameworks/mbed.py @@ -86,7 +86,7 @@ MBED_LIBS_MAP = { def get_mbedlib_includes(): result = [] - for lib in MBED_LIBS_MAP.keys(): + for lib in MBED_LIBS_MAP: includes = [] lib_dir = join(env.subst("$PLATFORMFW_DIR"), "libs", lib) for _, _, files in walk(lib_dir): diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index e1b599c8..c9758fa1 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -154,7 +154,7 @@ def ProcessUnFlags(env, flags): all_flags.extend(items) all_flags = set(all_flags) - for key in parsed_flags.keys(): + for key in parsed_flags: cur_flags = set(env.get(key, [])) for item in cur_flags & all_flags: while item in env[key]: diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index f2bd73e5..bbf8bb09 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -153,7 +153,7 @@ def lib_install(ctx, libid, version): def lib_install_dependency(ctx, data): assert isinstance(data, dict) query = [] - for key in data.keys(): + for key in data: if key in ("authors", "frameworks", "platforms", "keywords"): values = data[key] if not isinstance(values, list): diff --git a/platformio/maintenance.py b/platformio/maintenance.py index 34395604..d2e944eb 100644 --- a/platformio/maintenance.py +++ b/platformio/maintenance.py @@ -101,7 +101,7 @@ class Upgrader(object): prev_platforms = [] # remove platform's folder (obsolete package structure) - for name in PlatformFactory.get_platforms().keys(): + for name in PlatformFactory.get_platforms(): pdir = join(get_home_dir(), name) if not isdir(pdir): continue @@ -234,7 +234,7 @@ def check_internal_updates(ctx, what): outdated_items = [] if what == "platforms": - for platform in PlatformFactory.get_platforms(installed=True).keys(): + for platform in PlatformFactory.get_platforms(installed=True): p = PlatformFactory.newPlatform(platform) if p.is_outdated(): outdated_items.append(platform) diff --git a/platformio/telemetry.py b/platformio/telemetry.py index 48ca79ab..f8fea43c 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -326,7 +326,7 @@ def backup_reports(items): for params in items: # skip static options - for key in params.keys(): + for key in params: if key in ("v", "tid", "cid", "cd1", "cd2", "sr", "an"): del params[key] From f12c721f448db3d22e7204d55f8324db44189506 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 9 Jul 2016 15:26:38 +0300 Subject: [PATCH 5/7] Iterating the dictionary directly instead of calling .keys() --- platformio/platforms/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformio/platforms/base.py b/platformio/platforms/base.py index 8486967d..5566f37b 100644 --- a/platformio/platforms/base.py +++ b/platformio/platforms/base.py @@ -330,7 +330,7 @@ class BasePlatform(object): def get_installed_packages(self): pm = PackageManager() - return [n for n in self.get_packages().keys() if pm.is_installed(n)] + return [n for n in self.get_packages() if pm.is_installed(n)] def install(self, with_packages=None, without_packages=None, skip_default_packages=False): @@ -380,7 +380,7 @@ class BasePlatform(object): deppkgs = deppkgs.union(set(p.get_packages().keys())) pm = PackageManager() - for name in self.get_packages().keys(): + for name in self.get_packages(): if not pm.is_installed(name) or name in deppkgs: continue pm.uninstall(name) From a0d9173b4f3f961cb0d1634bd346ee881eab7474 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 9 Jul 2016 18:44:45 +0300 Subject: [PATCH 6/7] Add "Rebuild C/C++ Project Index" target to CLion and Eclipse IDEs --- HISTORY.rst | 1 + docs/ide/clion.rst | 18 +++-- docs/ide/eclipse.rst | 19 ++++-- platformio/__init__.py | 2 +- platformio/builder/tools/piomisc.py | 10 ++- platformio/commands/init.py | 25 +++++-- platformio/ide/projectgenerator.py | 7 +- .../ide/tpls/clion/.idea/workspace.xml.tpl | 65 ++++++------------- platformio/ide/tpls/clion/CMakeLists.txt.tpl | 11 ++-- .../ide/tpls/clion/CMakeListsPrivate.txt.tpl | 13 +++- platformio/ide/tpls/eclipse/.cproject.tpl | 8 +++ platformio/telemetry.py | 2 +- 12 files changed, 107 insertions(+), 74 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 8cad7732..c9629b4d 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,6 +11,7 @@ PlatformIO 2.0 * Updated Microchip PIC32 Arduino framework to v1.2.1 * Documented `uploading of EEPROM data `__ (from EEMEM directive) +* Added ``Rebuild C/C++ Project Index`` target to CLion and Eclipse IDEs * Improved project generator for `CLion IDE `__ * Auto-remove project cache when PlatformIO is upgraded * Keep user changes for ``.gitignore`` file when re-generate/update project data diff --git a/docs/ide/clion.rst b/docs/ide/clion.rst index 89ad7cfa..bbd6584a 100644 --- a/docs/ide/clion.rst +++ b/docs/ide/clion.rst @@ -53,16 +53,20 @@ There are 6 predefined targets for building (*NOT FOR RUNNING*, see marks on the screenshot below): * ``PLATFORMIO_BUILD`` - Build project without auto-uploading -* ``PLATFORMIO_UPLOAD`` - Build and upload (if no errors). -* ``PLATFORMIO_CLEAN`` - Clean compiled objects. -* ``PLATFORMIO_PROGRAM`` - Build and upload using external programmer (if no errors), see :ref:`atmelavr_upload_via_programmer`. -* ``PLATFORMIO_UPLOADFS`` - Upload files to file system SPIFFS, see :ref:`platform_espressif_uploadfs`. -* ``PLATFORMIO_UPDATE`` - Update installed platforms and libraries via :ref:`cmd_update`. +* ``PLATFORMIO_UPLOAD`` - Build and upload (if no errors) +* ``PLATFORMIO_CLEAN`` - Clean compiled objects +* ``PLATFORMIO_PROGRAM`` - Build and upload using external programmer + (if no errors), see :ref:`atmelavr_upload_via_programmer` +* ``PLATFORMIO_UPLOADFS`` - Upload files to file system SPIFFS, + see :ref:`platform_espressif_uploadfs` +* ``PLATFORMIO_UPDATE`` - Update installed platforms and libraries via :ref:`cmd_update` +* ``PLATFORMIO_REBUILD_PROJECT_INDEX`` - Rebuild C/C++ Index for the Project. + Allows to fix code completion and code linting issues. .. warning:: The libraries which are added, installed or used in the project - after generating process wont be reflected in IDE. To fix it you - need to reinitialize project using :ref:`cmd_init` (repeat it). + after generating process wont be reflected in IDE. To fix it please run + ``PLATFORMIO_REBUILD_PROJECT_INDEX`` target. Articles / Manuals ------------------ diff --git a/docs/ide/eclipse.rst b/docs/ide/eclipse.rst index 230de1f9..2ef869f8 100644 --- a/docs/ide/eclipse.rst +++ b/docs/ide/eclipse.rst @@ -51,7 +51,7 @@ Then: ``Menu: File > Import... > General > Existing Projects into Workspace > Next`` and specify root directory where is located :ref:`projectconf` 2. Open source file from ``src`` directory (``*.c, *.cpp, *.ino, etc.``) -3. Build project using ``Menu: Project > Build Project`` or preconfigured +3. Build project using ``Menu: Project > Build Project`` or pre-configured Make Targets (see screenshot below): + ``PlatformIO: Build`` - Build project without auto-uploading @@ -59,17 +59,24 @@ Then: + ``PlatformIO: Upload`` - Build and upload (if no errors) + ``PlatformIO: Upload using Programmer`` see :ref:`atmelavr_upload_via_programmer` + ``PlatformIO: Upload SPIFFS image`` see :ref:`platform_espressif_uploadfs` - + ``PlatformIO: Update platforms and libraries`` - Update installed platforms and libraries via :ref:`cmd_update`. + + ``PlatformIO: Update platforms and libraries`` - Update installed + platforms and libraries via :ref:`cmd_update` + + ``PlatformIO: Rebuild C/C++ Project Index`` - Rebuild C/C++ Index for the Project. + Allows to fix code completion and code linting issues. If you have some problems with unresolved includes, defines, etc., then -* Restart Eclipse IDE -* Rebuild index using ``Menu: Project > C/C++ Index > Rebuild``. +1. Rebuild PlatformIO Project Index: + ``PlatformIO: Rebuild C/C++ Project Index`` target +2. Rebuild Eclipse Project Index: ``Menu: Project > C/C++ Index > Rebuild`` +3. Refresh Project, right click on the project ``Project > Refresh`` (F5) or + restart Eclipse IDE. .. warning:: The libraries which are added, installed or used in the project - after generating process wont be reflected in IDE. To fix it you - need to reinitialize project using :ref:`cmd_init` (repeat it). + after generating process wont be reflected in IDE. To fix it please run + ``PlatformIO: Rebuild C/C++ Project Index`` target and right click on the + project and ``Project > Refresh`` (F5). Live Integration ---------------- diff --git a/platformio/__init__.py b/platformio/__init__.py index 1891ceb7..adf76f97 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -14,7 +14,7 @@ import sys -VERSION = (2, 11, "1.dev1") +VERSION = (2, 11, "1.dev2") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/builder/tools/piomisc.py b/platformio/builder/tools/piomisc.py index a848ea0e..29ab41a2 100644 --- a/platformio/builder/tools/piomisc.py +++ b/platformio/builder/tools/piomisc.py @@ -202,7 +202,9 @@ def DumpIDEData(env): def get_defines(env_): defines = [] # global symbols - for item in env.Flatten(env_.get("CPPDEFINES", [])): + for item in env_.get("CPPDEFINES", []): + if isinstance(item, list) or isinstance(item, tuple): + item = "=".join(item) defines.append(env_.subst(item).replace('\\"', '"')) # special symbol for Atmel AVR MCU @@ -224,13 +226,17 @@ def DumpIDEData(env): "includes": get_includes(env_), "cc_flags": env_.subst(LINTCCOM), "cxx_flags": env_.subst(LINTCXXCOM), + "cc_path": where_is_program( + env_.subst("$CC"), env_.subst("${ENV['PATH']}")), "cxx_path": where_is_program( env_.subst("$CXX"), env_.subst("${ENV['PATH']}")) } # https://github.com/platformio/platformio-atom-ide/issues/34 _new_defines = [] - for item in env.Flatten(env_.get("CPPDEFINES", [])): + for item in env_.get("CPPDEFINES", []): + if isinstance(item, list) or isinstance(item, tuple): + item = "=".join(item) item = item.replace('\\"', '"') if " " in item: _new_defines.append(item.replace(" ", "\\\\ ")) diff --git a/platformio/commands/init.py b/platformio/commands/init.py index d9b48288..550e839c 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -23,11 +23,10 @@ from platformio.commands.platforms import \ platforms_install as cli_platforms_install from platformio.ide.projectgenerator import ProjectGenerator from platformio.platforms.base import PlatformFactory -from platformio.util import get_boards, get_source_dir def validate_boards(ctx, param, value): # pylint: disable=W0613 - unknown_boards = set(value) - set(get_boards().keys()) + unknown_boards = set(value) - set(util.get_boards().keys()) try: assert not unknown_boards return value @@ -84,6 +83,10 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 ) if ide: + if not board: + board = get_first_board(project_dir) + if board: + board = [board] if not board: raise exception.BoardNotDefined() if len(board) > 1: @@ -95,8 +98,7 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 " '%s'." % (board[0], ", ".join(board)), fg="yellow" ) - pg = ProjectGenerator( - project_dir, ide, board[0]) + pg = ProjectGenerator(project_dir, ide, board[0]) pg.generate() click.secho( @@ -112,10 +114,21 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 ) +def get_first_board(project_dir): + with util.cd(project_dir): + config = util.get_project_config() + for section in config.sections(): + if not section.startswith("env:"): + continue + elif config.has_option(section, "board"): + return config.get(section, "board") + return None + + def init_base_project(project_dir): platformio_ini = join(project_dir, "platformio.ini") if not isfile(platformio_ini): - copyfile(join(get_source_dir(), "projectconftpl.ini"), + copyfile(join(util.get_source_dir(), "projectconftpl.ini"), platformio_ini) lib_dir = join(project_dir, "lib") @@ -260,7 +273,7 @@ def init_cvs_ignore(project_dir): def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals ctx, platformio_ini, board_types, enable_auto_uploading, env_prefix, force_download): - builtin_boards = get_boards() + builtin_boards = util.get_boards() content = [] used_boards = [] used_platforms = [] diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 102f7878..4c8c210f 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -32,6 +32,9 @@ class ProjectGenerator(object): self.board = board self._tplvars = {} + with util.cd(self.project_dir): + self.project_src_dir = util.get_projectsrc_dir() + self._gather_tplvars() @staticmethod @@ -94,7 +97,8 @@ class ProjectGenerator(object): def get_src_files(self): result = [] with util.cd(self.project_dir): - for root, _, files in os.walk(util.get_projectsrc_dir()): + for root, _, files in os.walk(self.project_src_dir): + print root, files for f in files: result.append(relpath(join(root, f))) return result @@ -157,6 +161,7 @@ class ProjectGenerator(object): "src_files": self.get_src_files(), "user_home_dir": abspath(expanduser("~")), "project_dir": self.project_dir, + "project_src_dir": self.project_src_dir, "systype": util.get_systype(), "platformio_path": self._fix_os_path( util.where_is_program("platformio")), diff --git a/platformio/ide/tpls/clion/.idea/workspace.xml.tpl b/platformio/ide/tpls/clion/.idea/workspace.xml.tpl index 582177fb..59426c43 100644 --- a/platformio/ide/tpls/clion/.idea/workspace.xml.tpl +++ b/platformio/ide/tpls/clion/.idea/workspace.xml.tpl @@ -10,6 +10,7 @@ + @@ -39,28 +40,14 @@ - - - - - - - - - + + % for file in src_files: - - - - - - - - - + + - % end + % end @@ -113,6 +100,8 @@ + + @@ -120,13 +109,13 @@ @@ -201,7 +190,11 @@ - + + + + + @@ -209,6 +202,7 @@ + @@ -225,27 +219,10 @@ - + - - - - - - - - - - - - - - - - - - + @@ -280,4 +257,4 @@ - \ No newline at end of file + diff --git a/platformio/ide/tpls/clion/CMakeLists.txt.tpl b/platformio/ide/tpls/clion/CMakeLists.txt.tpl index 9b56290c..a31664d0 100644 --- a/platformio/ide/tpls/clion/CMakeLists.txt.tpl +++ b/platformio/ide/tpls/clion/CMakeLists.txt.tpl @@ -3,10 +3,6 @@ project({{project_name}}) include(CMakeListsPrivate.txt) -% for define in defines: -add_definitions(-D{{!define}}) -% end - add_custom_target( PLATFORMIO_BUILD ALL COMMAND ${PLATFORMIO_CMD} -f -c clion run @@ -43,5 +39,10 @@ add_custom_target( WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) -aux_source_directory(src SRC_LIST) +add_custom_target( + PLATFORMIO_REBUILD_PROJECT_INDEX ALL + COMMAND ${PLATFORMIO_CMD} -f -c clion init --ide clion + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + add_executable(${PROJECT_NAME} ${SRC_LIST}) diff --git a/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl b/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl index ef859843..40414aa8 100644 --- a/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl +++ b/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl @@ -1,6 +1,15 @@ set(ENV{PATH} "{{env_path}}") set(PLATFORMIO_CMD "{{platformio_path}}") +SET(CMAKE_C_COMPILER "{{cc_path}}") +SET(CMAKE_CXX_COMPILER "{{cxx_path}}") +SET(CMAKE_CXX_FLAGS_DISTRIBUTION "{{cxx_flags}}") +SET(CMAKE_C_FLAGS_DISTRIBUTION "{{cc_flags}}") + +% for define in defines: +add_definitions(-D{{!define}}) +% end + % for include in includes: % if include.startswith(user_home_dir): % if "windows" in systype: @@ -11,4 +20,6 @@ include_directories("$ENV{HOME}{{include.replace(user_home_dir, '').replace("\\" % else: include_directories("{{include.replace("\\", "/")}}") % end -% end \ No newline at end of file +% end + +aux_source_directory({{project_src_dir}} SRC_LIST) diff --git a/platformio/ide/tpls/eclipse/.cproject.tpl b/platformio/ide/tpls/eclipse/.cproject.tpl index b21e2aa5..fb03c356 100644 --- a/platformio/ide/tpls/eclipse/.cproject.tpl +++ b/platformio/ide/tpls/eclipse/.cproject.tpl @@ -166,6 +166,14 @@ true false + + platformio + -f -c eclipse + init --ide eclipse + true + true + false + diff --git a/platformio/telemetry.py b/platformio/telemetry.py index f8fea43c..48ca79ab 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -326,7 +326,7 @@ def backup_reports(items): for params in items: # skip static options - for key in params: + for key in params.keys(): if key in ("v", "tid", "cid", "cd1", "cd2", "sr", "an"): del params[key] From 005665144771f7a69b9ddb70d4234769e6cde6be Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 9 Jul 2016 18:49:35 +0300 Subject: [PATCH 7/7] Remove debug info --- platformio/ide/projectgenerator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 4c8c210f..4c0a4365 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -98,7 +98,6 @@ class ProjectGenerator(object): result = [] with util.cd(self.project_dir): for root, _, files in os.walk(self.project_src_dir): - print root, files for f in files: result.append(relpath(join(root, f))) return result