1#!/bin/bash 2# 3# Copyright (C) 2007 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# This script is used by external_updater to replace a package. Don't 18# invoke directly. 19 20set -e 21 22tmp_dir=$1 23external_dir=$2 24tmp_file=$3 25 26# root of Android source tree 27root_dir=`pwd` 28 29echo "Entering $tmp_dir..." 30cd $tmp_dir 31 32function CopyIfPresent() { 33 if [ -e $external_dir/$1 ]; then 34 cp -a -n $external_dir/$1 . 35 fi 36} 37 38echo "Copying preserved files..." 39CopyIfPresent "Android.bp" 40CopyIfPresent "Android.mk" 41CopyIfPresent "CleanSpec.mk" 42CopyIfPresent "LICENSE" 43CopyIfPresent "NOTICE" 44cp -a -f -n $external_dir/MODULE_LICENSE_* . 45CopyIfPresent "METADATA" 46CopyIfPresent "TEST_MAPPING" 47CopyIfPresent ".git" 48CopyIfPresent ".gitignore" 49if compgen -G "$external_dir/cargo2android*"; then 50 cp -a -f -n $external_dir/cargo2android* . 51fi 52CopyIfPresent "patches" 53CopyIfPresent "post_update.sh" 54CopyIfPresent "OWNERS" 55CopyIfPresent "README.android" 56 57file_counter=0 58total_files=$(ls $tmp_dir/patches | grep -Ei '(diff|patch)$' | wc -l) 59for p in $tmp_dir/patches/*.{diff,patch} 60do 61 file_counter=$((file_counter+1)) 62 [ -e "$p" ] || continue 63 # Do not patch the Android.bp file, as we assume it will 64 # patch itself. 65 if [ -f $tmp_dir/Cargo.toml ] 66 then 67 [ "$(basename $p)" != "Android.bp.diff" ] || continue 68 [ "$(basename $p)" != "Android.bp.patch" ] || continue 69 fi 70 echo "Applying patch [$file_counter/$total_files] $p..." 71 patch -p1 -d $tmp_dir --no-backup-if-mismatch < $p; 72done 73 74if [ -f $tmp_dir/Cargo.toml -a -f $tmp_dir/Android.bp ] 75then 76 # regenerate Android.bp after local patches, as they may 77 # have deleted files that it uses. 78 /bin/bash `dirname $0`/regen_bp.sh $root_dir $external_dir 79fi 80 81if [ -f $tmp_dir/post_update.sh ] 82then 83 echo "Running post update script" 84 $tmp_dir/post_update.sh $tmp_dir $external_dir 85fi 86 87echo "Swapping old and new..." 88second_tmp_dir=`mktemp -d` 89mv $external_dir $second_tmp_dir 90mv $tmp_dir $external_dir 91mv $second_tmp_dir/* $tmp_dir 92rm -rf $second_tmp_dir 93if [ -n "$tmp_file" ]; then 94 # Write to the temporary file to show we have swapped. 95 echo "Swapping" > $tmp_file 96fi 97 98cd $external_dir 99git add . 100 101exit 0 102