From 9709dd2def24260ec2ea4fdc16e3a78fa206bbb9 Mon Sep 17 00:00:00 2001
From: ShizZy <shizzy@6bit.net>
Date: Fri, 13 Sep 2013 17:46:27 -0400
Subject: [PATCH] added scm_rev_gen project to automatically create a header
 with the git revision on build

---
 akiru.sln                      | 19 ++++++++
 src/common/scm_rev_gen.js      | 80 ++++++++++++++++++++++++++++++++++
 src/common/scm_rev_gen.vcxproj | 79 +++++++++++++++++++++++++++++++++
 src/common/src/scm_rev.h       |  4 +-
 src/common/src/version.cpp     |  2 +-
 5 files changed, 181 insertions(+), 3 deletions(-)
 create mode 100644 src/common/scm_rev_gen.js
 create mode 100644 src/common/scm_rev_gen.vcxproj

diff --git a/akiru.sln b/akiru.sln
index 325d99f6fe..045e0015c6 100644
--- a/akiru.sln
+++ b/akiru.sln
@@ -1,10 +1,21 @@
 Microsoft Visual Studio Solution File, Format Version 11.00
 # Visual Studio 2010
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "src\common\common.vcxproj", "{DFE335FC-755D-4BAA-8452-94434F8A1EDB}"
+	ProjectSection(ProjectDependencies) = postProject
+		{69F00340-5C3D-449F-9A80-958435C6CF06} = {69F00340-5C3D-449F-9A80-958435C6CF06}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "akiru", "src\akiru\akiru.vcxproj", "{CE7D2C07-21CE-4590-81AB-2ADA88A2B85F}"
+	ProjectSection(ProjectDependencies) = postProject
+		{69F00340-5C3D-449F-9A80-958435C6CF06} = {69F00340-5C3D-449F-9A80-958435C6CF06}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "src\core\core.vcxproj", "{8AEA7F29-3466-4786-A10D-6A4BD0610977}"
+	ProjectSection(ProjectDependencies) = postProject
+		{69F00340-5C3D-449F-9A80-958435C6CF06} = {69F00340-5C3D-449F-9A80-958435C6CF06}
+	EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scm_rev_gen", "src\common\scm_rev_gen.vcxproj", "{69F00340-5C3D-449F-9A80-958435C6CF06}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -38,6 +49,14 @@ Global
 		{8AEA7F29-3466-4786-A10D-6A4BD0610977}.Release|Win32.Build.0 = Release|Win32
 		{8AEA7F29-3466-4786-A10D-6A4BD0610977}.Release|x64.ActiveCfg = Release|x64
 		{8AEA7F29-3466-4786-A10D-6A4BD0610977}.Release|x64.Build.0 = Release|x64
+		{69F00340-5C3D-449F-9A80-958435C6CF06}.Debug|Win32.ActiveCfg = Debug|Win32
+		{69F00340-5C3D-449F-9A80-958435C6CF06}.Debug|Win32.Build.0 = Debug|Win32
+		{69F00340-5C3D-449F-9A80-958435C6CF06}.Debug|x64.ActiveCfg = Release|x64
+		{69F00340-5C3D-449F-9A80-958435C6CF06}.Debug|x64.Build.0 = Release|x64
+		{69F00340-5C3D-449F-9A80-958435C6CF06}.Release|Win32.ActiveCfg = Release|Win32
+		{69F00340-5C3D-449F-9A80-958435C6CF06}.Release|Win32.Build.0 = Release|Win32
+		{69F00340-5C3D-449F-9A80-958435C6CF06}.Release|x64.ActiveCfg = Release|x64
+		{69F00340-5C3D-449F-9A80-958435C6CF06}.Release|x64.Build.0 = Release|x64
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
diff --git a/src/common/scm_rev_gen.js b/src/common/scm_rev_gen.js
new file mode 100644
index 0000000000..e3ca5e67b3
--- /dev/null
+++ b/src/common/scm_rev_gen.js
@@ -0,0 +1,80 @@
+var wshShell		= new ActiveXObject("WScript.Shell")
+var oFS				= new ActiveXObject("Scripting.FileSystemObject");
+
+var outfile			= "./src/scm_rev.h";
+var cmd_revision	= " rev-parse HEAD";
+var cmd_describe	= " describe --always --long --dirty";
+var cmd_branch		= " rev-parse --abbrev-ref HEAD";
+
+function GetGitExe()
+{
+	for (var gitexe in {"git.cmd":1, "git":1})
+	{
+		try
+		{
+			wshShell.Exec(gitexe);
+			return gitexe;
+		}
+		catch (e)
+		{}
+	}
+
+	WScript.Echo("Cannot find git or git.cmd, check your PATH:\n" +
+		wshShell.ExpandEnvironmentStrings("%PATH%"));
+	WScript.Quit(1);
+}
+
+function GetFirstStdOutLine(cmd)
+{
+	try
+	{
+		return wshShell.Exec(cmd).StdOut.ReadLine();
+	}
+	catch (e)
+	{
+		// catch "the system cannot find the file specified" error
+		WScript.Echo("Failed to exec " + cmd + " this should never happen");
+		WScript.Quit(1);
+	}
+}
+
+function GetFileContents(f)
+{
+	try
+	{
+		return oFS.OpenTextFile(f).ReadAll();
+	}
+	catch (e)
+	{
+		// file doesn't exist
+		return "";
+	}
+}
+
+// get info from git
+var gitexe = GetGitExe();
+var revision	= GetFirstStdOutLine(gitexe + cmd_revision);
+var describe	= GetFirstStdOutLine(gitexe + cmd_describe);
+var branch		= GetFirstStdOutLine(gitexe + cmd_branch);
+var isMaster    = +("master" == branch);
+
+// remove hash (and trailing "-0" if needed) from description
+describe = describe.replace(/(-0)?-[^-]+(-dirty)?$/, '$2');
+
+var out_contents =
+	"#define SCM_REV_STR \"" + revision + "\"\n" +
+	"#define SCM_DESC_STR \"" + describe + "\"\n" +
+	"#define SCM_BRANCH_STR \"" + branch + "\"\n" +
+	"#define SCM_IS_MASTER " + isMaster + "\n";
+
+// check if file needs updating
+if (out_contents == GetFileContents(outfile))
+{
+	WScript.Echo(outfile + " current at " + describe);
+}
+else
+{
+	// needs updating - writeout current info
+	oFS.CreateTextFile(outfile, true).Write(out_contents);
+	WScript.Echo(outfile + " updated to " + describe);
+}
diff --git a/src/common/scm_rev_gen.vcxproj b/src/common/scm_rev_gen.vcxproj
new file mode 100644
index 0000000000..e1b413c56c
--- /dev/null
+++ b/src/common/scm_rev_gen.vcxproj
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="scm_rev_gen.js">
+    </None>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="force_rebuild.h" />
+    <ClInclude Include="src\scm_rev.h" />
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{69F00340-5C3D-449F-9A80-958435C6CF06}</ProjectGuid>
+    <RootNamespace>scm_rev_gen</RootNamespace>
+    <ProjectName>scm_rev_gen</ProjectName>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Utility</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\..\vsprops\base.props" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="..\..\vsprops\base.props" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <Import Project="..\..\vsprops\base.props" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="..\..\vsprops\base.props" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <PreBuildEvent>
+      <Command>cscript /nologo /E:JScript "scm_rev_gen.js"</Command>
+    </PreBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <PreBuildEvent>
+      <Command>cscript /nologo /E:JScript "scm_rev_gen.js"</Command>
+    </PreBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <PreBuildEvent>
+      <Command>cscript /nologo /E:JScript "scm_rev_gen.js"</Command>
+    </PreBuildEvent>
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/src/common/src/scm_rev.h b/src/common/src/scm_rev.h
index cb4eccfd0f..05ad769644 100644
--- a/src/common/src/scm_rev.h
+++ b/src/common/src/scm_rev.h
@@ -1,4 +1,4 @@
-#define SCM_REV_STR "7d11f8cedd7c135d96880f19ecbd3ff87a60a11f"
-#define SCM_DESC_STR "3.5-254-dirty"
+#define SCM_REV_STR "bfa6493324336066a1ef9d04f336faacae57d9f3"
+#define SCM_DESC_STR "bfa6493"
 #define SCM_BRANCH_STR "master"
 #define SCM_IS_MASTER 1
diff --git a/src/common/src/version.cpp b/src/common/src/version.cpp
index 47d7b52adc..d5cf10c3d7 100644
--- a/src/common/src/version.cpp
+++ b/src/common/src/version.cpp
@@ -13,7 +13,7 @@
 	#define BUILD_TYPE_STR ""
 #endif
 
-const char *scm_rev_str = "Dolphin "
+const char *scm_rev_str = "Akiru "
 #if !SCM_IS_MASTER
 	"[" SCM_BRANCH_STR "] "
 #endif