• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
57echo "Applying patches..."
58for p in $tmp_dir/patches/*.{diff,patch}
59do
60  [ -e "$p" ] || continue
61  # Do not patch the Android.bp file, as we assume it will
62  # patch itself.
63  if [ -f $tmp_dir/Cargo.toml ]
64  then
65      [ "$(basename $p)" != "Android.bp.diff" ] || continue
66      [ "$(basename $p)" != "Android.bp.patch" ] || continue
67  fi
68  echo "Applying $p..."
69  patch -p1 -d $tmp_dir --no-backup-if-mismatch < $p;
70done
71
72if [ -f $tmp_dir/Cargo.toml -a -f $tmp_dir/Android.bp ]
73then
74    # regenerate Android.bp after local patches, as they may
75    # have deleted files that it uses.
76  /bin/bash `dirname $0`/regen_bp.sh $root_dir $external_dir
77fi
78
79if [ -f $tmp_dir/post_update.sh ]
80then
81  echo "Running post update script"
82  $tmp_dir/post_update.sh $tmp_dir $external_dir
83fi
84
85echo "Swapping old and new..."
86second_tmp_dir=`mktemp -d`
87mv $external_dir $second_tmp_dir
88mv $tmp_dir $external_dir
89mv $second_tmp_dir/* $tmp_dir
90rm -rf $second_tmp_dir
91if [ -n "$tmp_file" ]; then
92    # Write to the temporary file to show we have swapped.
93    echo "Swapping" > $tmp_file
94fi
95
96cd $external_dir
97git add .
98
99exit 0
100