• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# See usage() below for the description.
3
4function usage() {
5  cat <<EOF
6# This script copies the .jar files that each plugin depends on into the plugins libs folder.
7# By default, on Mac & Linux, this script creates symlinks from the libs folder to the jar file.
8# Since Windows does not support symlinks, the jar files are copied.
9#
10# Options:
11# -f : to copy files rather than creating symlinks on the Mac/Linux platforms.
12# -d : print make dependencies instead of running make; doesn't copy files.
13# -c : copy files expected after make dependencies (reported by -d) have been built.
14#
15# The purpose of -d/-c is to include the workflow in a make file:
16# - the make rule should depend on \$(shell create_all_symlinks -d)
17# - the rule body should perform   \$(shell create_all_symlinks -c [-f])
18EOF
19}
20
21# CD to the top android directory
22PROG_DIR=`dirname "$0"`
23cd "${PROG_DIR}/../../../"
24
25HOST=`uname`
26USE_COPY=""        # force copy dependent jar files rather than creating symlinks
27ONLY_SHOW_DEPS=""  # only report make dependencies but don't build them nor copy.
28ONLY_COPY_DEPS=""  # only copy dependencies built by make; uses -f as needed.
29
30function die() {
31  echo "Error: $*" >/dev/stderr
32  exit 1
33}
34
35function warn() {
36  # Only print something if not in show-deps mode
37  if [[ -z $ONLY_SHOW_DEPS ]]; then
38    echo "$*"
39  fi
40}
41
42## parse arguments
43while [ $# -gt 0 ]; do
44  case "$1" in
45    "-f" )
46      USE_COPY="1"
47      ;;
48    "-d" )
49      ONLY_SHOW_DEPS="1"
50      ;;
51    "-c" )
52      ONLY_COPY_DEPS="1"
53      ;;
54    * )
55      usage
56      exit 2
57  esac
58  shift
59done
60
61warn "## Running $0"
62
63if [[ "${HOST:0:6}" == "CYGWIN" || "$USE_MINGW" == "1" ]]; then
64  # This is either Cygwin or Linux/Mingw cross-compiling to Windows.
65  PLATFORM="windows-x86"
66  if [[ "${HOST:0:6}" == "CYGWIN" ]]; then
67    # We can't use symlinks under Cygwin
68    USE_COPY="1"
69  fi
70elif [[ "$HOST" == "Linux" ]]; then
71  PLATFORM="linux-x86"
72elif [[ "$HOST" == "Darwin" ]]; then
73  PLATFORM="darwin-x86"
74else
75  die "Unsupported platform ($HOST). Aborting."
76fi
77
78if [[ "$USE_COPY" == "1" ]]; then
79  function cpfile { # $1=source $2=dest
80    cp -fv $1 $2/
81  }
82
83  function cpdir() { # $1=source $2=dest
84    rsync -avW --delete-after $1 $2
85  }
86else
87  # computes the "reverse" path, e.g. "a/b/c" => "../../.."
88  function back() {
89    echo $1 | sed 's@[^/]*@..@g'
90  }
91
92  function cpfile { # $1=source $2=dest
93    ln -svf `back $2`/$1 $2/
94  }
95
96  function cpdir() { # $1=source $2=dest
97    ln -svf `back $2`/$1 $2
98  }
99fi
100
101DEST="sdk/eclipse/scripts"
102
103set -e # fail early
104LIBS=""
105CP_FILES=""
106
107
108### BASE ###
109
110BASE_PLUGIN_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.base/libs"
111BASE_PLUGIN_LIBS="common sdkstats sdklib dvlib layoutlib-api sdk-common"
112BASE_PLUGIN_PREBUILTS="\
113    prebuilts/tools/common/m2/repository/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.jar \
114    prebuilts/tools/common/m2/repository/org/apache/commons/commons-compress/1.0/commons-compress-1.0.jar \
115    prebuilts/tools/common/m2/repository/com/google/guava/guava/13.0.1/guava-13.0.1.jar \
116    prebuilts/tools/common/m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar \
117    prebuilts/tools/common/m2/repository/commons-codec/commons-codec/1.4/commons-codec-1.4.jar \
118    prebuilts/tools/common/m2/repository/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.jar \
119    prebuilts/tools/common/m2/repository/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar \
120    prebuilts/tools/common/m2/repository/org/apache/httpcomponents/httpmime/4.1/httpmime-4.1.jar \
121    prebuilts/tools/common/m2/repository/org/bouncycastle/bcpkix-jdk15on/1.48/bcpkix-jdk15on-1.48.jar \
122    prebuilts/tools/common/m2/repository/org/bouncycastle/bcprov-jdk15on/1.48/bcprov-jdk15on-1.48.jar"
123
124LIBS="$LIBS $BASE_PLUGIN_LIBS"
125CP_FILES="$CP_FILES @:$BASE_PLUGIN_DEST $BASE_PLUGIN_LIBS $BASE_PLUGIN_PREBUILTS"
126
127
128### ADT ###
129
130ADT_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.adt/libs"
131ADT_LIBS="ant-glob asset-studio lint-api lint-checks ninepatch propertysheet rule-api sdkuilib swtmenubar manifest-merger"
132ADT_PREBUILTS="\
133    prebuilts/tools/common/freemarker/freemarker-2.3.19.jar \
134    prebuilts/tools/common/m2/repository/org/ow2/asm/asm/4.0/asm-4.0.jar \
135    prebuilts/tools/common/m2/repository/org/ow2/asm/asm-tree/4.0/asm-tree-4.0.jar \
136    prebuilts/tools/common/m2/repository/org/ow2/asm/asm-analysis/4.0/asm-analysis-4.0.jar \
137    prebuilts/tools/common/lombok-ast/lombok-ast-0.2.jar"
138
139LIBS="$LIBS $ADT_LIBS"
140CP_FILES="$CP_FILES @:$ADT_DEST $ADT_LIBS $ADT_PREBUILTS"
141
142
143### DDMS ###
144
145DDMS_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.ddms/libs"
146DDMS_LIBS="ddmlib ddmuilib swtmenubar uiautomatorviewer"
147
148DDMS_PREBUILTS="\
149    prebuilts/tools/common/m2/repository/jfree/jcommon/1.0.12/jcommon-1.0.12.jar \
150    prebuilts/tools/common/m2/repository/jfree/jfreechart/1.0.9/jfreechart-1.0.9.jar \
151    prebuilts/tools/common/m2/repository/jfree/jfreechart-swt/1.0.9/jfreechart-swt-1.0.9.jar"
152
153LIBS="$LIBS $DDMS_LIBS"
154CP_FILES="$CP_FILES @:$DDMS_DEST $DDMS_LIBS $DDMS_PREBUILTS"
155
156
157### TEST ###
158
159TEST_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.tests"
160TEST_LIBS="easymock sdktestutils"
161TEST_PREBUILTS="prebuilts/tools/common/m2/repository/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.jar"
162
163LIBS="$LIBS $TEST_LIBS"
164CP_FILES="$CP_FILES @:$TEST_DEST $TEST_LIBS $TEST_PREBUILTS"
165
166
167### BRIDGE ###
168
169if [[ $PLATFORM != "windows-x86" ]]; then
170  # We can't build enough of the platform on Cygwin to create layoutlib
171  BRIDGE_LIBS="layoutlib ninepatch"
172
173  LIBS="$LIBS $BRIDGE_LIBS"
174fi
175
176
177### HIERARCHYVIEWER ###
178
179HV_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/libs"
180HV_LIBS="hierarchyviewer2lib swtmenubar"
181
182LIBS="$LIBS $HV_LIBS"
183CP_FILES="$CP_FILES @:$HV_DEST $HV_LIBS"
184
185
186### TRACEVIEW ###
187
188TV_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.traceview/libs"
189TV_LIBS="traceview"
190
191LIBS="$LIBS $TV_LIBS"
192CP_FILES="$CP_FILES @:$TV_DEST $TV_LIBS"
193
194
195### MONITOR ###
196
197MONITOR_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.monitor/libs"
198MONITOR_LIBS="sdkuilib"
199
200LIBS="$LIBS $MONITOR_LIBS"
201CP_FILES="$CP_FILES @:$MONITOR_DEST $MONITOR_LIBS"
202
203
204### SDKMANAGER ###
205
206SDKMAN_LIBS="swtmenubar"
207
208LIBS="$LIBS $SDKMAN_LIBS"
209
210
211### GL DEBUGGER ###
212
213if [[ $PLATFORM != "windows-x86" ]]; then
214  # liblzf doesn't build under cygwin. If necessary, this should be fixed first.
215
216  GLD_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.gldebugger/libs"
217  GLD_LIBS="host-libprotobuf-java-2.3.0-lite liblzf"
218
219  LIBS="$LIBS $GLD_LIBS"
220  CP_FILES="$CP_FILES @:$GLD_DEST $GLD_LIBS"
221fi
222
223# If some of the libs are available in prebuilts/devtools, use link to them directly
224# instead of trying to rebuild them so remove them from the libs to build. Note that
225# they are already listed in CP_FILES so we'll adjust the source to copy later.
226
227LIBS2=""
228for LIB in $LIBS; do
229  J="prebuilts/devtools/tools/lib/$LIB.jar"
230  if [[ ! -f $J ]]; then
231    J="prebuilts/devtools/adt/lib/$LIB.jar"
232  fi
233  if [[ -f $J ]]; then
234    warn "## Using existing $J"
235  else
236    LIBS2="$LIBS2 $LIB"
237  fi
238done
239LIBS="$LIBS2"
240unset LIBS2
241
242# In the mode to only echo dependencies, output them and we're done
243if [[ -n $ONLY_SHOW_DEPS ]]; then
244  echo $LIBS
245  exit 0
246fi
247
248if [[ -z $ONLY_COPY_DEPS ]]; then
249  # Make sure we have lunch sdk-<something>
250  if [[ ! "$TARGET_PRODUCT" ]]; then
251    warn "## TARGET_PRODUCT is not set, running build/envsetup.sh"
252    . build/envsetup.sh
253    warn "## lunch sdk-eng"
254    lunch sdk-eng
255  fi
256
257  # Run make on all libs
258
259  J="4"
260  [[ $(uname) == "Darwin" ]] && J=$(sysctl hw.ncpu | cut -d : -f 2 | tr -d ' ')
261  [[ $(uname) == "Linux"  ]] && J=$(cat /proc/cpuinfo | grep processor | wc -l)
262
263  warn "## Building libs: make -j$J $LIBS"
264  make -j${J} $LIBS
265fi
266
267# Copy resulting files
268DEST=""
269for SRC in $CP_FILES; do
270  if [[ "${SRC:0:2}" == "@:" ]]; then
271    DEST="${SRC:2}"
272    mkdir -vp "$DEST"
273    continue
274  fi
275  if [[ ! -f "$SRC" ]]; then
276    ORIG_SRC="$SRC"
277    # Take a prebuilts/devtools instead of a framework one if possible.
278    SRC="prebuilts/devtools/tools/lib/$SRC.jar"
279    if [[ ! -f "$SRC" ]]; then
280      SRC="prebuilts/devtools/adt/lib/$ORIG_SRC.jar"
281    fi
282    if [[ ! -f "$SRC" ]]; then
283      SRC="out/host/$PLATFORM/framework/$ORIG_SRC.jar"
284    fi
285  fi
286  if [[ -f "$SRC" ]]; then
287    if [[ ! -d "$DEST" ]]; then
288      die "Invalid cp_file dest directory: $DEST"
289    fi
290
291    cpfile "$SRC" "$DEST"
292  else
293    die "## Unknown source '$ORIG_SRC' to copy in '$DEST'"
294  fi
295done
296
297# OS-specific post operations
298
299if [ "${HOST:0:6}" == "CYGWIN" ]; then
300  chmod -v a+rx "$ADT_DEST"/*.jar
301fi
302
303echo "### $0 done"
304