blob: 0751cfcf5d4e90a1c78a67bf8af47ca606cf86ec [file] [log] [blame]
Douglas Gregor7550a6c2009-10-05 18:52:24 +00001//===- 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 Kremenek2377a0e2010-01-22 20:55:35 +000013
14#include "llvm/ADT/StringRef.h"
Douglas Gregor7550a6c2009-10-05 18:52:24 +000015#include <cstring>
16#include <cstdlib>
Ted Kremenek2377a0e2010-01-22 20:55:35 +000017
Douglas Gregor7550a6c2009-10-05 18:52:24 +000018using namespace std;
19
20namespace clang {
21
Ted Kremenek2377a0e2010-01-22 20:55:35 +000022llvm::StringRef getClangRepositoryPath() {
Douglas Gregor7550a6c2009-10-05 18:52:24 +000023 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 Gregor4c25ce72009-11-05 23:46:05 +000032 End = strstr(URL, "/clang/tools/clang");
33 if (End)
34 *End = 0;
35
Douglas Gregor7550a6c2009-10-05 18:52:24 +000036 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
47unsigned getClangSubversionRevision() {
48#ifndef SVN_REVISION
Douglas Gregor1b7035d2009-10-05 20:33:49 +000049 // Subversion was not available at build time?
Douglas Gregor7550a6c2009-10-05 18:52:24 +000050 return 0;
51#else
Douglas Gregor1b7035d2009-10-05 20:33:49 +000052 return strtol(SVN_REVISION, 0, 10);
Douglas Gregor7550a6c2009-10-05 18:52:24 +000053#endif
54}
55
56} // end namespace clang