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 24 25# root of Android source tree 26root_dir=`pwd` 27 28echo "Entering $tmp_dir..." 29cd $tmp_dir 30 31function CopyIfPresent() { 32 if [ -e $external_dir/$1 ]; then 33 cp -a -n $external_dir/$1 . 34 fi 35} 36 37echo "Copying preserved files..." 38CopyIfPresent "Android.bp" 39CopyIfPresent "Android.mk" 40CopyIfPresent "CleanSpec.mk" 41CopyIfPresent "LICENSE" 42CopyIfPresent "NOTICE" 43cp -a -f -n $external_dir/MODULE_LICENSE_* . 44CopyIfPresent "METADATA" 45CopyIfPresent "TEST_MAPPING" 46CopyIfPresent ".git" 47CopyIfPresent ".gitignore" 48CopyIfPresent "cargo2android.json" 49CopyIfPresent "patches" 50CopyIfPresent "post_update.sh" 51CopyIfPresent "OWNERS" 52CopyIfPresent "README.android" 53 54if [ -f $tmp_dir/Cargo.toml -a -f $tmp_dir/Android.bp ] 55then 56 # regenerate Android.bp before local patches, so it is 57 # possible to patch the generated Android.bp after this. 58 /bin/bash `dirname $0`/regen_bp.sh $root_dir $external_dir 59fi 60 61echo "Applying patches..." 62for p in $tmp_dir/patches/*.{diff,patch} 63do 64 [ -e "$p" ] || continue 65 # Do not patch the Android.bp file, as we assume it will 66 # patch itself. 67 if [ -f $tmp_dir/Cargo.toml ] 68 then 69 [ "$(basename $p)" != "Android.bp.diff" ] || continue 70 [ "$(basename $p)" != "Android.bp.patch" ] || continue 71 fi 72 echo "Applying $p..." 73 patch -p1 -d $tmp_dir --no-backup-if-mismatch < $p; 74done 75 76if [ -f $tmp_dir/Cargo.toml -a -f $tmp_dir/Android.bp ] 77then 78 # regenerate Android.bp after local patches, as they may 79 # have deleted files that it uses. 80 /bin/bash `dirname $0`/regen_bp.sh $root_dir $external_dir 81fi 82 83if [ -f $tmp_dir/post_update.sh ] 84then 85 echo "Running post update script" 86 $tmp_dir/post_update.sh $tmp_dir $external_dir 87fi 88 89echo "Swapping old and new..." 90rm -rf $external_dir 91mv $tmp_dir $external_dir 92 93echo "Updating TEST_MAPPING..." 94UCT="$root_dir/development/scripts/update_crate_tests.py" 95[ -f "$UCT" ] || abort "ERROR: cannot find $UCT" 96$UCT $external_dir 97 98cd $external_dir 99git add . 100 101exit 0 102