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