Smart Home/MATTER

run_zaptool.sh 분석해보려고 했지만 쓸데 없는 것 같아 접음

감자최고 2022. 12. 6. 22:45

function _get_fullpath() {
    cd "$(dirname "$1")" && echo "$PWD/$(basename "$1")"
}

set -e

[[ "$1" == "--help" ]] && {
    echo "Usage: $0 [ZAP-file-path]" >&2
    exit 0
}

SCRIPT_PATH="$(_get_fullpath "$0")"
CHIP_ROOT="${SCRIPT_PATH%/scripts/tools/zap/run_zaptool.sh}"
[[ -n "$1" ]] && ZAP_ARGS=(-i "$(_get_fullpath "$1")") || ZAP_ARGS=()

(

    cd "$CHIP_ROOT" &&
        git submodule update --init third_party/zap/repo

    cd "third_party/zap/repo"
    if ! npm list installed-check &>/dev/null; then
        npm install installed-check
    fi

    if ! ./node_modules/.bin/installed-check -c &>/dev/null; then
        npm install
    fi

    echo "ARGS: ${ZAP_ARGS[@]}"

    if [[ "${ZAP_ARGS[@]}" == *"/all-clusters-app.zap"* ]]; then
        ZCL_FILE="$CHIP_ROOT/src/app/zap-templates/zcl/zcl-with-test-extensions.json"
    else
        ZCL_FILE="$CHIP_ROOT/src/app/zap-templates/zcl/zcl.json"
    fi

    node src-script/zap-start.js --logToStdout \
        --gen "$CHIP_ROOT/src/app/zap-templates/app-templates.json" \
        --zcl "$ZCL_FILE" \
        "${ZAP_ARGS[@]}"
)