This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathsquidb-ios-tests.sh
executable file
·145 lines (126 loc) · 5.56 KB
/
squidb-ios-tests.sh
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/zsh
if [ ! -f "${J2OBJC_HOME}/j2objc" ]; then echo "J2OBJC_HOME not correctly defined, currently set to '${J2OBJC_HOME}'"; exit 1; fi;
BUILD_DIR="build/ios-tests"
# clean up build directories
if [ -d $BUILD_DIR ]; then rm -r $BUILD_DIR; fi;
if [ -f run_squidb_ios_tests ]; then rm run_squidb_ios_tests; fi;
mkdir -p $BUILD_DIR
BIN="$BUILD_DIR/bin"; mkdir $BIN;
INTERMEDIATE="$BUILD_DIR/intermediate"; mkdir $INTERMEDIATE;
GEN="$BUILD_DIR/gen"; mkdir $GEN;
SQUIDB_SRC="squidb/src"
SQUIDB_ANNOTATIONS_SRC="squidb-annotations/src"
SQUIDB_JSON_SRC="squidb-addons/squidb-json/squidb-json-plugin/src"
SQUIDB_JSON_ANNOTATIONS_SRC="squidb-addons/squidb-json/squidb-json-annotations/src"
SQUIDB_IOS_SRC="squidb-ios/src"
SQUIDB_IOS_NATIVE="squidb-ios/native"
SQUIDB_IOS_TESTS="squidb-ios-tests"
SQUIDB_IOS_TESTS_SRC="$SQUIDB_IOS_TESTS/src"
SQUIDB_TESTS_ROOT="squidb-tests/src"
SQUIDB_TESTS_SRC="squidb-tests/src/com/yahoo/squidb"
SQUIDB_TESTS_DATA_SRC="${SQUIDB_TESTS_SRC}/data"
SQUIDB_TESTS_SQL_SRC="${SQUIDB_TESTS_SRC}/sql"
SQUIDB_TESTS_TEST_SRC="${SQUIDB_TESTS_SRC}/test"
SQUIDB_TESTS_UTILITY_SRC="${SQUIDB_TESTS_SRC}/utility"
SOURCEPATH="${GEN}:${SQUIDB_SRC}:${SQUIDB_ANNOTATIONS_SRC}:${SQUIDB_JSON_SRC}:${SQUIDB_JSON_ANNOTATIONS_SRC}:${SQUIDB_IOS_SRC}:${SQUIDB_IOS_TESTS_SRC}:${SQUIDB_TESTS_ROOT}"
#echo ${SOURCEPATH}
function buildTestExecutable () {
${J2OBJC_HOME}/j2objcc -L${J2OBJC_HOME}/lib/macosx "${LINK_ARGS[@]}" -ObjC -o run_squidb_ios_tests $BIN/*.o # link with libraries
linkerResult=$?
if [ ! $linkerResult -eq 0 ]
then
echo "Linker failed with error code $linkerResult"
exit $linkerResult
fi
}
function runTests () {
./run_squidb_ios_tests
testResults=$?
rm run_squidb_ios_tests
if [ ! $testResults -eq 0 ]
then
echo "Unit test failures, exiting with code $testResults"
exit $testResults
fi
}
function downloadSQLiteAmalgamation () {
SQLITE_VERSION="sqlite-amalgamation-3150000"
echo "Downloading $SQLITE_VERSION"
rm -rf $SQUIDB_IOS_NATIVE/sqlite
mkdir $SQUIDB_IOS_NATIVE/sqlite
if [ -z "$CI_IOS_TESTS" ] # local build
then
DESTINATION=$SQUIDB_IOS_NATIVE/sqlite
else
DESTINATION=/tmp
fi
wget https://www.sqlite.org/2016/$SQLITE_VERSION.zip -O $DESTINATION/$SQLITE_VERSION.zip
unzip -oq $DESTINATION/$SQLITE_VERSION.zip -d $DESTINATION
mv $DESTINATION/$SQLITE_VERSION/sqlite3.c $SQUIDB_IOS_NATIVE/sqlite
mv $DESTINATION/$SQLITE_VERSION/sqlite3.h $SQUIDB_IOS_NATIVE/sqlite
}
# Build annotation and processor jars
if [ -z "$CI_IOS_TESTS" ] # only build annotation processors from scratch when not on CI
then
./gradlew squidb-annotations:jar squidb-processor:jar squidb-json-annotations:jar squidb-json-compiler:jar
for f in squidb-annotations/build/libs/*.jar squidb-processor/build/libs/*.jar squidb-addons/squidb-json/squidb-json-annotations/build/libs/*.jar squidb-addons/squidb-json/squidb-json-compiler/build/libs/*.jar
do
rsync -rc -t $f $SQUIDB_IOS_TESTS
done
rm $SQUIDB_IOS_TESTS/*-javadoc.jar
rm $SQUIDB_IOS_TESTS/*-sources.jar
fi
# invoke annotation processing, output to gen folder
javac -classpath "${J2OBJC_HOME}/lib/j2objc_junit.jar:$SQUIDB_IOS_TESTS/*" \
-s $GEN -proc:only -AsquidbPlugins=com.yahoo.squidb.json.JSONPlugin -sourcepath "${SOURCEPATH}" ${SQUIDB_TESTS_TEST_SRC}/**/*.java
javacResult=$?
if [ ! $javacResult -eq 0 ]
then
echo "javac exited with error code $javacResult"
exit $javacResult
fi
# invoke j2objc to translate java sources
${J2OBJC_HOME}/j2objc -classpath "${J2OBJC_HOME}/lib/j2objc_junit.jar:${J2OBJC_HOME}/lib/jre_emul.jar" -d $INTERMEDIATE \
--no-package-directories -use-arc -sourcepath "${SOURCEPATH}" \
${SQUIDB_SRC}/**/*.java ${SQUIDB_IOS_SRC}/**/*.java ${SQUIDB_JSON_SRC}/**/*.java ${SQUIDB_JSON_ANNOTATIONS_SRC}/**/*.java \
${SQUIDB_TESTS_TEST_SRC}/*.java ${GEN}/**/*.java ${SQUIDB_IOS_TESTS_SRC}/**/*.java ${SQUIDB_TESTS_DATA_SRC}/*.java \
${SQUIDB_TESTS_SQL_SRC}/*.java ${SQUIDB_TESTS_UTILITY_SRC}/*.java
j2objcResult=$?
if [ ! $j2objcResult -eq 0 ]
then
echo "j2objc exited with code $j2objcResult"
exit $j2objcResult
fi
# compile translated Obj-C sources
for f in squidb-ios/native/**/*.m $INTERMEDIATE/*.m ${SQUIDB_IOS_TESTS_SRC}/**/*.m
do
echo "Compiling $f"
# output .o file to bin folder
${J2OBJC_HOME}/j2objcc -fobjc-arc -I$INTERMEDIATE -I$SQUIDB_IOS_NATIVE -I$SQUIDB_IOS_NATIVE/sqlite -o "$BIN/${$(basename $f)%.*}.o" -c $f
j2objccResult=$?
if [ ! $j2objccResult -eq 0 ]
then
echo "j2objcc failed to compile $f, exiting with code $j2objccResult"
exit $j2objccResult
fi
done
# When using the -ObjC flag, the -ljre_core, -ljre_util, and -ljre_concurrent flags are the ones SquiDB requires.
# If not using the flag, it should be safe to use -ljre_emul, because unused symbols will be stripped
# the android_util lib is used for testing json functions using the org.json package, and in turn requires jre_net
LINK_ARGS_BASE=(-ljre_core -ljre_util -ljre_concurrent -ljunit -landroid_util -ljre_net)
LINK_ARGS_SQLITE=("${LINK_ARGS_BASE[@]}")
LINK_ARGS_SQLITE+=(-lsqlite3)
echo "Building test executable for default SQLite"
LINK_ARGS=("${LINK_ARGS_SQLITE[@]}")
buildTestExecutable
runTests
echo "Building test executable for custom built SQLite"
downloadSQLiteAmalgamation
f=$SQUIDB_IOS_NATIVE/sqlite/sqlite3.c
echo "Compiling $f"
gcc -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_JSON1 -DSQLITE_TEMP_STORE=3 -DHAVE_STRCHRNUL=0 \
-I$SQUIDB_IOS_NATIVE/sqlite -o "$BIN/${$(basename $f)%.*}.o" -c $f
LINK_ARGS=("${LINK_ARGS_BASE[@]}")
buildTestExecutable
runTests
exit 0