From 6bc81f5ac4209d5d6fdd9d54dc234f6db6d2f9a7 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Sun, 14 Aug 2011 13:17:57 -0700 Subject: [PATCH] git compat: add git support to cmake and make_svnrev.h.js add .gitignore --- .gitignore | 37 +++++++++++++++++++++++++++++ CMakeLists.txt | 11 +++++---- Source/Core/Common/make_svnrev.h.js | 26 +++++++++++++------- 3 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..22e80a5475 --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ + +#ignore thumbnails created by windows +Thumbs.db +#Ignore files built by Visual Studio +*.obj +*.exe +*.pdb +*.user +*.aps +*.pch +*.vspscc +*_i.c +*_p.c +*.ncb +*.suo +*.tlb +*.tlh +*.bak +*.cache +*.ilk +*.log +[Bb]in +[Dd]ebug*/ +*.lib +*.sbr +obj/ +[Rr]elease*/ +_ReSharper*/ +[Tt]est[Rr]esult* +Binary/Win32 +Binary/x64 +Source/Core/Common/Src/svnrev.h +*.opensdf +*.sdf +[Bb]uild + +*.ipch \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 133e689613..6ce4cf6b75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,10 +46,13 @@ function(enable_precompiled_headers PRECOMPILED_HEADER SOURCE_FILE SOURCE_VARIAB endif(MSVC) endfunction(enable_precompiled_headers) - -include(FindSubversion OPTIONAL) # for revision info -if(Subversion_FOUND AND NOT DOLPHIN_WC_REVISION) - Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} DOLPHIN) # defines DOLPHIN_WC_REVISION +# for revision info +include(FindGit OPTIONAL) +if(GIT_FOUND AND NOT DOLPHIN_WC_REVISION) + # defines DOLPHIN_WC_REVISION + EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + OUTPUT_VARIABLE DOLPHIN_WC_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE) endif() # Various compile flags diff --git a/Source/Core/Common/make_svnrev.h.js b/Source/Core/Common/make_svnrev.h.js index 38bcda312a..a68485e0f6 100644 --- a/Source/Core/Common/make_svnrev.h.js +++ b/Source/Core/Common/make_svnrev.h.js @@ -5,8 +5,9 @@ var outfile = "./Src/svnrev.h"; var svncmd = "SubWCRev ../../.. ./Src/svnrev_template.h " + outfile; var svntestcmd = "SubWCRev ../../.."; var hgcmd = "hg svn info"; +var gitcmd = "git.cmd rev-parse HEAD"; -var SVN = 1, HG = 2; +var SVN = 1, HG = 2, git = 3; var file_rev = 0, cur_rev = 0, cur_cms = 0; function RunCmdGetMatch(cmd, regex) @@ -32,14 +33,14 @@ function RunCmdGetMatch(cmd, regex) return 0; } -if (oFS.FileExists(outfile)) +try { - // file exists, read the value of SVN_REV_STR - file_rev = oFS.OpenTextFile(outfile).ReadLine().match(/\d+/); + // read the value of SVN_REV_STR + file_rev = oFS.OpenTextFile(outfile).ReadLine().match(/\d+/); } -else +catch (e) { - // file doesn't exist, create it + // file doesn't exist or string not found, (re)create it oFS.CreateTextFile(outfile); } @@ -49,14 +50,21 @@ if (cur_rev) cur_cms = SVN; else { - // SubWCRev failed, so use hg + // SubWCRev failed, try hg cur_rev = RunCmdGetMatch(hgcmd, /Revision.*?(\d+)/); if (cur_rev) cur_cms = HG; else { - WScript.Echo("Neither SVN or Hg revision info found!"); - WScript.Quit(1); + // hg failed, try git + cur_rev = RunCmdGetMatch(gitcmd, /(.*)/); + if (cur_rev) + cur_cms = git; + else + { + WScript.Echo("Trying to get SVN, Hg, and git info all failed"); + WScript.Quit(1); + } } }