#
# Copyright (C) 2019-Present A-Team Digital Solutions
#

from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
SCRIPTS = ROOT / "scripts"

def _make_command(project, script):
    """
    Generate a shell command that exports every Project environment
    variable before executing the requested script.
    """
    exports = []
    for key, value in project.as_environment().items():
        exports.append(f"export {key}='{value}'")
    exports.append(f"bash '{script}'")
    return "; ".join(exports)
#
# BUILD
#
def build_command(project,
                  android_version,
                  build_jobs,
                  use_ccache):
    # Update runtime settings
    project.android_version = android_version
    project.build_jobs = build_jobs
    project.use_ccache = use_ccache
    return _make_command(
        project,
        SCRIPTS / "build.sh"
    )
#
# SYNC
#
def sync_command(project):
    return _make_command(
        project,
        SCRIPTS / "sync.sh"
    )
#
# CLEAN
#
def clean_command(project):
    return _make_command(
        project,
        SCRIPTS / "clean.sh"
    )
