Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions cov_docker_script/common_build_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,35 @@ apply_patch() {
return 0
fi

if [[ "$type" == "patch_file" ]]; then
# For patch_file type, 'search' parameter contains the patch file path
local patch_file="$search"
local repo_dir="$file"

# Expand environment variables in patch file path
patch_file=$(eval echo "$patch_file")

Comment on lines +142 to +149
if [[ ! -f "$patch_file" ]]; then
err "Patch file not found: $patch_file"
return 1
fi

log "Applying patch file: $patch_file to $repo_dir"

pushd "$repo_dir" >/dev/null || return 1

# Apply the patch using patch -p1
if ! patch -p1 < "$patch_file"; then
err "Failed to apply patch file: $patch_file"
popd >/dev/null
Comment on lines +159 to +162
return 1
fi

popd >/dev/null
ok "Patch file applied successfully"
return 0
fi

if [[ ! -f "$file" ]]; then
err "Patch target not found: $file"
return 1
Expand Down
69 changes: 69 additions & 0 deletions cov_docker_script/setup_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,69 @@ fi

check_dependencies || exit 1

# Apply source patches for a dependency
apply_dependency_patches() {
local index=$1
local repo_dir=$2
local name=$3

local patch_count
patch_count=$(jq -r ".dependencies.repos[$index].source_patches // [] | length" "$CONFIG_FILE")

if [[ "$patch_count" -eq 0 ]]; then
return 0
fi

step "Applying source patches for $name ($patch_count patches)"

local i=0
while [[ $i -lt $patch_count ]]; do
local file search replace type content patch_file
file=$(jq -r ".dependencies.repos[$index].source_patches[$i].file" "$CONFIG_FILE")
type=$(jq -r ".dependencies.repos[$index].source_patches[$i].type // \"replace\"" "$CONFIG_FILE")

if [[ "$type" == "patch_file" ]]; then
# For patch_file type, get the patch file path
patch_file=$(jq -r ".dependencies.repos[$index].source_patches[$i].patch_file" "$CONFIG_FILE")

# Expand $HOME and $BUILD_DIR in patch file path
local expanded_patch_file=$(expand_path "$patch_file")

# For patch_file, 'file' should point to the repo directory, and patch file goes in 'search' param
if ! apply_patch "$repo_dir" "$expanded_patch_file" "" "$type" ""; then
err "Failed to apply patch $((i+1))/$patch_count for $name"
return 1
fi
else
# For replace/create types
search=$(jq -r ".dependencies.repos[$index].source_patches[$i].search // \"\"" "$CONFIG_FILE")
replace=$(jq -r ".dependencies.repos[$index].source_patches[$i].replace // \"\"" "$CONFIG_FILE")
content=$(jq -r ".dependencies.repos[$index].source_patches[$i].content // \"\"" "$CONFIG_FILE")

# Expand $HOME in file path, then resolve relative paths from repo_dir
local expanded_file=$(expand_path "$file")
local target_file
if [[ "$expanded_file" = /* ]]; then
# Absolute path - use as is
target_file="$expanded_file"
else
# Relative path - prepend repo_dir
target_file="$repo_dir/$expanded_file"
fi

if ! apply_patch "$target_file" "$search" "$replace" "$type" "$content"; then
err "Failed to apply patch $((i+1))/$patch_count for $name"
return 1
fi
fi

i=$((i + 1))
done

ok "Applied $patch_count patches for $name"
return 0
}

# Initialize environment
initialize_environment() {
print_banner "Dependency Setup"
Expand Down Expand Up @@ -212,6 +275,12 @@ process_dependency() {
return 1
fi

# Apply source patches
if ! apply_dependency_patches "$index" "$repo_dir" "$name"; then
err "Failed to apply patches for $name"
return 1
fi

# Copy headers
if ! process_headers "$index" "$repo_dir" "$name"; then
err "Failed to copy headers for $name"
Expand Down
Loading