From afb8e72dcd01b2b52009c05a298870c8be7a9192 Mon Sep 17 00:00:00 2001
From: WuChang <3142324836@qq.com>
Date: Wed, 31 Jul 2024 13:37:24 +0800
Subject: [PATCH] Fixed CI executable find scripts for multi platforms

---
 CIUtils/find-elf.sh        | 28 ++++++++++++++++++++++++++
 CIUtils/find-executable.sh | 40 ++++++++++++++------------------------
 CIUtils/find-macho.sh      | 28 ++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 25 deletions(-)
 create mode 100644 CIUtils/find-elf.sh
 create mode 100644 CIUtils/find-macho.sh

diff --git a/CIUtils/find-elf.sh b/CIUtils/find-elf.sh
new file mode 100644
index 0000000..87394f1
--- /dev/null
+++ b/CIUtils/find-elf.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# Check if a directory is provided as an argument
+if [ -z "$1" ]; then
+  echo "Usage: $0 <directory>"
+  exit 1
+fi
+
+# Directory to search
+directory=$1
+
+# Find ELF files in the specified directory
+files=$(find "$directory" -type f -exec sh -c 'file -b "$1" | grep -q "ELF" && echo "$1"' _ {} \;)
+
+# Initialize an empty string for the output
+output=""
+
+# Loop through each file and format it
+for file in $files; do
+  if [ -z "$output" ]; then
+    output="\"$file\""
+  else
+    output="$output,\"$file\""
+  fi
+done
+
+# Print the formatted output
+echo $output
diff --git a/CIUtils/find-executable.sh b/CIUtils/find-executable.sh
index d838e9d..e6ddb4c 100644
--- a/CIUtils/find-executable.sh
+++ b/CIUtils/find-executable.sh
@@ -1,28 +1,18 @@
 #!/bin/bash
 
-# Check if a directory is provided as an argument
-if [ -z "$1" ]; then
-  echo "Usage: $0 <directory>"
-  exit 1
-fi
+# Detect the operating system
+os_type=$(uname)
 
-# Directory to search
-directory=$1
-
-# Find ELF, Mach-O and Universal Binary files in the specified directory
-files=$(find "$directory" -type f -exec sh -c 'file -b "$1" | grep -q "ELF|Mach-O|universal binary" && echo "$1"' _ {} \;)
-
-# Initialize an empty string for the output
-output=""
-
-# Loop through each file and format it
-for file in $files; do
-  if [ -z "$output" ]; then
-    output="\"$file\""
-  else
-    output="$output,\"$file\""
-  fi
-done
-
-# Print the formatted output
-echo $output
+# Execute the corresponding script based on the operating system
+case "$os_type" in
+  Linux)
+    echo $(./find-elf.sh "$1")
+    ;;
+  Darwin)
+    echo $(./find-macho.sh "$1")
+    ;;
+  *)
+    echo "Unsupported OS: $os_type"
+    exit 1
+    ;;
+esac
diff --git a/CIUtils/find-macho.sh b/CIUtils/find-macho.sh
new file mode 100644
index 0000000..84529c5
--- /dev/null
+++ b/CIUtils/find-macho.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# Check if a directory is provided as an argument
+if [ -z "$1" ]; then
+  echo "Usage: $0 <directory>"
+  exit 1
+fi
+
+# Directory to search
+directory=$1
+
+# Find Mach-O and Universal Binary files in the specified directory
+files=$(find "$directory" -type f -exec sh -c 'file -b "$1" | grep -q "Mach-O|universal binary" && echo "$1"' _ {} \;)
+
+# Initialize an empty string for the output
+output=""
+
+# Loop through each file and format it
+for file in $files; do
+  if [ -z "$output" ]; then
+    output="\"$file\""
+  else
+    output="$output,\"$file\""
+  fi
+done
+
+# Print the formatted output
+echo $output