xref: /aosp_15_r20/external/robolectric/scripts/update-cpp.sh (revision e6ba16074e6af37d123cb567d575f496bf0a58ee)
1#!/bin/bash
2
3set -e
4
5#currentVersion=android-8.0.0_r36
6#currentVersion=android-8.1.0_r22
7currentVersion=android-9.0.0_r12
8
9baseDir=`dirname $0`/..
10frameworksBaseRepoDir="$HOME/Dev/AOSP/frameworks/base"
11
12function showDiffs2() {
13  file="$1"
14  line="$2"
15
16  x=$(echo "$line" | sed -e 's/.*https:\/\/android.googlesource.com\/\([^ ]*\)\/[+]\/\([^/]*\)\/\([^ ]*\).*/\1 \2 \3/')
17  IFS=" " read -a parts <<< "$x"
18  repo="${parts[0]}"
19  version="${parts[1]}"
20  repoFile="${parts[2]}"
21
22  curSha=$(cd "$frameworksBaseRepoDir" && git rev-parse --verify "$currentVersion") || true
23  if [[ -z "$curSha" ]]; then
24    echo "Unknown $currentVersion!"
25    exit 1
26  fi
27
28  thisSha=$(cd "$frameworksBaseRepoDir" && git rev-parse --verify "$version") || true
29  if [[ -z "$thisSha" ]]; then
30    echo "Unknown $version!"
31    return
32  fi
33
34  if [ "x$curSha" != "x$thisSha" ]; then
35    (cd "$frameworksBaseRepoDir" && git diff --quiet "${version}..${currentVersion}" "--" "$repoFile")
36    if [ $? -eq 0 ]; then
37      echo "No changes in: $file"
38      echo "  From $repoFile $version -> $currentVersion"
39    else
40      tmpFile="/tmp/diff.tmp"
41      rm -f "$tmpFile"
42      echo "Apply changes to: $file" > "$tmpFile"
43      echo "  From $repoFile $version -> $currentVersion" >> "$tmpFile"
44      (cd "$frameworksBaseRepoDir" && git diff --color=always "${version}..${currentVersion}" "--" "$repoFile" >> "$tmpFile")
45      less -r "$tmpFile"
46    fi
47  fi
48}
49
50function showDiffs() {
51  file="$1"
52
53  grep -E 'https?:\/\/(android\.googlesource\.com|.*\.git\.corp\.google\.com)\/' "$file" | \
54      while read -r line ; do
55    showDiffs2 "$file" "$line"
56  done
57}
58
59files=$*
60
61if [ -z "$files" ]; then
62  find . -name "*.java" -print0 | while read -d $'\0' file; do
63    showDiffs "$file"
64  done
65else
66  for file in "$files"; do
67    showDiffs "$file"
68  done
69fi