CPP: Fix bug in installation step and add test to the continuous integration script.
authorphilip.liard@gmail.com <philip.liard@gmail.com@ee073f10-1060-11df-b6a4-87a95322a99c>
Wed, 17 Aug 2011 10:14:24 +0000 (10:14 +0000)
committerphilip.liard@gmail.com <philip.liard@gmail.com@ee073f10-1060-11df-b6a4-87a95322a99c>
Wed, 17 Aug 2011 10:14:24 +0000 (10:14 +0000)
git-svn-id: http://libphonenumber.googlecode.com/svn/trunk@335 ee073f10-1060-11df-b6a4-87a95322a99c

cpp/CMakeLists.txt
tools/script/continuous-integration.sh

index 4aecdc3..4cda515 100644 (file)
@@ -313,10 +313,12 @@ install (FILES
 
 install (FILES
   "src/base/basictypes.h"
-  "src/base/memory/singleton.h"
   "src/base/scoped_ptr.h"
   DESTINATION include/base/
 )
+install (FILES src/base/memory/singleton.h
+         DESTINATION include/base/memory)
+
 install (FILES src/base/synchronization/lock.h
          DESTINATION include/base/synchronization)
 
index 81efebb..212b4b3 100755 (executable)
 (find resources/geocoding -type f | xargs file | egrep -v 'UTF-8|ASCII') && exit 1
 
 # Test the C++ version with the provided CMake parameter.
+CXX=g++
+INSTALL_PREFIX=/tmp/libphonenumber
+
 test_cpp_version() {
+  CC_TEST_FILE=`mktemp`.cc
+  CC_TEST_BINARY=`mktemp`
   CMAKE_FLAGS="$1"
+  # Write the program that tests the installation of the library to a temporary
+  # source file.
+  > $CC_TEST_FILE echo '
+    #include <cassert>
+    #include <phonenumbers/phonenumberutil.h>
+    using i18n::phonenumbers::PhoneNumberUtil;
+    int main() {
+      PhoneNumberUtil* const phone_util = PhoneNumberUtil::GetInstance();
+      return phone_util == NULL;
+    }'
+  # Run the build and tests.
   (
-    rm -rf cpp/build && mkdir cpp/build && cd cpp/build && \
-        cmake "${CMAKE_FLAGS}" .. && make && ./libphonenumber_test
-  ) || exit $?
+    rm -rf cpp/build /tmp/libphonenumber &&
+    mkdir cpp/build /tmp/libphonenumber && cd cpp/build &&
+    cmake "${CMAKE_FLAGS}" -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX .. &&
+    make && ./libphonenumber_test && make install &&
+    $CXX -o $CC_TEST_BINARY $CC_TEST_FILE -I${INSTALL_PREFIX}/include \
+        -lboost_thread -L${INSTALL_PREFIX}/lib -lphonenumber &&
+    $CC_TEST_BINARY
+  )
+  STATUS=$?
+  # Remove the temporary files.
+  rm -f $CC_TEST_FILE
+  rm -f $CC_TEST_BINARY
+
+  [ $STATUS -ne 0 ] && exit $STATUS
 }
 test_cpp_version ''
 test_cpp_version '-DUSE_RE2=ON'