Douglas Gregor | 60b5d8e | 2009-10-05 18:52:24 +0000 | [diff] [blame^] | 1 | //===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines several version-related utility functions for Clang. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #include <cstring> |
| 14 | #include <cstdlib> |
| 15 | using namespace std; |
| 16 | |
| 17 | namespace clang { |
| 18 | |
| 19 | const char *getClangSubversionPath() { |
| 20 | static const char *Path = 0; |
| 21 | if (Path) |
| 22 | return Path; |
| 23 | |
| 24 | static char URL[] = "$URL$"; |
| 25 | char *End = strstr(URL, "/lib/Basic"); |
| 26 | if (End) |
| 27 | *End = 0; |
| 28 | |
| 29 | char *Begin = strstr(URL, "cfe/"); |
| 30 | if (Begin) { |
| 31 | Path = Begin + 4; |
| 32 | return Path; |
| 33 | } |
| 34 | |
| 35 | Path = URL; |
| 36 | return Path; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | unsigned getClangSubversionRevision() { |
| 41 | #ifndef SVN_REVISION |
| 42 | return 0; |
| 43 | #else |
| 44 | // What follows is an evil trick. We can end up getting three different |
| 45 | // kinds of results when asking for the Subversion information: |
| 46 | // - if SVN_REVISION is a number, we return that number (adding 0 to it is |
| 47 | // harmless). |
| 48 | // - if SVN_REVISION is "exported" (for an tree without any Subversion |
| 49 | // info), we end up referencing the local variable "exported" and adding |
| 50 | // zero to it, and we return 0. |
| 51 | // - if SVN_REVISION is empty (because "svn info" returned no results), |
| 52 | // the "+" turns into a unary "+" operator and we return 0. |
| 53 | // |
| 54 | // Making this less ugly requires doing more computation in the CMake- and |
| 55 | // Makefile-based build systems, with all sorts of checking to make sure we |
| 56 | // don't end up breaking this build. It's better this way. Really. |
| 57 | const unsigned exported = 0; |
| 58 | (void)exported; |
| 59 | return SVN_REVISION + 0; |
| 60 | #endif |
| 61 | } |
| 62 | |
| 63 | } // end namespace clang |