Initial support of PlatformIO Project Generator // Issue #151

This commit is contained in:
Ivan Kravets
2015-04-24 14:43:13 +01:00
parent 97044bf5a5
commit 6fd07e1e56
13 changed files with 348 additions and 4 deletions

View File

@ -1,3 +1,3 @@
[settings]
line_length=79
known_third_party=click,requests,serial,SCons,pytest
known_third_party=click,requests,serial,SCons,pytest,bottle

View File

@ -1,7 +1,7 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details.
VERSION = (2, 0, "0.dev2")
VERSION = (2, 0, "0.dev3")
__version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio"

View File

@ -8,6 +8,7 @@ from shutil import copyfile
import click
from platformio import app, exception
from platformio.ide.projectgenerator import ProjectGenerator
from platformio.util import get_boards, get_source_dir
@ -28,9 +29,11 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613
writable=True, resolve_path=True))
@click.option("--board", "-b", multiple=True, metavar="TYPE",
callback=validate_boards)
@click.option("--ide",
type=click.Choice(ProjectGenerator.get_supported_ides()))
@click.option("--disable-auto-uploading", is_flag=True)
@click.option("--env-prefix", default="autogen_")
def cli(project_dir, board, disable_auto_uploading, env_prefix):
def cli(project_dir, board, ide, disable_auto_uploading, env_prefix):
# ask about auto-uploading
if board and app.get_setting("enable_prompts"):
@ -82,6 +85,10 @@ def cli(project_dir, board, disable_auto_uploading, env_prefix):
fill_project_envs(
project_file, board, disable_auto_uploading, env_prefix)
if ide:
pg = ProjectGenerator(project_dir, ide)
pg.generate()
click.secho(
"\nProject has been successfully initialized!\nUseful commands:\n"
"`platformio run` - process/build project from the current "

View File

@ -0,0 +1,2 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details.

View File

@ -0,0 +1,63 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details.
from glob import glob
from os import listdir
from os.path import basename, isdir, join
import bottle
from platformio import util
class ProjectGenerator(object):
def __init__(self, project_dir, ide):
self.project_dir = project_dir
self.ide = ide
self._tplvars = self._gather_tplvars()
@staticmethod
def get_supported_ides():
tpls_dir = join(util.get_source_dir(), "ide", "tpls")
return [d for d in listdir(tpls_dir)
if isdir(join(tpls_dir, d))]
@staticmethod
def get_project_env():
data = {}
config = util.get_project_config()
for section in config.sections():
if not section.startswith("env:"):
continue
for k, v in config.items(section):
data[k] = v
return data
def get_project_name(self):
return basename(self.project_dir)
def get_tpls(self):
tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide)
return glob(join(tpls_dir, ".*.tpl")) + glob(join(tpls_dir, "*.tpl"))
def generate(self):
for tpl_path in self.get_tpls():
file_name = basename(tpl_path)[:-4]
with open(join(self.project_dir, file_name), "w") as f:
f.write(self._render_tpl(tpl_path))
def _render_tpl(self, tpl_path):
content = ""
with open(tpl_path) as f:
content = f.read()
return bottle.template(content, **self._tplvars)
def _gather_tplvars(self):
data = self.get_project_env()
data.update({
"project_name": self.get_project_name()
})
return data

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="0.910961921">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.910961921" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="0.910961921" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.910961921." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.952979152" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform binaryParser="org.eclipse.cdt.core.ELF" id="org.eclipse.cdt.build.core.prefbase.toolchain.952979152.52310970" name=""/>
<builder cleanBuildTarget="--force run --target clean" command="platformio" id="org.eclipse.cdt.build.core.settings.default.builder.1519453406" incrementalBuildTarget="--force run" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.1409095472" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.1624502120" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.239157887" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${HOME}/.platformio/packages/toolchain-atmelavr/avr/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${HOME}/.platformio/packages/framework-arduinoavr/cores/arduino&quot;"/>
</option>
<option id="org.eclipse.cdt.build.core.settings.holder.symbols.922107295" name="Symbols" superClass="org.eclipse.cdt.build.core.settings.holder.symbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="__AVR_ATmega168__"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.149990277" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.54121539" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1096940598" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${HOME}/.platformio/atmelavr/tools/toolchain/avr/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${HOME}/.platformio/atmelavr/frameworks/arduino/cores/arduino&quot;"/>
<listOptionValue builtIn="false" value="&quot;${HOME}/.platformio/packages/toolchain-atmelavr/avr/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${HOME}/.platformio/packages/framework-arduinoavr/cores/arduino&quot;"/>
</option>
<option id="org.eclipse.cdt.build.core.settings.holder.symbols.1198905600" name="Symbols" superClass="org.eclipse.cdt.build.core.settings.holder.symbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="__AVR_ATmega168__"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.762536863" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1310559623" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.41298875" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${HOME}/.platformio/atmelavr/tools/toolchain/avr/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${HOME}/.platformio/atmelavr/frameworks/arduino/cores/arduino&quot;"/>
<listOptionValue builtIn="false" value="&quot;${HOME}/.platformio/packages/toolchain-atmelavr/avr/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${HOME}/.platformio/packages/framework-arduinoavr/cores/arduino&quot;"/>
</option>
<option id="org.eclipse.cdt.build.core.settings.holder.symbols.884639970" name="Symbols" superClass="org.eclipse.cdt.build.core.settings.holder.symbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="__AVR_ATmega168__"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.549319812" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="arduino_pro5.null.189551033" name="arduino_pro5"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.910961921">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Default">
<resource resourceType="PROJECT" workspacePath="/arduino_pro5"/>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cproject>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>{{project_name}}</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,19 @@
win32 {
HOMEDIR += $$(USERPROFILE)
}
else {
HOMEDIR += $$(PWD)
}
INCLUDEPATH += "$$HOMEDIR/.platformio/packages/framework-arduinoavr/cores/arduino"
INCLUDEPATH += "$$HOMEDIR/.platformio/packages/toolchain-atmelavr/avr/include"
win32:INCLUDEPATH ~= s,/,\\,g
# DEFINES += __AVR_ATmega328__
OTHER_FILES += \
platformio.ini
SOURCES += \
src/main.c

View File

@ -0,0 +1,45 @@
{
"build_systems":
[
{
"cmd":
[
"platformio",
"run"
],
"name": "{{project_name}}",
"variants":
[
{
"cmd":
[
"platformio",
"--force",
"run",
"--target",
"clean"
],
"name": "Clean"
},
{
"cmd":
[
"platformio",
"--force",
"run",
"--target",
"upload"
],
"name": "Upload"
}
],
"working_dir": "${project_path:${folder}}"
}
],
"folders":
[
{
"path": "."
}
]
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Source Files\src">
<UniqueIdentifier>{cad450ef-1a84-42d4-a5b5-a1736b8833d3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="readme.txt" />
</ItemGroup>
<ItemGroup>
<None Include="platformio.ini" />
<None Include="src\blink.pde">
<Filter>Source Files\src</Filter>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{0FA9C3A8-452B-41EF-A418-9102B170F49F}</ProjectGuid>
<Keyword>MakeFileProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<NMakeBuildCommandLine>platformio --force run</NMakeBuildCommandLine>
<NMakeCleanCommandLine>platformio --force run --target clean</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<NMakeIncludeSearchPath>$(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\toolchain-atmelavr\avr\include;$(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\framework-arduinoavr\cores\arduino;$(NMakeIncludeSearchPath)</NMakeIncludeSearchPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<NMakeBuildCommandLine>platformio run</NMakeBuildCommandLine>
<NMakeCleanCommandLine>platformio run -t clean</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>WIN32;NDEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<NMakeIncludeSearchPath>$(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\toolchain-atmelavr\avr\include;$(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\framework-arduinoavr\cores\arduino;$(NMakeIncludeSearchPath)</NMakeIncludeSearchPath>
</PropertyGroup>
<ItemDefinitionGroup>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="readme.txt" />
</ItemGroup>
<ItemGroup>
<None Include="platformio.ini" />
<None Include="src\blink.pde" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1,3 +1,4 @@
bottle=0.12.8
click==3.3
colorama==0.3.3
pyserial==2.7

View File

@ -18,13 +18,21 @@ setup(
url=__url__,
license=__license__,
install_requires=[
"bottle",
"click>=3.0",
"pyserial",
"requests>=2.4.0",
# "SCons"
] + (["colorama"] if system() == "Windows" else []),
packages=find_packages(),
package_data={"platformio": ["projectconftpl.ini", "boards/*.json"]},
package_data={
"platformio": [
"projectconftpl.ini",
"boards/*.json",
"ide/tpls/*/.*.tpl",
"ide/tpls/*/*.tpl"
]
},
entry_points={
"console_scripts": [
"platformio = platformio.__main__:main"