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