# build.py
# pre-build script, setting up build environment and fetch hal file for user's board

import sys
import os
import os.path
import requests
from os.path import basename
from platformio import util
from SCons.Script import DefaultEnvironment

try:
    import configparser
except ImportError:
    import ConfigParser as configparser

# get platformio environment variables
env = DefaultEnvironment()

config = configparser.ConfigParser()
config.read("platformio.ini")

# get platformio source path
srcdir = env.get("PROJECT_SRC_DIR")
project_dir = env.subst("$PROJECT_DIR")


board = env.BoardConfig()


env.Append(
    LIBPATH=[
        os.path.join(variants_dir, board.get("build.variant"))
    ]
)

libs = []

if "build.variant" in env.BoardConfig():
    env.Append(
        CPPPATH=[os.path.join(variants_dir, board.get("build.variant"))]
    )
    libs.append(env.BuildLibrary(
        os.path.join("$BUILD_DIR", "FrameworkArduinoVariant"),
        os.path.join(variants_dir, board.get("build.variant"))
    ))

env.Prepend(LIBS=libs)




# get bintray upload parameters from platformio environment
version = config.get("common", "release_version")





