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 --update=none $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 --update=none $external_dir/MODULE_LICENSE_* . 45CopyIfPresent "METADATA" 46CopyIfPresent "TEST_MAPPING" 47CopyIfPresent ".git" 48CopyIfPresent ".gitignore" 49if compgen -G "$external_dir/cargo2android*"; then 50 cp -a -f --update=none $external_dir/cargo2android* . 51fi 52if compgen -G "$external_dir/cargo_embargo*"; then 53 cp -a -f --update=none $external_dir/cargo_embargo* . 54fi 55CopyIfPresent "patches" 56CopyIfPresent "post_update.sh" 57CopyIfPresent "OWNERS" 58CopyIfPresent "README.android" 59CopyIfPresent "rules.mk" 60if compgen -G "$external_dir/cargo2rulesmk*"; then 61 cp -a -f --update=none $external_dir/cargo2rulesmk* . 62fi 63 64file_counter=0 65total_files=$(ls $tmp_dir/patches | grep -Ei '(diff|patch)$' | wc -l) 66for p in $tmp_dir/patches/*.{diff,patch} 67do 68 file_counter=$((file_counter+1)) 69 [ -e "$p" ] || continue 70 # Do not patch the Android.bp file, as we assume it will 71 # patch itself. 72 if [ -f $tmp_dir/Cargo.toml ] 73 then 74 [ "$(basename $p)" != "Android.bp.diff" ] || continue 75 [ "$(basename $p)" != "Android.bp.patch" ] || continue 76 [ "$(basename $p)" != "rules.mk.diff" ] || continue 77 [ "$(basename $p)" != "rules.mk.patch" ] || continue 78 fi 79 echo "Applying patch [$file_counter/$total_files] $p..." 80 patch -p1 -d $tmp_dir --no-backup-if-mismatch < $p; 81done 82 83if [ -f $tmp_dir/Cargo.toml -a -f $tmp_dir/Android.bp ] 84then 85 # regenerate Android.bp after local patches, as they may 86 # have deleted files that it uses. 87 /bin/bash `dirname $0`/regen_bp.sh $root_dir $external_dir 88fi 89 90if [ -f $tmp_dir/post_update.sh ] 91then 92 echo "Running post update script" 93 $tmp_dir/post_update.sh $tmp_dir $external_dir 94fi 95 96echo "Swapping old and new..." 97second_tmp_dir=`mktemp -d` 98mv $external_dir $second_tmp_dir 99mv $tmp_dir $external_dir 100mv $second_tmp_dir/* $tmp_dir 101rm -rf $second_tmp_dir 102if [ -n "$tmp_file" ]; then 103 # Write to the temporary file to show we have swapped. 104 echo "Swapping" > $tmp_file 105fi 106 107cd $external_dir 108git add . 109 110exit 0 111