Skip to content

Commit 8a26adf

Browse files
committed
scripts: Add support to checkout specific commits for alsa repos
Replace the hardcoded COMMIT_ID array with runtime command line parameters. Each repo can now be checked out to a specific commit or tag by passing --<repo-name>-commit=<ref> on the command line, e.g.: --alsa-lib-commit=v1.2.3 --alsa-utils-commit=abc1234 If no commit is provided for a specific repo then the code will be updated with latest code on remote. This is a slight modification from the original code where a list of hardcoded commits was used. But that behavior was already broken, e.g the hardcoded commit for alsa-utils cannot be found in git tree anyway. Also, remove check_commit() as it's no longer needed. Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
1 parent 3f7738d commit 8a26adf

1 file changed

Lines changed: 19 additions & 28 deletions

File tree

scripts/build-alsa-tools.sh

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ declare -a REPOS=(
1212
# Add more repositories here...
1313
)
1414

15-
# Commit ID to check for (optional). If specified, the script will update
16-
# the repository if this commit ID is not found. Leave empty to skip.
17-
# This array order must align with REPO array above.
18-
declare -a COMMIT_ID=(
19-
"df8f1cc1ec9d9ee15be5e2c23ad25b9389fd8766"
20-
"09550cd393b1a7d307ee6f26637b1ed7bd275e38"
21-
# Add more IDs here...
22-
)
15+
# Per-repo commit/tag overrides via --<repo-name>-commit=<ref>.
16+
# Example: --alsa-lib-commit=v1.2.3 --alsa-utils-commit=abc1234
17+
# If not provided for a repo the original update logic (fetch + pull) applies.
18+
declare -A REPO_COMMIT
19+
for arg in "$@"; do
20+
case "$arg" in
21+
--*-commit=*)
22+
key="${arg#--}"
23+
REPO_COMMIT["${key%-commit=*}"]="${key#*-commit=}" ;;
24+
esac
25+
done
2326

2427
# Directory where repositories will be cloned/updated.
2528
if [[ -z "$SOF_WORKSPACE" ]]; then
@@ -50,23 +53,6 @@ declare -a TARGET_ARGS=(
5053
"--enable-alsatopology"
5154
)
5255

53-
# Function to check if a commit ID exists in a repository
54-
check_commit() {
55-
local repo_dir="$1"
56-
local commit_id="$2"
57-
58-
if [ -z "$commit_id" ]; then
59-
return 0 # Skip check if no commit ID is provided
60-
fi
61-
62-
if ! git -C "$repo_dir" rev-parse --quiet --verify "$commit_id" >/dev/null 2>&1; then
63-
return 1 # Commit ID not found
64-
else
65-
return 0 # Commit ID found
66-
fi
67-
}
68-
69-
7056
# Function to update the repository
7157
update_repo() {
7258
local repo_dir="$1"
@@ -114,10 +100,15 @@ for ((i = 0; i < ${#REPOS[@]}; i++)); do
114100
if [ ! -d "$repo_dir" ]; then
115101
echo "Cloning repository: $repo_url"
116102
git clone "$repo_url" "$repo_dir" || { echo "git clone failed for $repo_url"; exit 1; }
117-
elif ! check_commit "$repo_dir" "${COMMIT_ID[i]}"; then
118-
update_repo "$repo_dir"
103+
fi
104+
105+
ref="${REPO_COMMIT[$repo_name]}"
106+
if [[ -n "$ref" ]]; then
107+
git -C "$repo_dir" fetch --all
108+
git -C "$repo_dir" checkout "$ref" ||
109+
{ echo "git checkout $ref failed in $repo_dir"; exit 1; }
119110
else
120-
echo "Repository $repo_name is up to date."
111+
update_repo "$repo_dir"
121112
fi
122113

123114
build_and_install "$repo_dir" "${CONFIGURE_ARGS[i]}"

0 commit comments

Comments
 (0)