diff --git a/HISTORY.rst b/HISTORY.rst new file mode 100644 index 0000000000..12cf9c6cb1 --- /dev/null +++ b/HISTORY.rst @@ -0,0 +1,16 @@ +Release History +=============== + +0.2.0 (2014-06-15) +------------------ + +* Resolved `issue #1 "Build referred libraries" `_ +* Renamed project's "libs" directory to "lib" +* Added `arduino-internal-library `_ example +* Changed to beta status + + +0.1.0 (2014-06-13) +------------------ + +* Birth! First alpha release diff --git a/README.rst b/README.rst index 0b75a87efc..fd7a4def36 100644 --- a/README.rst +++ b/README.rst @@ -35,7 +35,9 @@ instruments. **Platformio** is well suited for **embedded development**. It can: -* Compile frameworks and libraries sources to static libraries +* Automatically analyse dependency +* Reliably detect build changes +* Build framework or library source code to static library * Build *ELF* (executable and linkable firmware) * Convert *ELF* to *HEX* or *BIN* file * Extract *EEPROM* data @@ -285,14 +287,14 @@ Initialize new platformio based project. # Example $ platformio init Project successfully initialized. - Please put your source code to `src` directory, external libraries to `libs` + Please put your source code to `src` directory, external libraries to `lib` and setup environments in `platformio.ini` file. Then process project with `platformio run` command. After this command ``platformio`` will create: * ``.pioenvs`` - a temporary working directory. -* ``libs`` - a directory for project specific libraries. Platformio will +* ``lib`` - a directory for project specific libraries. Platformio will compile their to static libraries and link to executable file * ``src`` - a source directory. Put code here. * ``platformio.ini`` - a configuration file for project diff --git a/examples/arduino-internal-library/README.rst b/examples/arduino-internal-library/README.rst new file mode 100644 index 0000000000..45ed35b935 --- /dev/null +++ b/examples/arduino-internal-library/README.rst @@ -0,0 +1,20 @@ +Arduino Example: Build code with internal library +================================================= + +1. Download ``platformio`` + `sources `_ +2. Extract ZIP archive +3. Then run these commands: + +.. code-block:: bash + + # Change directory to example + $ cd platformio-develop/examples/arduino-internal-library/ + + # Install Atmel AVR development platform with Arduino Framework + $ platformio install atmelavr + + # Process example project + $ platformio run + +.. image:: console-result.png diff --git a/examples/arduino-internal-library/console-result.png b/examples/arduino-internal-library/console-result.png new file mode 100644 index 0000000000..2a66e12187 Binary files /dev/null and b/examples/arduino-internal-library/console-result.png differ diff --git a/examples/arduino-internal-library/platformio.ini b/examples/arduino-internal-library/platformio.ini new file mode 100644 index 0000000000..3e4373c791 --- /dev/null +++ b/examples/arduino-internal-library/platformio.ini @@ -0,0 +1,7 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +[env:arduino_pro5v] +platform = atmelavr +framework = arduino +board = pro16MHzatmega168 diff --git a/examples/arduino-internal-library/src/main.cpp b/examples/arduino-internal-library/src/main.cpp new file mode 100644 index 0000000000..92b55e2b5d --- /dev/null +++ b/examples/arduino-internal-library/src/main.cpp @@ -0,0 +1,51 @@ +/** + * Copyright (C) Ivan Kravets + * See LICENSE for details. + */ + +/* + * EEPROM Read + * + * Reads the value of each byte of the EEPROM and prints it + * to the computer. + * This example code is in the public domain. + * + * https://github.com/arduino/Arduino/blob/master/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino + */ + +#include +#include + +// start reading from the first byte (address 0) of the EEPROM +int address = 0; +byte value; + +void setup() +{ + // initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } +} + +void loop() +{ + // read a byte from the current address of the EEPROM + value = EEPROM.read(address); + + Serial.print(address); + Serial.print("\t"); + Serial.print(value, DEC); + Serial.println(); + + // advance to the next address of the EEPROM + address = address + 1; + + // there are only 512 bytes of EEPROM, from 0 to 511, so if we're + // on address 512, wrap around to address 0 + if (address == 512) + address = 0; + + delay(500); +} diff --git a/platformio/__init__.py b/platformio/__init__.py index 22247f5e2a..d8f50a348a 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (0, 1, 0) +VERSION = (0, 2, 0) __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/builder/main.py b/platformio/builder/main.py index 54ab2722f9..47e1594191 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -41,7 +41,11 @@ PLATFORMFW_DIR=join("$PLATFORM_DIR", "frameworks", "$FRAMEWORK"), PLATFORMTOOLS_DIR=join("$PLATFORM_DIR", "tools"), - BUILD_DIR=join("$PROJECT_DIR", ".pioenvs", "$PIOENV") + BUILD_DIR=join("$PROJECT_DIR", ".pioenvs", "$PIOENV"), + LIBSOURCE_DIRS=[ + join("$PROJECT_DIR", "lib"), + join("$PLATFORMFW_DIR", "libraries"), + ] ) env = DefaultEnvironment() diff --git a/platformio/builder/scripts/frameworks/arduino.py b/platformio/builder/scripts/frameworks/arduino.py index fc7b6bbdcf..345b5a301e 100644 --- a/platformio/builder/scripts/frameworks/arduino.py +++ b/platformio/builder/scripts/frameworks/arduino.py @@ -23,6 +23,7 @@ "-DARDUINO=%d" % ARDUINO_VERSION, "-DARDUINO_%s" % BOARD_OPTIONS['build.board'] ] + # usb flags if "build.usb_product" in BOARD_OPTIONS: ARDUINO_FLAGS += [ @@ -32,12 +33,18 @@ '"', "") ] +# include board variant +env.VariantDir( + join("$BUILD_DIR", "variant"), + join("$PLATFORMFW_DIR", "variants", BOARD_OPTIONS['build.variant']) +) + env.Append( ASFLAGS=ARDUINO_FLAGS, CCFLAGS=ARDUINO_FLAGS, CPPPATH=[ join("$BUILD_DIR", "core"), - join("$PLATFORMFW_DIR", "variants", BOARD_OPTIONS['build.variant']) + join("$BUILD_DIR", "variant") ] ) diff --git a/platformio/builder/scripts/frameworks/energia.py b/platformio/builder/scripts/frameworks/energia.py index f69bed8838..4169b084e9 100644 --- a/platformio/builder/scripts/frameworks/energia.py +++ b/platformio/builder/scripts/frameworks/energia.py @@ -24,12 +24,18 @@ "-DENERGIA=%d" % ENERGIA_VERSION ] +# include board variant +env.VariantDir( + join("$BUILD_DIR", "variant"), + join("$PLATFORMFW_DIR", "variants", BOARD_OPTIONS['build.variant']) +) + env.Append( ASFLAGS=ENERGIA_FLAGS, CCFLAGS=ENERGIA_FLAGS, CPPPATH=[ join("$BUILD_DIR", "core"), - join("$PLATFORMFW_DIR", "variants", BOARD_OPTIONS['build.variant']) + join("$BUILD_DIR", "variant") ] ) diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index a9466ee05c..fc8aa0b666 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -1,8 +1,9 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -from os import walk -from os.path import isfile, join +import re +from os import listdir, walk +from os.path import isdir, isfile, join from time import sleep from serial import Serial @@ -17,10 +18,34 @@ def BuildLibrary(env, variant_dir, library_dir): ) +def BuildDependentLibraries(env, src_dir): + libs = [] + for deplibfile in env.GetDependentLibraries(src_dir): + for lsd_dir in env['LIBSOURCE_DIRS']: + lsd_dir = env.subst(lsd_dir) + if not isdir(lsd_dir): + continue + for libname in listdir(lsd_dir): + if not isfile(join(lsd_dir, libname, deplibfile)): + continue + _libbuild_dir = join("$BUILD_DIR", libname) + env.Append(CPPPATH=[_libbuild_dir]) + libs.append( + env.BuildLibrary(_libbuild_dir, join(lsd_dir, libname))) + return libs + + def BuildFirmware(env, libslist): src = env.Clone() - vdirs = src.VariantDirRecursive(join("$BUILD_DIR", "src"), - join("$PROJECT_DIR", "src")) + vdirs = src.VariantDirRecursive( + join("$BUILD_DIR", "src"), join("$PROJECT_DIR", "src")) + + # build source's dependent libs + for vdir in vdirs: + _libs = src.BuildDependentLibraries(vdir) + if _libs: + libslist += _libs + return src.Program( join("$BUILD_DIR", "firmware"), [src.GlobCXXFiles(vdir) for vdir in vdirs], @@ -38,6 +63,14 @@ def GlobCXXFiles(env, path): return files +def GetDependentLibraries(env, src_dir): + deplibs = [] + regexp = re.compile(r"^#include\s+<([^>]+)>", re.M) + for node in env.GlobCXXFiles(src_dir): + deplibs += regexp.findall(node.get_text_contents()) + return deplibs + + def VariantDirRecursive(env, variant_dir, src_dir, duplicate=True): # add root dir by default variants = [variant_dir] @@ -101,8 +134,10 @@ def exists(_): def generate(env): env.AddMethod(BuildLibrary) + env.AddMethod(BuildDependentLibraries) env.AddMethod(BuildFirmware) env.AddMethod(GlobCXXFiles) + env.AddMethod(GetDependentLibraries) env.AddMethod(VariantDirRecursive) env.AddMethod(ParseBoardOptions) env.AddMethod(ResetDevice) diff --git a/platformio/commands/init.py b/platformio/commands/init.py index 10e3670adf..b1dd14bd3f 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -16,7 +16,7 @@ def cli(): if isfile("platformio.ini") and isdir("src"): raise ProjectInitialized() - for d in (".pioenvs", "libs", "src"): + for d in (".pioenvs", "lib", "src"): if not isdir(d): makedirs(d) if not isfile("platformio.ini"): @@ -24,7 +24,7 @@ def cli(): "platformio.ini") secho("Project successfully initialized.\n" "Please put your source code to `src` directory, " - "external libraries to `libs` and " + "external libraries to `lib` and " "setup environments in `platformio.ini` file.\n" "Then process project with `platformio run` command.", fg="green") diff --git a/platformio/platforms/atmelavr.py b/platformio/platforms/atmelavr.py index 907761b7cf..676cb010d6 100644 --- a/platformio/platforms/atmelavr.py +++ b/platformio/platforms/atmelavr.py @@ -26,7 +26,7 @@ class AtmelavrPlatform(BasePlatform): "framework-arduinoavr": { "path": join("frameworks", "arduino"), - "default": False + "default": True } } diff --git a/platformio/platforms/timsp430.py b/platformio/platforms/timsp430.py index f815dbf3c1..34a859b506 100644 --- a/platformio/platforms/timsp430.py +++ b/platformio/platforms/timsp430.py @@ -26,7 +26,7 @@ class Timsp430Platform(BasePlatform): "framework-energiamsp430": { "path": join("frameworks", "energia"), - "default": False + "default": True } } diff --git a/requirements.txt b/requirements.txt index b15fbf503d..3c510e9637 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -click==2.0 +click==2.1 colorama==0.3.1 pyserial==2.7 -requests=2.3.0 -scons=2.3.0 +requests==2.3.0 +scons==2.3.0 diff --git a/setup.py b/setup.py index ce4a9cef35..dae1ed807e 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ ] }, classifiers=[ - "Development Status :: 3 - Alpha", + "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License",