-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-dev-symlinks.sh
More file actions
executable file
·94 lines (78 loc) · 2.33 KB
/
Copy pathsetup-dev-symlinks.sh
File metadata and controls
executable file
·94 lines (78 loc) · 2.33 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
# The REAL CppBuild.java (and friends) live in CppMode/src/java/. This
# script creates symlinks INSIDE your processing4 checkout (at
# java/src/processing/mode/cpp/) pointing back at these real files, so
# that running Gradle from processing4 compiles the same source you're
# editing here -- no need to keep two copies in sync.
#
# Usage:
# ./setup-dev-symlinks.sh /path/to/your/processing4
set -e
if [ -z "$1" ]; then
echo "Usage: $0 /path/to/your/processing4"
echo "Example: $0 ~/Projects/processing4"
exit 1
fi
if [ ! -d "$1" ]; then
echo "ERROR: '$1' is not a directory."
exit 1
fi
PROCESSING4_DIR="$(cd "$1" && pwd)"
DEST_DIR="$PROCESSING4_DIR/java/src/processing/mode/cpp"
# This script lives in CppMode/scripts/, so CppMode's own root is one
# directory up from wherever this script actually is.
CPPMODE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SRC_DIR="$CPPMODE_DIR/src/java"
if [ ! -d "$SRC_DIR" ]; then
echo "ERROR: $SRC_DIR does not exist."
echo "Expected the real .java source files to live there."
exit 1
fi
mkdir -p "$DEST_DIR"
echo "real source: $SRC_DIR"
echo "linking into: $DEST_DIR"
echo
shopt -s nullglob
SOURCE_FILES=("$SRC_DIR"/*.java)
shopt -u nullglob
if [ ${#SOURCE_FILES[@]} -eq 0 ]; then
echo "WARNING: no .java files found in $SRC_DIR -- nothing to link."
exit 0
fi
linked=0
skipped=0
warned=0
for f in "${SOURCE_FILES[@]}"; do
name="$(basename "$f")"
target="$DEST_DIR/$name"
if [ ! -e "$f" ]; then
echo "WARNING: $name disappeared from source -- skipping."
warned=$((warned+1))
continue
fi
if [ -L "$target" ]; then
current_link="$(readlink "$target")"
if [ "$current_link" == "$f" ]; then
skipped=$((skipped+1))
continue
fi
echo "Replacing stale/incorrect symlink: $name (was -> $current_link)"
rm "$target"
elif [ -e "$target" ]; then
backup="$target.bak"
n=1
while [ -e "$backup" ]; do
backup="$target.bak.$n"
n=$((n+1))
done
echo "Backing up existing $name -> $(basename "$backup")"
mv "$target" "$backup"
fi
ln -s "$f" "$target"
echo "linked $name"
linked=$((linked+1))
done
echo
echo "Done: $linked linked, $skipped already correct, $warned warnings."
echo "$DEST_DIR now points at the real source in $SRC_DIR."
echo "Build the jar by running ./gradlew from $PROCESSING4_DIR."