Home | History | Annotate | Download | only in short-commands
      1 # Special script used to check that LOCAL_SHORT_COMMANDS works
      2 # correctly even when using a very large number of source files
      3 # when building a static or shared library.
      4 #
      5 # We're going to auto-generate all the files we need in a
      6 # temporary directory, because that's how we roll.
      7 #
      8 
      9 PROGDIR=$(dirname $0)
     10 PROGDIR=$(cd "$PROGDIR" && pwd)
     11 
     12 # TODO: Increment this to 1000 for long test runs. For the simple unit test
     13 #        suite, keep this just over 100
     14 #
     15 COUNT=110
     16 
     17 # Generate all our source files
     18 NUM=0
     19 
     20 SRCDIR=$PROGDIR/jni
     21 rm -rf "$SRCDIR" && mkdir -p "$SRCDIR"
     22 if [ $? != 0 ]; then
     23     echo "ERROR: Could not create temporary source directory: $SRCDIR"
     24     exit 1
     25 fi
     26 
     27 CLEAN_FILES=
     28 
     29 generate_source_files ()
     30 {
     31     # Generate all temporary source files we need
     32     local NUM=0
     33     while [ $NUM -lt $COUNT ]; do
     34         SRCFILE=$SRCDIR/foo$NUM.c
     35     cat > $SRCFILE <<EOF
     36 int foo$NUM (int x)
     37 {
     38     return x + 1;
     39 }
     40 EOF
     41         NUM=$(( $NUM + 1 ))
     42         CLEAN_FILES=$CLEAN_FILES" $SRCFILE"
     43     done
     44 }
     45 
     46 generate_main_file ()
     47 {
     48     cat > $SRCDIR/main.c <<EOF
     49 #include <stdio.h>
     50 EOF
     51     NUM=0
     52     while [ $NUM -lt $COUNT ]; do
     53         cat >> $SRCDIR/main.c <<EOF
     54 extern int foo$NUM (int);
     55 EOF
     56         NUM=$(( $NUM + 1 ))
     57     done
     58     cat >> $SRCDIR/main.c <<EOF
     59 int main(void)
     60 {
     61     int x = 0;
     62 EOF
     63     NUM=0
     64     while [ $NUM -lt $COUNT ]; do
     65         cat >> $SRCDIR/main.c <<EOF
     66     x = foo$NUM(x);
     67 EOF
     68         NUM=$(( $NUM + 1 ))
     69     done
     70 cat >> $SRCDIR/main.c <<EOF
     71     return 0;
     72 }
     73 EOF
     74     CLEAN_FILES=$CLEAN_FILES" $SRCDIR/main.c"
     75 }
     76 
     77 generate_build_file ()
     78 {
     79     local NUM
     80 
     81     # Generate the Android.mk
     82     cat > $SRCDIR/Android.mk <<EOF
     83 # Auto-generated - do not edit
     84 LOCAL_PATH := \$(call my-dir)
     85 EOF
     86 
     87     # First, build a huge static library with all the files
     88     cat >> $SRCDIR/Android.mk <<EOF
     89 include \$(CLEAR_VARS)
     90 LOCAL_MODULE := libfoo_big
     91 EOF
     92 
     93     NUM=0
     94     while [ $NUM -lt $COUNT ]; do
     95         cat >> $SRCDIR/Android.mk <<EOF
     96 LOCAL_SRC_FILES += foo$NUM.c
     97 EOF
     98         NUM=$(( $NUM + 1 ))
     99     done
    100 
    101     cat >> $SRCDIR/Android.mk <<EOF
    102 LOCAL_SHORT_COMMANDS := true
    103 include \$(BUILD_SHARED_LIBRARY)
    104 EOF
    105 
    106     # Second, generate a large number of static libraries
    107     # Then an executable that use them all
    108     NUM=0
    109     while [ $NUM -lt $COUNT ]; do
    110         cat >> $SRCDIR/Android.mk <<EOF
    111 include \$(CLEAR_VARS)
    112 LOCAL_MODULE := foo$NUM
    113 LOCAL_SRC_FILES := foo$NUM.c
    114 include \$(BUILD_STATIC_LIBRARY)
    115 EOF
    116         NUM=$(( $NUM + 1 ))
    117     done
    118 
    119         cat >> $SRCDIR/Android.mk <<EOF
    120 include \$(CLEAR_VARS)
    121 LOCAL_MODULE := test_linker_options_list
    122 LOCAL_SRC_FILES := main.c
    123 EOF
    124 
    125     NUM=0
    126     while [ $NUM -lt $COUNT ]; do
    127         cat >> $SRCDIR/Android.mk <<EOF
    128 LOCAL_WHOLE_STATIC_LIBRARIES += foo$NUM
    129 EOF
    130         NUM=$(( $NUM + 1 ))
    131     done
    132 
    133     cat >> $SRCDIR/Android.mk <<EOF
    134 #LOCAL_SHORT_COMMANDS := true
    135 include \$(BUILD_EXECUTABLE)
    136 EOF
    137     CLEAN_FILES=$CLEAN_FILES" $SRCDIR/Android.mk"
    138 }
    139 
    140 generate_source_files && 
    141 generate_main_file &&
    142 generate_build_file
    143 if [ $? != 0 ]; then
    144     echo "ERROR: Could not generate files for this test!"
    145     exit 1
    146 fi
    147 
    148 # Now run the build
    149 $NDK/ndk-build -C "$PROGDIR" "$@"
    150 RET=$?
    151 
    152 # Clean everything we generated
    153 rm -f $CLEAN_FILES
    154 rm -rf "$PROGDIR/obj" "$PROGDIR/libs"
    155 
    156 # Exit
    157 exit $RET
    158