Douglas Gregor | 7550a6c | 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 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 2377a0e | 2010-01-22 20:55:35 +0000 | [diff] [blame^] | 13 | |
| 14 | #include "llvm/ADT/StringRef.h" |
Douglas Gregor | 7550a6c | 2009-10-05 18:52:24 +0000 | [diff] [blame] | 15 | #include <cstring> |
| 16 | #include <cstdlib> |
Ted Kremenek | 2377a0e | 2010-01-22 20:55:35 +0000 | [diff] [blame^] | 17 | |
Douglas Gregor | 7550a6c | 2009-10-05 18:52:24 +0000 | [diff] [blame] | 18 | using namespace std; |
| 19 | |
| 20 | namespace clang { |
| 21 | |
Ted Kremenek | 2377a0e | 2010-01-22 20:55:35 +0000 | [diff] [blame^] | 22 | llvm::StringRef getClangRepositoryPath() { |
Douglas Gregor | 7550a6c | 2009-10-05 18:52:24 +0000 | [diff] [blame] | 23 | static const char *Path = 0; |
| 24 | if (Path) |
| 25 | return Path; |
| 26 | |
| 27 | static char URL[] = "$URL$"; |
| 28 | char *End = strstr(URL, "/lib/Basic"); |
| 29 | if (End) |
| 30 | *End = 0; |
| 31 | |
Douglas Gregor | 4c25ce7 | 2009-11-05 23:46:05 +0000 | [diff] [blame] | 32 | End = strstr(URL, "/clang/tools/clang"); |
| 33 | if (End) |
| 34 | *End = 0; |
| 35 | |
Douglas Gregor | 7550a6c | 2009-10-05 18:52:24 +0000 | [diff] [blame] | 36 | char *Begin = strstr(URL, "cfe/"); |
| 37 | if (Begin) { |
| 38 | Path = Begin + 4; |
| 39 | return Path; |
| 40 | } |
| 41 | |
| 42 | Path = URL; |
| 43 | return Path; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | unsigned getClangSubversionRevision() { |
| 48 | #ifndef SVN_REVISION |
Douglas Gregor | 1b7035d | 2009-10-05 20:33:49 +0000 | [diff] [blame] | 49 | // Subversion was not available at build time? |
Douglas Gregor | 7550a6c | 2009-10-05 18:52:24 +0000 | [diff] [blame] | 50 | return 0; |
| 51 | #else |
Douglas Gregor | 1b7035d | 2009-10-05 20:33:49 +0000 | [diff] [blame] | 52 | return strtol(SVN_REVISION, 0, 10); |
Douglas Gregor | 7550a6c | 2009-10-05 18:52:24 +0000 | [diff] [blame] | 53 | #endif |
| 54 | } |
| 55 | |
| 56 | } // end namespace clang |