aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/scripts/create_all_symlinks.sh
blob: 25dce68747f394e1173ca87639ac79c3ed140e57 (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash
# See usage() below for the description.

function usage() {
  cat <<EOF
# This script copies the .jar files that each plugin depends on into the plugins libs folder.
# By default, on Mac & Linux, this script creates symlinks from the libs folder to the jar file.
# Since Windows does not support symlinks, the jar files are copied.
#
# Options:
# -f : to copy files rather than creating symlinks on the Mac/Linux platforms.
# -d : print make dependencies instead of running make; doesn't copy files.
# -c : copy files expected after make dependencies (reported by -d) have been built.
#
# The purpose of -d/-c is to include the workflow in a make file:
# - the make rule should depend on \$(shell create_all_symlinks -d)
# - the rule body should perform   \$(shell create_all_symlinks -c [-f])
EOF
}

# CD to the top android directory
PROG_DIR=`dirname "$0"`
cd "${PROG_DIR}/../../../"

HOST=`uname`
USE_COPY=""        # force copy dependent jar files rather than creating symlinks
ONLY_SHOW_DEPS=""  # only report make dependencies but don't build them nor copy.
ONLY_COPY_DEPS=""  # only copy dependencies built by make; uses -f as needed.

function die() {
  echo "Error: $*" >/dev/stderr
  exit 1
}

function warn() {
  # Only print something if not in show-deps mode
  if [[ -z $ONLY_SHOW_DEPS ]]; then
    echo "$*"
  fi
}

## parse arguments
while [ $# -gt 0 ]; do
  case "$1" in
    "-f" )
      USE_COPY="1"
      ;;
    "-d" )
      ONLY_SHOW_DEPS="1"
      ;;
    "-c" )
      ONLY_COPY_DEPS="1"
      ;;
    * )
      usage
      exit 2
  esac
  shift
done

warn "## Running $0"

if [[ "${HOST:0:6}" == "CYGWIN" || "$USE_MINGW" == "1" ]]; then
  # This is either Cygwin or Linux/Mingw cross-compiling to Windows.
  PLATFORM="windows-x86"
  if [[ "${HOST:0:6}" == "CYGWIN" ]]; then
    # We can't use symlinks under Cygwin
    USE_COPY="1"
  fi
elif [[ "$HOST" == "Linux" ]]; then
  PLATFORM="linux-x86"
elif [[ "$HOST" == "Darwin" ]]; then
  PLATFORM="darwin-x86"
else
  die "Unsupported platform ($HOST). Aborting."
fi

if [[ "$USE_COPY" == "1" ]]; then
  function cpfile { # $1=source $2=dest
    cp -fv $1 $2/
  }

  function cpdir() { # $1=source $2=dest
    rsync -avW --delete-after $1 $2
  }
else
  # computes the "reverse" path, e.g. "a/b/c" => "../../.."
  function back() {
    echo $1 | sed 's@[^/]*@..@g'
  }

  function cpfile { # $1=source $2=dest
    ln -svf `back $2`/$1 $2/
  }

  function cpdir() { # $1=source $2=dest
    ln -svf `back $2`/$1 $2
  }
fi

DEST="sdk/eclipse/scripts"

set -e # fail early

LIBS=""
CP_FILES=""

### ADT ###

ADT_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.adt/libs"
ADT_LIBS="sdkstats androidprefs common layoutlib_api lint_api lint_checks ide_common rule_api ninepatch sdklib sdkuilib assetstudio"
ADT_PREBUILTS="\
    prebuilt/common/kxml2/kxml2-2.3.0.jar \
    prebuilts/tools/common/asm-tools/asm-4.0.jar \
    prebuilts/tools/common/asm-tools/asm-tree-4.0.jar \
    prebuilts/tools/common/guava-tools/guava-10.0.1.jar \
    prebuilts/tools/common/lombok-ast/lombok-ast-0.2.jar \
    prebuilt/common/commons-compress/commons-compress-1.0.jar \
    prebuilt/common/http-client/httpclient-4.1.1.jar \
    prebuilt/common/http-client/httpcore-4.1.jar \
    prebuilt/common/http-client/httpmime-4.1.1.jar \
    prebuilt/common/http-client/commons-logging-1.1.1.jar \
    prebuilt/common/http-client/commons-codec-1.4.jar"

LIBS="$LIBS $ADT_LIBS"
CP_FILES="$CP_FILES @:$ADT_DEST $ADT_LIBS $ADT_PREBUILTS"

### DDMS ###

DDMS_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.ddms/libs"
DDMS_LIBS="ddmlib ddmuilib swtmenubar"

DDMS_PREBUILTS="\
    prebuilt/common/jfreechart/jcommon-1.0.12.jar \
    prebuilt/common/jfreechart/jfreechart-1.0.9.jar \
    prebuilt/common/jfreechart/jfreechart-1.0.9-swt.jar"

LIBS="$LIBS $DDMS_LIBS"
CP_FILES="$CP_FILES @:$DDMS_DEST $DDMS_LIBS $DDMS_PREBUILTS"


### TEST ###

TEST_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.tests"
TEST_LIBS="easymock"
TEST_PREBUILTS="prebuilt/common/kxml2/kxml2-2.3.0.jar"

LIBS="$LIBS $TEST_LIBS"
CP_FILES="$CP_FILES @:$TEST_DEST $TEST_LIBS $TEST_PREBUILTS"


### BRIDGE ###

if [[ $PLATFORM != "windows-x86" ]]; then
  # We can't build enough of the platform on Cygwin to create layoutlib
  BRIDGE_LIBS="layoutlib ninepatch"

  LIBS="$LIBS $BRIDGE_LIBS"
fi



### HIERARCHYVIEWER ###

HV_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/libs"
HV_LIBS="hierarchyviewerlib swtmenubar"

LIBS="$LIBS $HV_LIBS"
CP_FILES="$CP_FILES @:$HV_DEST $HV_LIBS"


### TRACEVIEW ###

TV_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.traceview/libs"
TV_LIBS="traceview"

LIBS="$LIBS $TV_LIBS"
CP_FILES="$CP_FILES @:$TV_DEST $TV_LIBS"


### SDKMANAGER ###

SDMAN_LIBS="swtmenubar"

LIBS="$LIBS $SDKMAN_LIBS"

### MONITOR ###

MONITOR_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.monitor/libs"
MONITOR_LIBS="sdklib sdkstats androidprefs"

LIBS="$LIBS $MONITOR_LIBS"
CP_FILES="$CP_FILES @:$MONITOR_DEST $MONITOR_LIBS"

### GL DEBUGGER ###

if [[ $PLATFORM != "windows-x86" ]]; then
  # liblzf doesn't build under cygwin. If necessary, this should be fixed first.
  
  GLD_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.gldebugger/libs"
  GLD_LIBS="host-libprotobuf-java-2.3.0-lite liblzf sdklib ddmlib"
  GLD_PREBUILTS="prebuilts/tools/common/guava-tools/guava-10.0.1.jar"

  LIBS="$LIBS $GLD_LIBS"
  CP_FILES="$CP_FILES @:$GLD_DEST $GLD_LIBS $GLD_PREBUILTS"
fi

# In the mode to only echo dependencies, output them and we're done
if [[ -n $ONLY_SHOW_DEPS ]]; then
  echo $LIBS
  exit 0
fi

if [[ -z $ONLY_COPY_DEPS ]]; then
  # Make sure we have lunch sdk-<something>
  if [[ ! "$TARGET_PRODUCT" ]]; then
    warn "## TARGET_PRODUCT is not set, running build/envsetup.sh"
    . build/envsetup.sh
    warn "## lunch sdk-eng"
    lunch sdk-eng
  fi

  # Run make on all libs

  J="4"
  [[ $(uname) == "Darwin" ]] && J=$(sysctl hw.ncpu | cut -d : -f 2 | tr -d ' ')
  [[ $(uname) == "Linux"  ]] && J=$(cat /proc/cpuinfo | grep processor | wc -l)

  warn "## Building libs: make -j$J $LIBS"
  make -j${J} $LIBS
fi

# Copy resulting files
DEST=""
for SRC in $CP_FILES; do
  if [[ "${SRC:0:2}" == "@:" ]]; then
    DEST="${SRC:2}"
    mkdir -vp "$DEST"
    continue
  fi
  if [[ ! -f "$SRC" ]]; then
    SRC="out/host/$PLATFORM/framework/$SRC.jar"
  fi
  if [[ -f "$SRC" ]]; then
    if [[ ! -d "$DEST" ]]; then
      die "Invalid cp_file dest directory: $DEST"
    fi

    cpfile "$SRC" "$DEST"
  else
    die "## Unknown file '$SRC' to copy in '$DEST'"
  fi
done

# OS-specific post operations

if [ "${HOST:0:6}" == "CYGWIN" ]; then
  chmod -v a+rx "$ADT_DEST"/*.jar
fi

echo "### $0 done"