import("$tizen_core/build/manifest.gni")
import("$tizen_core/build/config.gni")
import("$tizen_core/build/sign.gni")
import("$tizen_core/build/pack.gni")
import("$tizen_core/build/device.gni")

# Tizen workspace
template("tizen_workspace") {
    forward_variables_from(invoker, "*", [])

    projects_all = []
    foreach(proj, projects) {
        projects_all += [ "//${proj}:all"]
    }

    group("build") {
        deps = projects_all
    }

    project_hashes = []
    foreach(proj, projects) {
        project_hashes += [ "//${proj}:hash"]
    }

    if (defined(manifests) && manifests != []) {
        # merge manifest files
        merge_manifests("manifest"){}
        project_hashes += [":manifest.hash"]
    }
    
    if (defined(configFiles) && configFiles != []) {
        # TODO: handle merge config files. Currently we only copy files
        merge_configs("config"){}
        project_hashes += [":config.hash"]
    }

    group("hash") {
        deps = project_hashes
    }

    # sign package files
    sign_package("sign"){
        sign_deps = project_hashes
    }

    # create tpk package
    package("pack"){
        pack_deps = [":sign"]
    }

    install_package("install") {
        install_deps = [":pack"]
    }

    foreach(exe_name, executables) {
        run_package("run.$exe_name") {
            run_deps = [":install"]
        }
    }

    uninstall_package("uninstall"){}
}