1#!/bin/bash 2# Copyright (c) 2021-2022 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 17<<COMMENT 18 19# -p NUM --strip=NUM Strip NUM leading components from file names. 20# -i PATCHFILE --input=PATCHFILE Read patch from PATCHFILE instead of stdin. 21# -d DIR --directory=DIR Change the working directory to DIR first. 22 23bash -x ./apply_patch.sh \ 24 ../../../../third_party/libinput/ \ 25 ../../../../out/ohos-arm-release/libinput_mmi \ 26 ./diff_libinput_mmi 27 28COMMENT 29 30curdir=$(pwd) 31source_dir=$1 32out_dir=$2 33path_file_dir=$3 34 35echo "curdir: $curdir" 36echo "source_dir: $source_dir" 37echo "out_dir: $out_dir" 38echo "path_file_dir: $path_file_dir" 39 40if [ "$source_dir" == "" ] || [ "$out_dir" == "" ] || [ "$path_file_dir" == "" ]; then 41 echo "param is invalid." 42 exit 1 43fi 44 45echo "check out_dir: $out_dir" 46if [ -d "$out_dir" ]; then 47 echo "remove $out_dir begin" 48 rm -rf "$out_dir" 49fi 50 51echo "mkdir out_dir: $out_dir" 52mkdir -p $out_dir 53 54echo "cp $source_dir/* to $out_dir/" 55cp -fra $source_dir/* $out_dir 56 57ls -l $path_file_dir/*.diff 58if [ $? -ne 0 ]; then 59 echo "WARNING: no patch." 60 exit 0 61fi 62 63PATCH_FILE=$(realpath $(ls -l $path_file_dir/*.diff | tail -n 1 | awk '{print $9}')) 64 65echo "PATCH_FILE: $PATCH_FILE" 66 67cd $out_dir 68echo "pwd: $(pwd)" 69patch -p1 -i $PATCH_FILE 70if [ $? -ne 0 ]; then 71 echo "patch fail. path_file_dir=$path_file_dir" 72 exit 1 73fi 74 75cd $curdir 76exit 0 77