package-release.sh 15.4 KB
Newer Older
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
#!/bin/sh
#
# Copyright (C) 2009-2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This script is used to package complete Android NDK release packages.
#
# You will need prebuilt toolchain binary tarballs or a previous
# NDK release package to do that.
#

. `dirname $0`/prebuilt-common.sh

NDK_ROOT_DIR="$ANDROID_NDK_ROOT"

27 28 29 30
# the list of platforms / API levels we want to package in
# this release. This can be overriden with the --platforms
# option, see below.
#
31
PLATFORMS="$API_LEVELS"
32

33 34 35 36 37 38 39 40 41 42 43 44 45
# the default release name (use today's date)
RELEASE=`date +%Y%m%d`
register_var_option "--release=<name>" RELEASE "Specify release name"

# the directory containing all prebuilts
PREBUILT_DIR=
register_var_option "--prebuilt-dir=<path>" PREBUILT_DIR "Specify prebuilt directory"

# a prebuilt NDK archive (.zip file). empty means don't use any
PREBUILT_NDK=
register_var_option "--prebuilt-ndk=<file>" PREBUILT_NDK "Specify prebuilt ndk package"

# the list of supported host development systems
46
SYSTEMS=$DEFAULT_SYSTEMS
47 48
register_var_option "--systems=<list>" SYSTEMS "Specify host systems"

49
# ARCH to build for
50
ARCHS="$DEFAULT_ARCHS"
51
register_var_option "--arch=<arch>" ARCHS "Specify target architecture(s)"
52

53 54 55 56 57 58
# set to 'yes' if we should use 'git ls-files' to list the files to
# be copied into the archive.
NO_GIT=no
register_var_option "--no-git" NO_GIT "Don't use git to list input files, take all of them."

# set of toolchain prebuilts we need to package
59
OPTION_TOOLCHAINS=
60
register_var_option "--toolchains=<list>" OPTION_TOOLCHAINS "Specify list of toolchains."
61 62 63 64 65 66 67 68 69

# set of platforms to package (all by default)
register_var_option "--platforms=<list>" PLATFORMS "Specify API levels"

# the package prefix
PREFIX=android-ndk
register_var_option "--prefix=<name>" PREFIX "Specify package prefix"

# default location for generated packages
70
OUT_DIR=$TMPDIR/release
71 72 73 74 75
OPTION_OUT_DIR=
register_var_option "--out-dir=<path>" OPTION_OUT_DIR "Specify output package directory" "$OUT_DIR"

# Find the location of the platforms root directory
DEVELOPMENT_ROOT=`dirname $ANDROID_NDK_ROOT`/development/ndk
76
register_var_option "--development-root=<path>" DEVELOPMENT_ROOT "Specify platforms directory"
77

78 79 80
GCC_VERSION_LIST="default" # it's arch defined by default so use default keyword
register_var_option "--gcc-version-list=<vers>" GCC_VERSION_LIST "List of GCC release versions"

81 82 83
GDB_VERSION=$DEFAULT_GDB_VERSION
register_var_option "--gdb-version=<versions>" GDB_VERSION "GDB release version"

84 85
register_try64_option

86 87 88 89 90
PROGRAM_PARAMETERS=
PROGRAM_DESCRIPTION=\
"Package a new set of release packages for the Android NDK.

You will need to have generated one or more prebuilt binary tarballs
Dan Albert's avatar
Dan Albert committed
91 92 93
with the checkbuild.py script. These files should be named like
<toolname>-<system>.tar.bz2, where <toolname> is an arbitrary tool name, and
<system> is one of: $SYSTEMS
94 95 96 97 98 99 100 101 102 103 104 105 106

Use the --prebuilt-dir=<path> option to build release packages from the
binary tarballs stored in <path>.

Alternatively, you can use --prebuilt-ndk=<file> where <file> is the path
to a previous NDK release package. It will be used to extract the toolchain
binaries and copy them to your new release. Only use this for experimental
package releases.

The generated release packages will be stored in a temporary directory that
will be printed at the end of the generation process.
"

107
extract_parameters "$@"
108

109 110 111 112
# Ensure that SYSTEMS is space-separated
SYSTEMS=$(commas_to_spaces $SYSTEMS)

ARCHS=$(commas_to_spaces $ARCHS)
113

114 115 116
# Compute ABIS from ARCHS
ABIS=
for ARCH in $ARCHS; do
117 118 119 120 121 122
    DEFAULT_ABIS=$(get_default_abis_for_arch $ARCH)
    if [ -z "$ABIS" ]; then
        ABIS=$DEFAULT_ABIS
    else
        ABIS=$ABIS" $DEFAULT_ABIS"
    fi
123 124
done

Andrew Hsieh's avatar
Andrew Hsieh committed
125
# If --arch is used to list x86 as a target architecture, Add x86-4.8 to
126 127 128 129 130 131 132 133
# the list of default toolchains to package. That is, unless you also
# explicitely use --toolchains=<list>
#
# Ensure that TOOLCHAINS is space-separated after this.
#
if [ "$OPTION_TOOLCHAINS" != "$TOOLCHAINS" ]; then
    TOOLCHAINS=$(commas_to_spaces $OPTION_TOOLCHAINS)
else
134 135 136 137 138 139
    for ARCH in $ARCHS; do
       case $ARCH in
           arm|arm64|x86|x86_64|mips|mips64) TOOLCHAINS=$TOOLCHAINS" "$(get_toolchain_name_list_for_arch $ARCH) ;;
           *) echo "ERROR: Unknown arch to package: $ARCH"; exit 1 ;;
       esac
    done
140 141 142
    TOOLCHAINS=$(commas_to_spaces $TOOLCHAINS)
fi

143 144 145 146 147 148 149 150 151 152 153 154
if [ "$GCC_VERSION_LIST" != "default" ]; then
   TOOLCHAIN_NAMES=
   for VERSION in $(commas_to_spaces $GCC_VERSION_LIST); do
      for TOOLCHAIN in $TOOLCHAINS; do
         if [ $TOOLCHAIN != ${TOOLCHAIN%%$VERSION} ]; then
            TOOLCHAIN_NAMES="$TOOLCHAIN $TOOLCHAIN_NAMES"
         fi
      done
   done
   TOOLCHAINS=$TOOLCHAIN_NAMES
fi

155 156
# Check the prebuilt path
#
157
if [ -n "$PREBUILT_NDK" -a -n "$PREBUILT_DIR" ] ; then
158 159 160 161 162 163 164 165 166 167 168 169
    echo "ERROR: You cannot use both --prebuilt-ndk and --prebuilt-dir at the same time."
    exit 1
fi

if [ -z "$PREBUILT_DIR" -a -z "$PREBUILT_NDK" ] ; then
    echo "ERROR: You must use one of --prebuilt-dir or --prebuilt-ndk. See --help for details."
    exit 1
fi

# Check the option directory.
if [ -n "$OPTION_OUT_DIR" ] ; then
    OUT_DIR="$OPTION_OUT_DIR"
170 171 172 173
    mkdir -p $OUT_DIR
    if [ $? != 0 ] ; then
        echo "ERROR: Could not create output directory: $OUT_DIR"
        exit 1
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    fi
else
    rm -rf $OUT_DIR && mkdir -p $OUT_DIR
fi

# Handle the prebuilt binaries now
#
if [ -n "$PREBUILT_DIR" ] ; then
    if [ ! -d "$PREBUILT_DIR" ] ; then
        echo "ERROR: the --prebuilt-dir argument is not a directory: $PREBUILT_DIR"
        exit 1
    fi
    if [ -z "$SYSTEMS" ] ; then
        echo "ERROR: Your systems list is empty, use --systems=LIST to specify a different one."
        exit 1
    fi
else
    if [ ! -f "$PREBUILT_NDK" ] ; then
        echo "ERROR: the --prebuilt-ndk argument is not a file: $PREBUILT_NDK"
        exit 1
    fi
    # Check that the name ends with the proper host tag
    HOST_NDK_SUFFIX="$HOST_TAG.zip"
    echo "$PREBUILT_NDK" | grep -q "$HOST_NDK_SUFFIX"
198
    fail_panic "The name of the prebuilt NDK must end in $HOST_NDK_SUFFIX"
199 200 201
    SYSTEMS=$HOST_TAG
fi

202 203
echo "Architectures: $ARCHS"
echo "CPU ABIs: $ABIS"
204
echo "GCC Toolchains: $TOOLCHAINS"
205 206 207
echo "Host systems: $SYSTEMS"


208 209 210 211 212 213 214 215 216 217 218 219
# The list of git files to copy into the archives
if [ "$NO_GIT" != "yes" ] ; then
    echo "Collecting sources from git (use --no-git to copy all files instead)."
    GIT_FILES=`cd $NDK_ROOT_DIR && git ls-files`
else
    echo "Collecting all sources files under tree."
    # Get all files under the NDK root
    GIT_FILES=`cd $NDK_ROOT_DIR && find .`
    GIT_FILES=`echo $GIT_FILES | sed -e "s!\./!!g"`
fi

# temporary directory used for packaging
220
TMPDIR=$NDK_TMPDIR
221 222 223 224 225 226

RELEASE_PREFIX=$PREFIX-$RELEASE

# ensure that the generated files are ug+rx
umask 0022

227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
# Translate name to 64-bit's counterpart
# $1: prebuilt name
name64 ()
{
    local NAME=$1
    case $NAME in
        *windows)
            NAME=${NAME}-x86_64
            ;;
        *linux-x86|*darwin-x86)
            NAME=${NAME}_64
            ;;
    esac
    echo $NAME
}

243
# Unpack a prebuilt into specified destination directory
244
# $1: prebuilt name, relative to $PREBUILT_DIR
245
# $2: destination directory
246 247
unpack_prebuilt ()
{
248
    local PREBUILT=$1
249
    local DDIR="$2"
250 251 252

    PREBUILT=${PREBUILT}.tar.bz2

253 254 255 256 257
    echo "Unpacking $PREBUILT"
    if [ -f "$PREBUILT_DIR/$PREBUILT" ] ; then
        unpack_archive "$PREBUILT_DIR/$PREBUILT" "$DDIR"
        fail_panic "Could not unpack prebuilt $PREBUILT. Aborting."
    else
Elliott Hughes's avatar
Elliott Hughes committed
258
        fail_panic "Could not find $PREBUILT in $PREBUILT_DIR"
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
    fi
}

# Copy a prebuilt directory from the previous
# $1: Source directory relative to
copy_prebuilt ()
{
    local SUBDIR="$1"
    if [ -d "$1" ] ; then
        echo "Copying: $SUBDIR"
        copy_directory "$SUBDIR" "$DSTDIR/$2"
    else
        echo "Ignored: $SUBDIR"
    fi
}


276 277
rm -rf $TMPDIR && mkdir -p $TMPDIR

278 279 280 281 282 283 284 285 286 287
# Unpack the previous NDK package if any
if [ -n "$PREBUILT_NDK" ] ; then
    echo "Unpacking prebuilt toolchains from $PREBUILT_NDK"
    UNZIP_DIR=$TMPDIR/prev-ndk
    rm -rf $UNZIP_DIR && mkdir -p $UNZIP_DIR
    fail_panic "Could not create temporary directory: $UNZIP_DIR"
    unpack_archive "$PREBUILT_NDK" "$UNZIP_DIR"
    fail_panic "Could not unzip NDK package $PREBUILT_NDK"
fi

288 289
# first create the reference ndk directory from the git reference
echo "Creating reference from source files"
290
REFERENCE=$TMPDIR/reference && rm -rf $REFERENCE/* &&
291
copy_file_list "$NDK_ROOT_DIR" "$REFERENCE" $GIT_FILES &&
292
rm -f $REFERENCE/Android.mk
293
fail_panic "Could not create reference. Aborting."
294

295 296 297
# Copy platform and sample files
if [ "$PREBUILT_DIR" ]; then
    echo "Unpacking platform files" &&
298 299
    unpack_archive "$PREBUILT_DIR/platforms.tar.bz2" "$REFERENCE"
    fail_panic "Could not unpack platform files"
300 301 302 303 304 305 306 307 308 309 310 311
elif [ "$PREBUILT_NDK" ]; then
    echo "ERROR: NOT IMPLEMENTED!"
    exit 1
else
    # copy platform and sample files
    echo "Copying platform and sample files"
    FLAGS="--src-dir=$DEVELOPMENT_ROOT --dst-dir=$REFERENCE"
    FLAGS="$FLAGS --platform=$(spaces_to_commas $PLATFORMS)"
    FLAGS="$FLAGS --arch=$(spaces_to_commas $ARCHS)"
    $NDK_ROOT_DIR/build/tools/gen-platforms.sh $FLAGS
    fail_panic "Could not copy platform files. Aborting."
fi
312

313 314
cp -r $NDK_ROOT_DIR/samples $REFERENCE

315 316 317
# Remove the source for host tools to make the final package smaller
rm -rf $REFERENCE/sources/host-tools

318
# Remove leftovers, just in case...
319 320 321
rm -rf $REFERENCE/tests/build/*/{obj,libs} &&
rm -rf $REFERENCE/tests/device/*/{obj,libs}

322 323 324
# copy sources files
if [ -d $DEVELOPMENT_ROOT/sources ] ; then
    echo "Copying NDK sources files"
325 326
    copy_file_list "$DEVELOPMENT_ROOT" "$REFERENCE" "sources"
    fail_panic "Could not copy sources. Aborting."
327 328
fi

329 330 331
# Unpack prebuilt C++ runtimes headers and libraries
if [ -z "$PREBUILT_NDK" ]; then
    # Unpack gdbserver
332
    for ARCH in $ARCHS; do
333
        unpack_prebuilt gdbserver-$ARCH "$REFERENCE"
334 335
    done
    # Unpack C++ runtimes
336
    for VERSION in $DEFAULT_GCC_VERSION_LIST; do
Dan Albert's avatar
Dan Albert committed
337
        unpack_prebuilt gnustl-$VERSION "$REFERENCE"
338
    done
339 340 341

    unpack_prebuilt stlport "$REFERENCE"
    unpack_prebuilt libcxx "$REFERENCE"
342 343
fi

344 345 346 347 348
# create a release file named 'RELEASE.TXT' containing the release
# name. This is used by the build script to detect whether you're
# invoking the NDK from a release package or from the development
# tree.
#
349 350 351 352 353
if [ "$TRY64" = "yes" ]; then
    echo "$RELEASE (64-bit)" > $REFERENCE/RELEASE.TXT
else
    echo "$RELEASE" > $REFERENCE/RELEASE.TXT
fi
354 355 356 357 358 359

# Remove un-needed files
rm -f $REFERENCE/CleanSpec.mk

# now, for each system, create a package
#
360 361
DSTDIR=$TMPDIR/$RELEASE_PREFIX

362
for SYSTEM in $SYSTEMS; do
363 364 365 366
    if [ "$TRY64" = "yes" ]; then
        SYSTEM=`name64 $SYSTEM`
    fi

367 368
    echo "Preparing package for system $SYSTEM."
    BIN_RELEASE=$RELEASE_PREFIX-$SYSTEM
369 370
    rm -rf "$DSTDIR" &&
    mkdir -p "$DSTDIR" &&
371
    copy_directory "$REFERENCE" "$DSTDIR"
372
    fail_panic "Could not copy reference. Aborting."
373

374
    if [ "$PREBUILT_NDK" ]; then
375 376
        cd $UNZIP_DIR/android-ndk-* && cp -rP toolchains/$SYSTEM/* \
            $DSTDIR/toolchains/$SYSTEM
377
        fail_panic "Could not copy toolchain files from $PREBUILT_NDK"
378

379 380 381 382 383 384 385 386 387
        if [ -d "$DSTDIR/$GABIXX_SUBDIR" ]; then
            GABIXX_ABIS=$PREBUILT_ABIS
            for GABIXX_ABI in $GABIXX_ABIS; do
                copy_prebuilt "$GABIXX_SUBDIR/libs/$GABIXX_ABI" "$GABIXX_SUBDIR/libs"
            done
        else
            echo "WARNING: Could not find GAbi++ source tree!"
        fi

388
        if [ -d "$DSTDIR/$STLPORT_SUBDIR" ] ; then
389
            STLPORT_ABIS=$PREBUILT_ABIS
390
            for STL_ABI in $STLPORT_ABIS; do
391
                copy_prebuilt "$STLPORT_SUBDIR/libs/$STL_ABI" "$STLPORT_SUBDIR/libs"
392 393 394 395
            done
        else
            echo "WARNING: Could not find STLport source tree!"
        fi
396

Andrew Hsieh's avatar
Andrew Hsieh committed
397
        if [ -d "$DSTDIR/$LIBCXX_SUBDIR" ]; then
398
            LIBCXX_ABIS=$PREBUILT_ABIS
Andrew Hsieh's avatar
Andrew Hsieh committed
399 400 401 402 403
            for STL_ABI in $LIBCXX_ABIS; do
                copy_prebuilt "$LIBCXX_SUBDIR/libs/$STL_ABI" "$LIBCXX_SUBDIR/libs"
            done
        else
            echo "WARNING: Could not find Libc++ source tree!"
404 405
        fi

406 407 408 409 410
        for VERSION in $DEFAULT_GCC_VERSION_LIST; do
            copy_prebuilt "$GNUSTL_SUBDIR/$VERSION/include" "$GNUSTL_SUBDIR/$VERSION/"
            for STL_ABI in $PREBUILT_ABIS; do
                copy_prebuilt "$GNUSTL_SUBDIR/$VERSION/libs/$STL_ABI" "$GNUSTL_SUBDIR/$VERSION/libs"
            done
411
        done
412
    else
Dan Albert's avatar
Dan Albert committed
413
        for ARCH in $ARCHS; do
414
            unpack_prebuilt gcc-$ARCH-$SYSTEM "$DSTDIR"
Dan Albert's avatar
Dan Albert committed
415
            unpack_prebuilt binutils-$ARCH-$SYSTEM "$DSTDIR"
Dan Albert's avatar
Dan Albert committed
416
            unpack_prebuilt gcclibs-$ARCH "$DSTDIR"
Dan Albert's avatar
Dan Albert committed
417 418
        done

Andrew Hsieh's avatar
Andrew Hsieh committed
419
        # Unpack clang/llvm
420
        unpack_prebuilt llvm-$SYSTEM "$DSTDIR"
Logan Chien's avatar
Logan Chien committed
421

422
        rm -rf $DSTDIR/toolchains/$SYSTEM/*l
423

Elliott Hughes's avatar
Elliott Hughes committed
424 425
        # Unpack renderscript tools; http://b/22377128.
        echo "WARNING: no renderscript-$SYSTEM tools! http://b/22377128"
426
        #unpack_prebuilt renderscript-$SYSTEM "$DSTDIR"
427

428
        # Unpack prebuilt ndk-stack and other host tools
Dan Albert's avatar
Dan Albert committed
429
        unpack_prebuilt host-tools-$SYSTEM "$DSTDIR"
430 431
    fi

Elliott Hughes's avatar
Elliott Hughes committed
432 433
    # Unpack renderscript headers/libs; http://b/22377128.
    echo "WARNING: no renderscript headers/libs! http://b/22377128"
434
    #unpack_prebuilt renderscript "$DSTDIR"
Andrew Hsieh's avatar
Andrew Hsieh committed
435

Andrew Hsieh's avatar
Andrew Hsieh committed
436 437
    # Unpack misc stuff
    if [ -f "$PREBUILT_DIR/misc.tar.bz2" ]; then
438
        unpack_prebuilt misc "$DSTDIR"
Andrew Hsieh's avatar
Andrew Hsieh committed
439 440
    fi

Andrew Hsieh's avatar
Andrew Hsieh committed
441
    # Remove duplicated files in case-insensitive file system
442 443
    if [ "$SYSTEM" = "windows" -o "$SYSTEM" = "windows-x86_64" -o \
         "$SYSTEM" = "darwin-x86" ]; then
Andrew Hsieh's avatar
Andrew Hsieh committed
444
        rm -rf $DSTDIR/tests/build/c++-stl-source-extensions
445
        find "$DSTDIR/platforms" | sort -f | uniq -di | xargs rm
Andrew Hsieh's avatar
Andrew Hsieh committed
446 447 448
    fi

    # Remove include-fixed/linux/a.out.h.   See b.android.com/73728
449
    find "$DSTDIR/toolchains" -name a.out.h | grep include-fixed/ | xargs rm
Andrew Hsieh's avatar
Andrew Hsieh committed
450

451
    # Remove redundant pretty-printers/libstdcxx
452 453
    rm -rf $DSTDIR/prebuilt/share/pretty-printers/libstdcxx/gcc-l*
    rm -rf $DSTDIR/prebuilt/share/pretty-printers/libstdcxx/gcc-4.9-*
454

455
    # Remove python *.pyc and *.pyo files
456 457
    find $DSTDIR/prebuilt/lib/python* -name "*.pyc" -exec rm -rf {} \;
    find $DSTDIR/prebuilt/lib/python* -name "*.pyo" -exec rm -rf {} \;
458

459 460 461
    # Remove .git*
    find $DSTDIR -name ".git*" -exec rm -rf {} \;

462 463
    # Create an archive for the final package. Extension depends on the
    # host system.
464
    ARCHIVE=$BIN_RELEASE
465
    if [ "$SYSTEM" = "windows" ]; then
466
        ARCHIVE=$ARCHIVE-x86
467
    fi
468
    case "$SYSTEM" in
469
        windows|windows-x86_64)
470
            ARCHIVE="$ARCHIVE.zip"
471 472
            ;;
        *)
473
            ARCHIVE="$ARCHIVE.tar.bz2"
474 475
            ;;
    esac
Dan Albert's avatar
Dan Albert committed
476

477
    make_repo_prop $DSTDIR
478

479
    echo "Creating $ARCHIVE"
480 481
    # make all file universally readable, and all executable (including directory)
    # universally executable, punt intended
482 483
    find $DSTDIR -exec chmod a+r {} \;
    find $DSTDIR -executable -exec chmod a+x {} \;
484 485
    pack_archive "$OUT_DIR/$ARCHIVE" "$TMPDIR" "$RELEASE_PREFIX"
    fail_panic "Could not create archive: $OUT_DIR/$ARCHIVE"
486 487 488 489 490 491 492
done

echo "Cleaning up."
rm -rf $TMPDIR/reference
rm -rf $TMPDIR/prev-ndk

echo "Done, please see packages in $OUT_DIR:"
493
ls -lh $OUT_DIR | tee $OUT_DIR/artifacts.txt