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=$TMPDIR/platforms
     49 register_var_option "--src-dir=<path>" SRCDIR "Specify source platforms directory"
     50 
     51 DSTDIR=$TMPDIR/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         echo "Files found:"
     86         echo "$FILES" | tr ' ' '\n'
     87         for FILENAME in $FILES; do
     88             FILENAME=${FILENAME##./}  # Get rid of leading ./
     89             PFILE=$PDIR/$FILENAME
     90             CFILE=$SDIR/$FILENAME
     91             DFILE=$DDIR/$FILENAME
     92             if [ -f "$PFILE" ]; then
     93                 log "Comparing $CFILE with $PFILE"
     94                 if cmp --quiet $PFILE $CFILE; then
     95                     # Files are identical, remove it from destination
     96                     # if it exists there, it's not longer relevant.
     97                     if [ -f "$DFILE" ]; then
     98                         log "Removing obsolete $DFILE"
     99                         rm -f $DFILE
    100                     else
    101                         log "Skipping $CFILE"
    102                     fi
    103                     continue
    104                 fi
    105             fi
    106             # New or modified file, copy it
    107             DFILE=$DDIR/$FILENAME
    108             log "Copying $SFILE --> $DFILE"
    109             mkdir -p $(dirname "$DFILE") && cp $CFILE $DFILE
    110             fail_panic "Could not copy $CFILE to $DFILE"
    111         done
    112     fi
    113     PREV_PLATFORM=$PLATFORM
    114 done
    115 
    116 log "Done!"
    117 exit 0
    118