forked from dropbox/dropbox-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff-generated-sources
executable file
·59 lines (52 loc) · 1.76 KB
/
diff-generated-sources
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
# Exit immediately on any error.
set -euo pipefail
# Locate the script file. Cross symlinks if necessary.
loc="$0"
while [ -h "$loc" ]; do
ls=`ls -ld "$loc"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
loc="$link" # Absolute link
else
loc="`dirname "$loc"`/$link" # Relative link
fi
done
# Move to the location of the script
base_dir=`dirname "$loc"`
cd $base_dir
# Save the current branch name.
branch=`git rev-parse --abbrev-ref HEAD`
# Checkout master, update the suprepos and generate source files.
git checkout master
git submodule sync
git submodule update --init
./gradlew cleanGenerateBabelSources generateBabelSources
# Save these source files ia temp directory.
temp_dir="$(mktemp -d -t diff-generated-sources.XXXXXX)" # Weird usage, but works on Linux and Mac OS
function finish() {
[[ ! -e "$temp_dir" ]] || rm -r "$temp_dir"
}
trap finish EXIT
cp -r build/generated-sources/ $temp_dir
# Switch back to the original branch, update the suprepos and generate source files.
git checkout $branch
git submodule sync
git submodule update --init
./gradlew cleanGenerateBabelSources generateBabelSources
# Create the diff and open the page to submit to Phabricator.
# The diff command uses its return command to signal whether there was any
# difference, so we disable exiting on non-zero return codes for this command.
set +e
raw_diff=`diff -uNr ${temp_dir}/babel/ build/generated-sources/babel/`
diff_status=$?
set -e
if [ $diff_status -eq 1 ]; then
echo "$raw_diff" | grep -v "diff -uNr" | pbcopy
echo "Diff copied to the clipboard."
open "https://tails.corp.dropbox.com/differential/diff/create/"
elif [ $diff_status -eq 0 ]; then
>&2 echo "No difference found!"
else
exit $diff_status
fi