From 6d079c1421885038d14a1f65e71c010836b6c94c Mon Sep 17 00:00:00 2001 From: Hans Fugal Date: Thu, 8 Jan 2015 14:49:01 -0800 Subject: [PATCH] (folly) make check on OSX Yosemite (10.10) Summary: This switches from gcc-4.9 provided by Homebrew to the default g++ (clang) from Yosemite. $ g++ --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.0.0 Thread model: posix Absolute path for double-conversion, so make in `test/` works. gtest-1.7.0 (Using 1.6.0 causes compilation errors in Yosemite) Various portability fixes. Enhancements/fixes to `configure.ac` and associated source code for better portability. Test Plan: It builds and runs (yay) Two tests fail, not sure whether that's specific to osx. Will investigate and make any fixes in a follow-up diff Reviewed By: pgriess@fb.com Subscribers: trunkagent, folly-diffs@, exa FB internal diff: D1768669 Tasks: 5936226 Signature: t1:1768669:1420728580:dd6919c21e0edf30788e523b16e3a5b923e2d7f0 --- folly/Conv.h | 5 +++++ folly/SpinLock.h | 2 +- folly/bootstrap-osx-homebrew.sh | 15 +++++++++++---- folly/configure.ac | 7 +++---- folly/detail/SpinLockImpl.h | 4 ++-- folly/detail/ThreadLocalDetail.h | 12 ++++++++---- folly/test/.gitignore | 2 ++ folly/test/Makefile.am | 12 ++++++------ folly/test/SpinLockTest.cpp | 2 +- folly/test/sorted_vector_test.cpp | 2 +- 10 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 folly/test/.gitignore diff --git a/folly/Conv.h b/folly/Conv.h index 4d6fb0dd..5a196463 100644 --- a/folly/Conv.h +++ b/folly/Conv.h @@ -658,6 +658,11 @@ struct HasLengthEstimator : std::false_type {}; template constexpr typename std::enable_if< !std::is_fundamental::value +#ifdef FOLLY_HAVE_INT128_T + // On OSX 10.10, is_fundamental<__int128> is false :-O + && !std::is_same<__int128, Src>::value + && !std::is_same::value +#endif && !IsSomeString::value && !std::is_convertible::value && !std::is_convertible::value diff --git a/folly/SpinLock.h b/folly/SpinLock.h index ac6ed35b..2e2356c9 100644 --- a/folly/SpinLock.h +++ b/folly/SpinLock.h @@ -24,7 +24,7 @@ namespace folly { typedef SpinLockMslImpl SpinLock; #elif __APPLE__ typedef SpinLockAppleImpl SpinLock; -#elif __ANDROID__ +#elif FOLLY_HAVE_PTHREAD_SPINLOCK_T typedef SpinLockPthreadMutexImpl SpinLock; #else typedef SpinLockPthreadImpl SpinLock; diff --git a/folly/bootstrap-osx-homebrew.sh b/folly/bootstrap-osx-homebrew.sh index 6565f4b6..da1f73ed 100755 --- a/folly/bootstrap-osx-homebrew.sh +++ b/folly/bootstrap-osx-homebrew.sh @@ -9,8 +9,8 @@ brewget() { brew install $@ || brew upgrade $@ } -# tool dependencies: autotools, scons (for double-conversion), and gcc 4.9 -brewget autoconf automake libtool scons gcc +# tool dependencies: autotools and scons (for double-conversion) +brewget autoconf automake libtool scons # dependencies brewget glog gflags boost libevent @@ -18,7 +18,6 @@ brewget glog gflags boost libevent # Install the double-conversion library. # NB their install target installs the libs but not the headers, hence the # CPPFLAGS and link shenanigans. -DOUBLE_CONVERSION_CPPFLAGS="-I./double-conversion/src" test -d double-conversion || { git clone https://github.com/floitsch/double-conversion.git pushd double-conversion/src @@ -31,7 +30,15 @@ scons # (this won't work if you've already installed libdouble-conversion into a # default search path) rm -f libdouble-conversion*dylib +DOUBLE_CONVERSION_HOME=$(pwd) popd autoreconf -i -./configure CPPFLAGS="-I./double-conversion/src" LDFLAGS="-L./double-conversion" CXX=g++-4.9 +./configure CPPFLAGS=-I"$DOUBLE_CONVERSION_HOME/src" LDFLAGS=-L"$DOUBLE_CONVERSION_HOME" + +pushd test +test -d gtest-1.7.0 || { + curl -O https://googletest.googlecode.com/files/gtest-1.7.0.zip + unzip gtest-1.7.0.zip +} +popd diff --git a/folly/configure.ac b/folly/configure.ac index 3f66657c..5c2aa81f 100644 --- a/folly/configure.ac +++ b/folly/configure.ac @@ -92,10 +92,8 @@ AC_C_INLINE AC_TYPE_SIZE_T AC_HEADER_TIME AC_C_VOLATILE -AC_CHECK_TYPE([__int128], - [AC_DEFINE([HAVE_INT128_T], [1], [Define if __int128 exists])], - [AC_DEFINE([HAVE_INT128_T], [0], [Define if __int128 does not exist])]) -AC_CHECK_TYPES([ptrdiff_t]) +AC_CHECK_TYPE([__int128], AC_DEFINE([HAVE_INT128_T], [1], [Define if we have __int128])) +AC_CHECK_TYPES([ptrdiff_t, pthread_spinlock_t]) AC_CACHE_CHECK( [for ifunc support], @@ -274,6 +272,7 @@ AC_CHECK_FUNCS([getdelim \ pow \ strerror \ pthread_yield \ + pthread_atfork \ malloc_size \ malloc_usable_size \ memrchr \ diff --git a/folly/detail/SpinLockImpl.h b/folly/detail/SpinLockImpl.h index 1d65add9..f1f4e06e 100644 --- a/folly/detail/SpinLockImpl.h +++ b/folly/detail/SpinLockImpl.h @@ -84,7 +84,7 @@ class SpinLockAppleImpl { #include #include -#if !__ANDROID__ && !__APPLE__ +#if FOLLY_HAVE_PTHREAD_SPINLOCK_T // Apple and Android systems don't have pthread_spinlock_t, so we can't support // this version on those platforms. @@ -122,7 +122,7 @@ class SpinLockPthreadImpl { } -#endif // !__ANDROID__ && !__APPLE__ +#endif // FOLLY_HAVE_PTHREAD_SPINLOCK_T namespace folly { diff --git a/folly/detail/ThreadLocalDetail.h b/folly/detail/ThreadLocalDetail.h index 4f08acd5..283e1dfc 100644 --- a/folly/detail/ThreadLocalDetail.h +++ b/folly/detail/ThreadLocalDetail.h @@ -207,14 +207,18 @@ struct StaticMeta { int ret = pthread_key_create(&pthreadKey_, &onThreadExit); checkPosixError(ret, "pthread_key_create failed"); - // pthread_atfork is not part of the Android NDK at least as of n9d. If - // something is trying to call native fork() directly at all with Android's - // process management model, this is probably the least of the problems. -#if !__ANDROID__ +#if FOLLY_HAVE_PTHREAD_ATFORK ret = pthread_atfork(/*prepare*/ &StaticMeta::preFork, /*parent*/ &StaticMeta::onForkParent, /*child*/ &StaticMeta::onForkChild); checkPosixError(ret, "pthread_atfork failed"); +#elif !__ANDROID__ + // pthread_atfork is not part of the Android NDK at least as of n9d. If + // something is trying to call native fork() directly at all with Android's + // process management model, this is probably the least of the problems. + // + // But otherwise, this is a problem. + #warning pthread_atfork unavailable #endif } ~StaticMeta() { diff --git a/folly/test/.gitignore b/folly/test/.gitignore new file mode 100644 index 00000000..7e563b8b --- /dev/null +++ b/folly/test/.gitignore @@ -0,0 +1,2 @@ +*.log +*.trs diff --git a/folly/test/Makefile.am b/folly/test/Makefile.am index 6dfd6e61..85eee0db 100644 --- a/folly/test/Makefile.am +++ b/folly/test/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS = . function_benchmark ACLOCAL_AMFLAGS = -I m4 -CPPFLAGS += -Igtest-1.6.0/include +CPPFLAGS += -Igtest-1.7.0/include TESTS= \ sorted_vector_types_test \ @@ -17,11 +17,11 @@ TESTS= \ check_LTLIBRARIES = libgtestmain.la libgtest.la check_PROGRAMS = -libgtestmain_la_CPPFLAGS = -Igtest-1.6.0 -Igtest-1.6.0/src -libgtestmain_la_SOURCES = gtest-1.6.0/src/gtest-all.cc gtest-1.6.0/src/gtest_main.cc +libgtestmain_la_CPPFLAGS = -Igtest-1.7.0 -Igtest-1.7.0/src +libgtestmain_la_SOURCES = gtest-1.7.0/src/gtest-all.cc gtest-1.7.0/src/gtest_main.cc -libgtest_la_CPPFLAGS = -Igtest-1.6.0 -Igtest-1.6.0/src -libgtest_la_SOURCES = gtest-1.6.0/src/gtest-all.cc +libgtest_la_CPPFLAGS = -Igtest-1.7.0 -Igtest-1.7.0/src +libgtest_la_SOURCES = gtest-1.7.0/src/gtest-all.cc noinst_HEADERS = FBStringTestBenchmarks.cpp.h \ FBVectorTestBenchmarks.cpp.h @@ -127,7 +127,7 @@ concurrent_skiplist_test_LDADD = libgtest.la $(top_builddir)/libfolly.la TESTS += concurrent_skiplist_test concurrent_skiplist_benchmark_SOURCES = ConcurrentSkipListBenchmark.cpp -concurrent_skiplist_benchmark_LDADD = $(top_builddir)/libfollybenchmark.la $(top_builddir)/libfolly.la +concurrent_skiplist_benchmark_LDADD = libgtestmain.la $(top_builddir)/libfollybenchmark.la $(top_builddir)/libfolly.la check_PROGRAMS += concurrent_skiplist_benchmark histogram_test_SOURCES = HistogramTest.cpp diff --git a/folly/test/SpinLockTest.cpp b/folly/test/SpinLockTest.cpp index 847efcf5..7ce90d71 100644 --- a/folly/test/SpinLockTest.cpp +++ b/folly/test/SpinLockTest.cpp @@ -146,7 +146,7 @@ TEST(SpinLock, AppleTryLock) { } #endif -#if !__ANDROID__ +#if FOLLY_HAVE_PTHREAD_SPINLOCK_T TEST(SpinLock, PthreadCorrectness) { correctnessTest(); } diff --git a/folly/test/sorted_vector_test.cpp b/folly/test/sorted_vector_test.cpp index ca806aa0..2b75a520 100644 --- a/folly/test/sorted_vector_test.cpp +++ b/folly/test/sorted_vector_test.cpp @@ -207,7 +207,7 @@ TEST(SortedVectorTypes, Sizes) { typedef sorted_vector_set, std::allocator,OneAtATimePolicy> SetT; typedef sorted_vector_map, - std::allocator,OneAtATimePolicy> MapT; + std::allocator>,OneAtATimePolicy> MapT; EXPECT_EQ(sizeof(SetT), sizeof(std::vector)); EXPECT_EQ(sizeof(MapT), sizeof(std::vector >)); -- 2.34.1