check_arch.sh 950 B

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