-
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
·108 lines (92 loc) · 3.05 KB
/
Copy pathsetup-dev-symlinks.sh
File metadata and controls
executable file
·108 lines (92 loc) · 3.05 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
# The REAL CppBuild.java (and friends) live in THIS folder's 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.
#
# Handles:
# - destination directory missing entirely (creates it)
# - individual source files missing (skips just that one, warns)
# - a target that's already a regular file (backs it up, then links)
# - a target that's already a CORRECT symlink (skips, no-op)
# - a target that's a symlink pointing somewhere ELSE / dangling
# (replaces it with the correct link)
# - files in the destination that aren't part of our known set
# (left completely alone)
#
# 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"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SRC_DIR="$SCRIPT_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
# Shouldn't normally happen (glob already matched it), but guards
# against a file being deleted mid-run.
echo "WARNING: $name disappeared from source -- skipping."
warned=$((warned+1))
continue
fi
if [ -L "$target" ]; then
# Already a symlink -- check if it already points at the right file.
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
# A REAL file/directory sits at the target -- back it up rather than
# silently destroying whatever's there (could be a contributor's own
# local edits made before running this script).
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."