Home | History | Annotate | Download | only in tools
      1 #!/bin/sh
      2 #
      3 # Copyright (C) 2011 The Android Open Source Project
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 #      http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an "AS IS" BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 #
     17 # dev-platform-compress.sh
     18 #
     19 # Compressed expanded platform files into development/ndk/platforms/
     20 # structure.
     21 #
     22 
     23 PROGDIR=$(dirname $0)
     24 . $PROGDIR/prebuilt-common.sh
     25 
     26 PROGRAM_PARAMETERS=""
     27 PROGRAM_DESCRIPTION=\
     28 "This script is used to compress an expanded platforms NDK tree
     29 into the compressed/minimal structure used in development/ndk/platforms.
     30 
     31 The main idea is that in the destination directory, a file only appears
     32 once, even if it is provided by several platforms. I.e. if we have:
     33 
     34   file1 = \$SRC/android-3/foo
     35   file2 = \$SRC/android-4/foo
     36   file3 = \$SRC/android-5/foo
     37 
     38 We will always store a copy of file1 under \$DST/android-3/foo
     39 If file2 is identical to file1, we remove its copy in \$DST/android-4/foo,
     40 otherwise we do copy it to the same location
     41 
     42 If file3 is identical to file2, we remove its copy in \$DST/android-4/foo,
     43 otherwise we copy it to the same location.
     44 
     45 Repeat for all files under \$SRC/android-N for increasing values of N.
     46 "
     47 
     48 SRCDIR=/tmp/ndk-$USER/platforms
     49 register_var_option "--src-dir=<path>" SRCDIR "Specify source platforms directory"
     50 
     51 DSTDIR=/tmp/ndk-$USER/platforms-compressed
     52 register_var_option "--dst-dir=<path>" DSTDIR "Specify destination directory"
     53 
     54 API_LEVELS=$(spaces_to_commas $API_LEVELS)
     55 register_var_option "--platforms=<list>" API_LEVELS "Specify all API levels"
     56 
     57 extract_parameters "$@"
     58 
     59 API_LEVELS=$(commas_to_spaces $API_LEVELS)
     60 
     61 # Sanity check
     62 for PLATFORM in $API_LEVELS; do
     63     SDIR=$SRCDIR/android-$PLATFORM
     64     if [ ! -d "$SDIR" ]; then
     65         echo "ERROR: Missing source platform directory: $SDIR"
     66         exit 1
     67     fi
     68 done
     69 
     70 # Let's roll
     71 PREV_PLATFORM=
     72 for PLATFORM in $API_LEVELS; do
     73     SDIR=$SRCDIR/android-$PLATFORM
     74     DDIR=$DSTDIR/android-$PLATFORM
     75     if [ -z "$PREV_PLATFORM" ]; then
     76         # Copy everything here
     77         log "Copying directory: $SDIR --> $DDIR"
     78         copy_directory "$SDIR" "$DDIR"
     79     else
     80         # For each file, check whether it is new or
     81         # different from the one in the previous platform level
     82         log "Compressing directory: $SDIR"
     83         PDIR=$SRCDIR/android-$PREV_PLATFORM
     84         FILES=$(cd $SDIR && find . -type f)
     85         if [ "$VERBOSE2" = "yes" ]; then
     86             echo "Files found:"
     87             echo "$FILES" | tr ' ' '\n'
     88         fi
     89         for FILENAME in $FILES; do
     90             FILENAME=${FILENAME##./}  # Get rid of leading ./
     91             PFILE=$PDIR/$FILENAME
     92             CFILE=$SDIR/$FILENAME
     93             DFILE=$DDIR/$FILENAME
     94             if [ -f "$PFILE" ]; then
     95                 log2 "Comparing $CFILE with $PFILE"
     96                 if cmp --quiet $PFILE $CFILE; then
     97                     # Files are identical, remove it from destination
     98                     # if it exists there, it's not longer relevant.
     99                     if [ -f "$DFILE" ]; then
    100                         log2 "Removing obsolete $DFILE"
    101                         rm -f $DFILE
    102                     else
    103                         log2 "Skipping $CFILE"
    104                     fi
    105                     continue
    106                 fi
    107             fi
    108             # New or modified file, copy it
    109             DFILE=$DDIR/$FILENAME
    110             log2 "Copying $SFILE --> $DFILE"
    111             mkdir -p $(dirname "$DFILE") && cp $CFILE $DFILE
    112             fail_panic "Could not copy $CFILE to $DFILE"
    113         done
    114     fi
    115     PREV_PLATFORM=$PLATFORM
    116 done
    117 
    118 log "Done!"
    119 exit 0
    120