xref: /DragonOS/tools/check_arch.sh (revision e8b1db320d9014e92c1f5272c7a7e6dafac08b90)
1*e8b1db32SLoGin#!/bin/bash
2*e8b1db32SLoGin
3*e8b1db32SLoGinBASE_PATH=$(pwd)
4*e8b1db32SLoGin# 定义错误信息
5*e8b1db32SLoGinARCH_MISMATCH_ERROR="Error: ARCH in env.mk does not match arch in dadk-manifest.toml"
6*e8b1db32SLoGin
7*e8b1db32SLoGinif [ -z "$ARCH" ]; then
8*e8b1db32SLoGin    echo "Error: ARCH environment variable is not set." >&2
9*e8b1db32SLoGin    exit 1
10*e8b1db32SLoGinfi
11*e8b1db32SLoGin
12*e8b1db32SLoGin
13*e8b1db32SLoGin# Check if ROOT_PATH is set
14*e8b1db32SLoGinif [ -n "$ROOT_PATH" ]; then
15*e8b1db32SLoGin    CHECK_PATH="$ROOT_PATH"
16*e8b1db32SLoGinelse
17*e8b1db32SLoGin    # Check if the current directory name is "tools"
18*e8b1db32SLoGin    if [ "$(basename "$BASE_PATH")" = "tools" ]; then
19*e8b1db32SLoGin        # Try the parent directory's dadk-manifest
20*e8b1db32SLoGin        CHECK_PATH=$(dirname "$BASE_PATH")/
21*e8b1db32SLoGin    else
22*e8b1db32SLoGin        # Otherwise, check the current directory
23*e8b1db32SLoGin        CHECK_PATH="$BASE_PATH"
24*e8b1db32SLoGin    fi
25*e8b1db32SLoGinfi
26*e8b1db32SLoGin
27*e8b1db32SLoGinecho "Checking $CHECK_PATH"
28*e8b1db32SLoGin
29*e8b1db32SLoGin
30*e8b1db32SLoGin# 读取dadk-manifest.toml文件中的arch字段
31*e8b1db32SLoGinDADK_ARCH=$(grep -oP '(?<=arch = ")[^"]+' $CHECK_PATH/dadk-manifest.toml)
32*e8b1db32SLoGin
33*e8b1db32SLoGin# 检查arch字段是否为x86_64
34*e8b1db32SLoGinif [ "$ARCH" != $DADK_ARCH ]; then
35*e8b1db32SLoGin    echo "$ARCH_MISMATCH_ERROR" >&2
36*e8b1db32SLoGin    exit 1
37*e8b1db32SLoGinelse
38*e8b1db32SLoGin    echo "Arch check passed."
39*e8b1db32SLoGin    exit 0
40*e8b1db32SLoGinfi
41