You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2012/08/11 15:07:20 UTC

svn commit: r1371942 - in /subversion/trunk: aclocal.m4 build/ac-macros/macosx.m4 configure.ac subversion/libsvn_subr/sysinfo.c

Author: brane
Date: Sat Aug 11 13:07:19 2012
New Revision: 1371942

URL: http://svn.apache.org/viewvc?rev=1371942&view=rev
Log:
Display Mac OS release name with svn --version --verbose.

* configure.ac: Remove KeyChain test to build/ac-macros/macosx.m4.
* aclocal.m4: Include build/ac-macros/macosx.m4.
* build/ac-macros/macosx.m4: New file.
  (SVN_LIB_MACOS_PLIST): New. Check for Mac OS property list utilities.
  (SVN_LIB_MACOS_KEYCHAIN): New. Implementation moved from configure.ac.
  Don't check anything if SVN_LIB_MACOS_PLIST failed.

* subversion/libsvn_subr/sysinfo.c: Include apr_strings.h.
  [SVN_HAVE_MACOS_PLIST]: Include CoreFoundation/CoreFoundation.h.
  (svn_sysinfo__release_name): Conditionionally call macos_release_name.
  (system_version_plist, value_from_dict,
   release_name_from_version, macos_release_name): New, conditional.

Added:
    subversion/trunk/build/ac-macros/macosx.m4
Modified:
    subversion/trunk/aclocal.m4
    subversion/trunk/configure.ac
    subversion/trunk/subversion/libsvn_subr/sysinfo.c

Modified: subversion/trunk/aclocal.m4
URL: http://svn.apache.org/viewvc/subversion/trunk/aclocal.m4?rev=1371942&r1=1371941&r2=1371942&view=diff
==============================================================================
--- subversion/trunk/aclocal.m4 (original)
+++ subversion/trunk/aclocal.m4 Sat Aug 11 13:07:19 2012
@@ -46,6 +46,7 @@ sinclude(build/ac-macros/sqlite.m4)
 sinclude(build/ac-macros/swig.m4)
 sinclude(build/ac-macros/zlib.m4)
 sinclude(build/ac-macros/kwallet.m4)
+sinclude(build/ac-macros/macosx.m4)
 
 # Include the libtool macros
 sinclude(build/libtool.m4)

Added: subversion/trunk/build/ac-macros/macosx.m4
URL: http://svn.apache.org/viewvc/subversion/trunk/build/ac-macros/macosx.m4?rev=1371942&view=auto
==============================================================================
--- subversion/trunk/build/ac-macros/macosx.m4 (added)
+++ subversion/trunk/build/ac-macros/macosx.m4 Sat Aug 11 13:07:19 2012
@@ -0,0 +1,93 @@
+dnl ===================================================================
+dnl   Licensed to the Apache Software Foundation (ASF) under one
+dnl   or more contributor license agreements.  See the NOTICE file
+dnl   distributed with this work for additional information
+dnl   regarding copyright ownership.  The ASF licenses this file
+dnl   to you under the Apache License, Version 2.0 (the
+dnl   "License"); you may not use this file except in compliance
+dnl   with the License.  You may obtain a copy of the License at
+dnl
+dnl     http://www.apache.org/licenses/LICENSE-2.0
+dnl
+dnl   Unless required by applicable law or agreed to in writing,
+dnl   software distributed under the License is distributed on an
+dnl   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+dnl   KIND, either express or implied.  See the License for the
+dnl   specific language governing permissions and limitations
+dnl   under the License.
+dnl ===================================================================
+dnl
+dnl  Mac OS X specific checks
+
+dnl SVN_LIB_MACOS_PLIST
+dnl Assign variables for Mac OS property list support
+AC_DEFUN(SVN_LIB_MACOS_PLIST,
+[
+  AC_MSG_CHECKING([for Mac OS property list utilities])
+
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+    #include <AvailabilityMacros.h>
+    #if !DARWIN || (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_0)
+    #error ProperyList API unavailable.
+    #endif
+  ]],[[]])],[have_macos_plist=yes],[have_macos_plist=no])
+
+  if test "$have_macos_plist" = "yes"; then
+    dnl ### Hack.  We should only need to pass the -framework options when
+    dnl linking libsvn_subr, since it is the only library that uses Keychain.
+    dnl
+    dnl Unfortunately, libtool 1.5.x doesn't track transitive dependencies for
+    dnl OS X frameworks like it does for normal libraries, so we need to
+    dnl explicitly pass the option to all the users of libsvn_subr to allow
+    dnl static builds to link successfully.
+    dnl
+    dnl This does mean that all executables we link will be linked directly
+    dnl to these frameworks - even when building shared libraries - but that
+    dnl shouldn't cause any problems.
+
+    LIBS="$LIBS -framework CoreFoundation"
+    AC_DEFINE([SVN_HAVE_MACOS_PLIST], [1],
+              [Is Mac OS property list API available?])
+    AC_MSG_RESULT([yes])
+  else
+    AC_MSG_RESULT([no])
+  fi
+])
+
+dnl SVN_LIB_MACOS_KEYCHAIN
+dnl Check configure options and assign variables related to Keychain support
+
+AC_DEFUN(SVN_LIB_MACOS_KEYCHAIN,
+[
+  AC_ARG_ENABLE(keychain,
+    AS_HELP_STRING([--disable-keychain],
+    [Disable use of Mac OS KeyChain for auth credentials]),
+    [enable_keychain=$enableval],[enable_keychain=yes])
+
+  AC_MSG_CHECKING([for Mac OS KeyChain Services])
+
+  if test "$have_macos_plist" != "yes"; then
+    dnl There's no sense in checking for KeyChain if plists are not available
+    enable_keychain=no
+    AC_MSG_RESULT([no])
+  else
+    if test "$enable_keychain" = "yes"; then
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        #include <AvailabilityMacros.h>
+        #if !DARWIN || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_2)
+        #error KeyChain API unavailable.
+        #endif
+      ]],[[]])],[],[enable_keychain=no])
+    fi
+
+    if test "$enable_keychain" = "yes"; then
+      dnl ### Hack, see SVN_LIB_MACOS_PLIST
+      LIBS="$LIBS -framework Security"
+      LIBS="$LIBS -framework CoreServices"
+      AC_DEFINE([SVN_HAVE_KEYCHAIN_SERVICES], [1], [Is Mac OS KeyChain support enabled?])
+      AC_MSG_RESULT([yes])
+    else
+      AC_MSG_RESULT([no])
+    fi
+  fi
+])

Modified: subversion/trunk/configure.ac
URL: http://svn.apache.org/viewvc/subversion/trunk/configure.ac?rev=1371942&r1=1371941&r2=1371942&view=diff
==============================================================================
--- subversion/trunk/configure.ac (original)
+++ subversion/trunk/configure.ac Sat Aug 11 13:07:19 2012
@@ -477,43 +477,10 @@ if test "$svn_lib_sasl" = "yes"; then
             [Defined if Cyrus SASL v2 is present on the system])
 fi
 
-dnl Mac OS KeyChain -------------------
-
-AC_ARG_ENABLE(keychain,
-  AS_HELP_STRING([--disable-keychain], 
-  [Disable use of Mac OS KeyChain for auth credentials]),
-  [enable_keychain=$enableval],[enable_keychain=yes])
-
-AC_MSG_CHECKING([for Mac OS KeyChain Services])
-
-if test "$enable_keychain" = "yes"; then
-  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <AvailabilityMacros.h>
-#if !DARWIN || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_2)
-#error KeyChain API unavailable.
-#endif]], [[]])],[],[enable_keychain=no])
-fi
-
-if test "$enable_keychain" = "yes"; then
-  dnl ### Hack.  We should only need to pass the -framework options when
-  dnl linking libsvn_subr, since it is the only library that uses Keychain.
-  dnl
-  dnl Unfortunately, libtool 1.5.x doesn't track transitive dependencies for
-  dnl OS X frameworks like it does for normal libraries, so we need to
-  dnl explicitly pass the option to all the users of libsvn_subr to allow
-  dnl static builds to link successfully.
-  dnl
-  dnl This does mean that all executables we link will be linked directly
-  dnl to these frameworks - even when building shared libraries - but that
-  dnl shouldn't cause any problems.
-  LIBS="$LIBS -framework Security"
-  LIBS="$LIBS -framework CoreFoundation"
-  LIBS="$LIBS -framework CoreServices"
-  AC_DEFINE([SVN_HAVE_KEYCHAIN_SERVICES], [1], [Is Mac OS KeyChain support enabled?])
-  AC_MSG_RESULT([yes])
-else
-  AC_MSG_RESULT([no])
-fi
+dnl Mac OS soecufuc features -------------------
 
+SVN_LIB_MACOS_PLIST
+SVN_LIB_MACOS_KEYCHAIN
 
 dnl APR_HAS_DSO -------------------
 

Modified: subversion/trunk/subversion/libsvn_subr/sysinfo.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sysinfo.c?rev=1371942&r1=1371941&r2=1371942&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/sysinfo.c (original)
+++ subversion/trunk/subversion/libsvn_subr/sysinfo.c Sat Aug 11 13:07:19 2012
@@ -36,6 +36,7 @@
 #include <apr_lib.h>
 #include <apr_pools.h>
 #include <apr_file_info.h>
+#include <apr_strings.h>
 
 #include "svn_ctype.h"
 #include "svn_error.h"
@@ -48,6 +49,10 @@
 #include <sys/utsname.h>
 #endif
 
+#if SVN_HAVE_MACOS_PLIST
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
 #if HAVE_UNAME
 static const char* canonical_host_from_uname(apr_pool_t *pool);
 #endif
@@ -58,6 +63,10 @@ static const char * win32_release_name(a
 static const char * win32_shared_libs(apr_pool_t *pool);
 #endif /* WIN32 */
 
+#if SVN_HAVE_MACOS_PLIST
+static const char *macos_release_name(apr_pool_t *pool);
+#endif  /* SVN_HAVE_MACOS_PLIST */
+
 
 const char *
 svn_sysinfo__canonical_host(apr_pool_t *pool)
@@ -77,6 +86,8 @@ svn_sysinfo__release_name(apr_pool_t *po
 {
 #ifdef WIN32
   return win32_release_name(pool);
+#elif SVN_HAVE_MACOS_PLIST
+  return macos_release_name(pool);
 #else
   return NULL;
 #endif
@@ -461,3 +472,184 @@ win32_shared_libs(apr_pool_t *pool)
   return NULL;
 }
 #endif /* WIN32 */
+
+#if SVN_HAVE_MACOS_PLIST
+/* Load the SystemVersion.plist or ServerVersion.plist file into a
+   property list. Set SERVER to TRUE if the file read was
+   ServerVersion.plist. */
+static CFDictionaryRef
+system_version_plist(svn_boolean_t *server, apr_pool_t *pool)
+{
+  static const UInt8 server_version[] =
+    "/System/Library/CoreServices/ServerVersion.plist";
+  static const UInt8 system_version[] =
+    "/System/Library/CoreServices/SystemVersion.plist";
+
+  CFPropertyListRef plist = NULL;
+  CFDataRef resource = NULL;
+  CFStringRef errstr = NULL;
+  CFURLRef url = NULL;
+  SInt32 errcode;
+
+  url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
+                                                server_version,
+                                                sizeof(server_version) - 1,
+                                                FALSE);
+  if (!url)
+    return NULL;
+
+  if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
+                                                url, &resource,
+                                                NULL, NULL, &errcode))
+    {
+      CFRelease(url);
+      url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
+                                                    system_version,
+                                                    sizeof(system_version) - 1,
+                                                    FALSE);
+      if (!url)
+        return NULL;
+
+      if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
+                                                    url, &resource,
+                                                    NULL, NULL, &errcode))
+        {
+          CFRelease(url);
+          return NULL;
+        }
+      else
+        {
+          CFRelease(url);
+          *server = FALSE;
+        }
+    }
+  else
+    {
+      CFRelease(url);
+      *server = TRUE;
+    }
+
+  /* ### CFPropertyListCreateFromXMLData is obsolete, but its
+         replacement CFPropertyListCreateWithData is only available
+         from Mac OS 1.6 onward. */
+  plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resource,
+                                          kCFPropertyListImmutable,
+                                          &errstr);
+  if (resource)
+    CFRelease(resource);
+  if (errstr)
+    CFRelease(errstr);
+
+  if (CFDictionaryGetTypeID() != CFGetTypeID(plist))
+    {
+      /* Oops ... this really should be a dict. */
+      CFRelease(plist);
+      return NULL;
+    }
+
+  return plist;
+}
+
+/* Return the value for KEY from PLIST, or NULL if not available. */
+static const char *
+value_from_dict(CFDictionaryRef plist, CFStringRef key, apr_pool_t *pool)
+{
+  CFStringRef valref;
+  CFIndex bufsize;
+  const void *valptr;
+  const char *value;
+
+  if (!CFDictionaryGetValueIfPresent(plist, key, &valptr))
+    return NULL;
+
+  valref = valptr;
+  if (CFStringGetTypeID() != CFGetTypeID(valref))
+    return NULL;
+
+  value = CFStringGetCStringPtr(valref, kCFStringEncodingUTF8);
+  if (value)
+    return apr_pstrdup(pool, value);
+
+  bufsize =  5 * CFStringGetLength(valref) + 1;
+  value = apr_palloc(pool, bufsize);
+  if (!CFStringGetCString(valref, (char*)value, bufsize,
+                          kCFStringEncodingUTF8))
+    value = NULL;
+
+  return value;
+}
+
+/* Return the commercial name of the OS, given the version number in
+   a format that matches the regular expression /^10\.\d+(\..*)?$/ */
+static const char *
+release_name_from_version(const char *osver)
+{
+  char *end = NULL;
+  unsigned long num = strtoul(osver, &end, 10);
+
+  if (!end || *end != '.' || num != 10)
+    return NULL;
+
+  osver = end + 1;
+  end = NULL;
+  num = strtoul(osver, &end, 10);
+  if (!end || (*end && *end != '.'))
+    return NULL;
+
+  /* See http://en.wikipedia.org/wiki/History_of_OS_X#Release_timeline */
+  switch(num)
+    {
+    case 0: return "Cheetah";
+    case 1: return "Puma";
+    case 2: return "Jaguar";
+    case 3: return "Panther";
+    case 4: return "Tiger";
+    case 5: return "Leopard";
+    case 6: return "Snow Leopard";
+    case 7: return "Lion";
+    case 8: return "Mountain Lion";
+    }
+
+  return NULL;
+}
+
+static const char *
+macos_release_name(apr_pool_t *pool)
+{
+  svn_boolean_t server;
+  CFDictionaryRef plist = system_version_plist(&server, pool);
+
+  if (plist)
+    {
+      const char *osname = value_from_dict(plist, CFSTR("ProductName"), pool);
+      const char *osver = value_from_dict(plist,
+                                          CFSTR("ProductUserVisibleVersion"),
+                                          pool);
+      const char *build = value_from_dict(plist,
+                                          CFSTR("ProductBuildVersion"),
+                                          pool);
+      const char *release;
+
+      if (!osver)
+        osver = value_from_dict(plist, CFSTR("ProductVersion"), pool);
+      release = release_name_from_version(osver);
+
+      CFRelease(plist);
+      return apr_psprintf(pool, "%s%s%s%s%s%s%s%s",
+                          (osname ? osname : ""),
+                          (osver ? (osname ? " " : "") : ""),
+                          (osver ? osver : ""),
+                          (release ? (osname||osver ? " " : "") : ""),
+                          (release ? release : ""),
+                          (build
+                           ? (osname||osver||release ? ", " : "")
+                           : ""),
+                          (build
+                           ? (server ? "server build " : "build ")
+                           : ""),
+                          (build ? build : ""));
+    }
+
+  return NULL;
+}
+#endif  /* SVN_HAVE_MACOS_PLIST */