# Path: mod/log.py
# RED = '\033[1;31m'
# GREEN = '\033[1;32m'
# YELLOW = '\033[1;33m'
# BLUE = '\033[1;36m'
# DEF = '\033[0;0m'
# def error(msg, fatal=True) :
# def warn(msg) :
# def ok(item, status) :
# def failed(item, status) :
# def optional(item, status) :
# def info(msg) :
# def colored(color, msg) :
# 
# Path: mod/util.py
# def fix_path(path) :
# def get_workspace_dir(fips_dir) :
# def get_project_dir(fips_dir, proj_name) :
# def get_build_root_dir(fips_dir, proj_name):
# def get_deploy_root_dir(fips_dir, proj_name):
# def get_build_dir(fips_dir, proj_name, cfg) :
# def get_deploy_dir(fips_dir, proj_name, cfg) :
# def get_fips_dir(proj_dir, name):
# def get_configs_dir(proj_dir):
# def get_verbs_dir(proj_dir):
# def get_generators_dir(proj_dir):
# def get_toolchains_dir(proj_dir):
# def get_giturl_from_url(url) :
# def get_gitbranch_from_url(url) :
# def get_project_name_from_url(url) :
# def get_project_name_from_dir(proj_dir) :
# def load_fips_yml(proj_dir) :
# def lookup_target_cwd(proj_dir, target) :
# def is_valid_project_dir(proj_dir) :
# def ensure_valid_project_dir(proj_dir) :
# def is_git_url(url) :
# def confirm(question) :
# def url_download_hook(count, block_size, total_size) :
# def get_host_platform() :
# def get_cfg_target_list(fips_dir, proj_dir, cfg):
# def get_cfg_headersdirs_by_target(fips_dir, proj_dir, cfg):
# def get_cfg_defines_by_target(fips_dir, proj_dir, cfg):
# def get_num_cpucores():
# 
# Path: mod/tools/git.py
# def check_exists(fips_dir=None) :
# def check_exists_with_error():
# def clone(url, branch, depth, name, cwd) :
# def add(proj_dir, update=False):
# def commit(proj_dir, msg):
# def commit_allow_empty(proj_dir, msg):
# def push(proj_dir):
# def has_local_changes(proj_dir):
# def update_submodule(proj_dir):
# def update(proj_dir):
# def update_force_and_ignore_local_changes(proj_dir):
# def get_branches(proj_dir) :
# def checkout(proj_dir, revision) :
# def has_uncommitted_files(proj_dir) :
# def get_remote_rev(proj_dir, remote_branch) :
# def get_local_rev(proj_dir, local_branch) :
# def check_out_of_sync(proj_dir) :
# def check_branch_out_of_sync(proj_dir, branch) :


import os, stat, subprocess, shutil
from mod import log, util
from mod.tools import git
#-------------------------------------------------------------------------------
def get_emsdk_path(fips_dir):
    emsdk_script = 'emsdk.bat' if util.get_host_platform() == 'win' else 'emsdk'
    emsdk_path = get_emsdk_dir(fips_dir) + '/' + emsdk_script
    return emsdk_path

#-------------------------------------------------------------------------------
def check_exists(fips_dir):
    emsdk_path = get_emsdk_path(fips_dir)
    return os.path.isfile(emsdk_path)

#-------------------------------------------------------------------------------
def get_em_config(fips_dir):
    # returns the path to the local .emscripten file
    return get_emsdk_dir(fips_dir) + '/.emscripten'

#-------------------------------------------------------------------------------
def run(fips_dir, cmdline):
    if not check_exists(fips_dir):
        log.error("emsdk script not found at '{}', please run './fips emsdk install'".format(get_emsdk_path(fips_dir)))
    emsdk_path = get_emsdk_path(fips_dir)
    emsdk_dir = get_emsdk_dir(fips_dir)
    cmd = '{} {}'.format(emsdk_path, cmdline)
    subprocess.call(cmd, cwd=emsdk_dir, shell=True)

#-------------------------------------------------------------------------------
def clone_or_update_emsdk(fips_dir):
    # returns True on success
    emsdk_dir = get_emsdk_dir(fips_dir)
    if emsdk_dir_exists(fips_dir):

# Path: mod/log.py
# RED = '\033[1;31m'
# GREEN = '\033[1;32m'
# YELLOW = '\033[1;33m'
# BLUE = '\033[1;36m'
# DEF = '\033[0;0m'
# def error(msg, fatal=True) :
# def warn(msg) :
# def ok(item, status) :
# def failed(item, status) :
# def optional(item, status) :
# def info(msg) :
# def colored(color, msg) :
# 
# Path: mod/util.py
# def fix_path(path) :
# def get_workspace_dir(fips_dir) :
# def get_project_dir(fips_dir, proj_name) :
# def get_build_root_dir(fips_dir, proj_name):
# def get_deploy_root_dir(fips_dir, proj_name):
# def get_build_dir(fips_dir, proj_name, cfg) :
# def get_deploy_dir(fips_dir, proj_name, cfg) :
# def get_fips_dir(proj_dir, name):
# def get_configs_dir(proj_dir):
# def get_verbs_dir(proj_dir):
# def get_generators_dir(proj_dir):
# def get_toolchains_dir(proj_dir):
# def get_giturl_from_url(url) :
# def get_gitbranch_from_url(url) :
# def get_project_name_from_url(url) :
# def get_project_name_from_dir(proj_dir) :
# def load_fips_yml(proj_dir) :
# def lookup_target_cwd(proj_dir, target) :
# def is_valid_project_dir(proj_dir) :
# def ensure_valid_project_dir(proj_dir) :
# def is_git_url(url) :
# def confirm(question) :
# def url_download_hook(count, block_size, total_size) :
# def get_host_platform() :
# def get_cfg_target_list(fips_dir, proj_dir, cfg):
# def get_cfg_headersdirs_by_target(fips_dir, proj_dir, cfg):
# def get_cfg_defines_by_target(fips_dir, proj_dir, cfg):
# def get_num_cpucores():
# 
# Path: mod/tools/git.py
# def check_exists(fips_dir=None) :
# def check_exists_with_error():
# def clone(url, branch, depth, name, cwd) :
# def add(proj_dir, update=False):
# def commit(proj_dir, msg):
# def commit_allow_empty(proj_dir, msg):
# def push(proj_dir):
# def has_local_changes(proj_dir):
# def update_submodule(proj_dir):
# def update(proj_dir):
# def update_force_and_ignore_local_changes(proj_dir):
# def get_branches(proj_dir) :
# def checkout(proj_dir, revision) :
# def has_uncommitted_files(proj_dir) :
# def get_remote_rev(proj_dir, remote_branch) :
# def get_local_rev(proj_dir, local_branch) :
# def check_out_of_sync(proj_dir) :
# def check_branch_out_of_sync(proj_dir, branch) :


# Path: mod/emsdk.py
import os, stat, subprocess, shutil
from mod import log, util
from mod.tools import git

#-------------------------------------------------------------------------------
def get_emsdk_path(fips_dir):
    emsdk_script = 'emsdk.bat' if util.get_host_platform() == 'win' else 'emsdk'
    emsdk_path = get_emsdk_dir(fips_dir) + '/' + emsdk_script
    return emsdk_path

#-------------------------------------------------------------------------------
def check_exists(fips_dir):
    emsdk_path = get_emsdk_path(fips_dir)
    return os.path.isfile(emsdk_path)

#-------------------------------------------------------------------------------
def get_em_config(fips_dir):
    # returns the path to the local .emscripten file
    return get_emsdk_dir(fips_dir) + '/.emscripten'

#-------------------------------------------------------------------------------
def run(fips_dir, cmdline):
    if not check_exists(fips_dir):
        log.error("emsdk script not found at '{}', please run './fips emsdk install'".format(get_emsdk_path(fips_dir)))
    emsdk_path = get_emsdk_path(fips_dir)
    emsdk_dir = get_emsdk_dir(fips_dir)
    cmd = '{} {}'.format(emsdk_path, cmdline)
    subprocess.call(cmd, cwd=emsdk_dir, shell=True)

#-------------------------------------------------------------------------------
def clone_or_update_emsdk(fips_dir):
    # returns True on success
    emsdk_dir = get_emsdk_dir(fips_dir)
    if emsdk_dir_exists(fips_dir):

        log.colored(log.YELLOW, "=== updating emscripten SDK at '{}'".format(emsdk_dir))