• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (C) 2025 Huawei Device Co., Ltd.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15set -e
16
17cur_dir=$(pwd)
18src_dir=$1
19dst_dir=$2
20patch_dir=$3
21
22echo "cur_dir: $cur_dir"
23echo "src_dir: $src_dir"
24echo "dst_dir: $dst_dir"
25echo "patch_dir: $patch_dir"
26
27if [ "$src_dir" == "" ] || [ "$dst_dir" == "" ] || [ "$patch_dir" == "" ]; then
28    echo "invalid params for apply_patch."
29exit 1
30fi
31
32echo "check and clear patched_sqlite_dir: $dst_dir"
33if [ -d "$dst_dir" ]; then
34    echo "remove $dst_dir begin"
35    rm -rf "$dst_dir"
36fi
37
38echo "create patched_sqlite_dir: $dst_dir"
39mkdir -p $dst_dir
40
41echo "copy $src_dir/* to $dst_dir/"
42cp -fa $src_dir/* $dst_dir
43
44ls -l $patch_dir/*.patch
45if [ $? -ne 0 ]; then
46    echo "WARNING: no patch."
47    exit 0
48fi
49
50PATCH_FILES=$(realpath $(ls $patch_dir/*.patch))
51echo "found the following patchs:"
52echo "$PATCH_FILES"
53
54cd $dst_dir
55echo "pwd: $(pwd)"
56
57for patch_file in $PATCH_FILES; do
58    echo "applying patch: $patch_file"
59    patch -p1 -i "$patch_file"
60    if [ $? -ne 0 ]; then
61        echo "failed to apply patch: $patch_file"
62        exit 1
63    fi
64done
65
66cd $cur_dir
67exit 0
68