Skip to content

Commit

Permalink
Resolved issue #1"Build referred libraries"
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed Jun 15, 2014
1 parent 2fea037 commit 52ca242
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
9 changes: 8 additions & 1 deletion platformio/builder/scripts/frameworks/arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 += [
Expand All @@ -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")
]
)

Expand Down
8 changes: 7 additions & 1 deletion platformio/builder/scripts/frameworks/energia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
]
)

Expand Down
43 changes: 39 additions & 4 deletions platformio/builder/tools/platformio.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright (C) Ivan Kravets <[email protected]>
# 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
Expand All @@ -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],
Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 52ca242

Please sign in to comment.