* Added a project which can contain build-related tools (and msbuild tasks if we ever need them) and gave it responsibility for managing the svn revision stuff.
* With a little more work, it could handle unix and git checkouts too. * It could pull revisions from submodules as well, if they werent useless gibberish in git * Unaddressed: theres still a problem where depending on how emuhawk is built, the version project might not trigger
This commit is contained in:
parent
dceb09a0ef
commit
e7fe6252c6
Binary file not shown.
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>BizHawk.Build.Tool</RootNamespace>
|
||||
<AssemblyName>BizHawk.Build.Tool</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<OutputPath>..\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<OutputPath>..\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FileLocator.cs" />
|
||||
<Compile Include="Tool.cs" />
|
||||
<Compile Include="ToolPathUtil.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Build.Tool", "BizHawk.Build.Tool.csproj", "{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9BDF5B40-2547-4BAE-8FA7-C9BA0002CF03}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
|
||||
static class FileLocator
|
||||
{
|
||||
public static string LocateSVNTool(string _toolName)
|
||||
{
|
||||
string t = ToolPathUtil.MakeToolName(_toolName);
|
||||
string dir = null;
|
||||
try
|
||||
{
|
||||
dir = FindToolPath(t);
|
||||
}
|
||||
catch { }
|
||||
if (dir == null)
|
||||
return "";
|
||||
else
|
||||
return System.IO.Path.Combine(dir, t);
|
||||
|
||||
}
|
||||
|
||||
//stolen from MSBuild.Community.Tasks
|
||||
static string FindToolPath(string toolName)
|
||||
{
|
||||
string toolPath =
|
||||
ToolPathUtil.FindInRegistry(toolName) ??
|
||||
ToolPathUtil.FindInPath(toolName) ??
|
||||
ToolPathUtil.FindInProgramFiles(toolName,
|
||||
@"Subversion\bin",
|
||||
@"CollabNet Subversion Server",
|
||||
@"CollabNet Subversion",
|
||||
@"CollabNet Subversion Client",
|
||||
@"VisualSVN\bin",
|
||||
@"VisualSVN Server\bin",
|
||||
@"SlikSvn\bin");
|
||||
|
||||
if (toolPath == null)
|
||||
{
|
||||
throw new Exception("Could not find svn.exe. Looked in PATH locations and various common folders inside Program Files.");
|
||||
}
|
||||
|
||||
return toolPath;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BizHawk.Build.Tool
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string cmd = args[0];
|
||||
string[] cmdArgs = Crop(args, 1);
|
||||
switch (cmd.ToUpperInvariant())
|
||||
{
|
||||
case "SVN_REV": SVN_REV(cmdArgs); break;
|
||||
}
|
||||
}
|
||||
|
||||
static string[] Crop(string[] arr, int from)
|
||||
{
|
||||
return arr.Reverse().Take(arr.Length - from).Reverse().ToArray();
|
||||
}
|
||||
|
||||
static string EscapeArgument(string s)
|
||||
{
|
||||
return "\"" + Regex.Replace(s, @"(\\+)$", @"$1$1") + "\"";
|
||||
}
|
||||
|
||||
static string RunTool(string path, params string[] args)
|
||||
{
|
||||
string args_combined = "";
|
||||
foreach (var a in args)
|
||||
args_combined += EscapeArgument(a) + " ";
|
||||
args_combined.TrimEnd(' ');
|
||||
|
||||
var psi = new System.Diagnostics.ProcessStartInfo();
|
||||
psi.Arguments = args_combined;
|
||||
psi.FileName = path;
|
||||
psi.UseShellExecute = false;
|
||||
psi.CreateNoWindow = true;
|
||||
psi.RedirectStandardOutput = true;
|
||||
var proc = new System.Diagnostics.Process();
|
||||
proc.StartInfo = psi;
|
||||
proc.Start();
|
||||
|
||||
string output = "";
|
||||
while (!proc.StandardOutput.EndOfStream)
|
||||
{
|
||||
output += proc.StandardOutput.ReadLine();
|
||||
// do something with line
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static void WriteTextIfChanged(string path, string content)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
goto WRITE;
|
||||
string old = File.ReadAllText(path);
|
||||
if (old == content) return;
|
||||
WRITE:
|
||||
File.WriteAllText(path, content);
|
||||
}
|
||||
|
||||
//gets the working copy version. use this command:
|
||||
//BizHawk.Build.Tool.exe SCM_REV --wc c:\path\to\wcdir --template c:\path\to\templatefile --out c:\path\to\outputfile.cs
|
||||
//if the required tools aren't found
|
||||
static void SVN_REV(string[] args)
|
||||
{
|
||||
string wcdir = null, templatefile = null, outfile = null;
|
||||
int idx=0;
|
||||
while (idx < args.Length)
|
||||
{
|
||||
string a = args[idx++];
|
||||
string au = a.ToUpperInvariant();
|
||||
if(au == "--WC")
|
||||
wcdir = args[idx++];
|
||||
if(au == "--TEMPLATE")
|
||||
templatefile = args[idx++];
|
||||
if (au == "--OUT")
|
||||
outfile = args[idx++];
|
||||
}
|
||||
|
||||
//first read the template
|
||||
string templateContents = File.ReadAllText(templatefile);
|
||||
|
||||
//pick revision 0 in case the WC investigation fails
|
||||
int rev = 0;
|
||||
|
||||
//try to find an SVN and run it
|
||||
string svn = FileLocator.LocateSVNTool("svnversion");
|
||||
if (svn != "")
|
||||
{
|
||||
try {
|
||||
string output = RunTool(svn, wcdir);
|
||||
var parts = output.Split(':');
|
||||
var rstr = parts[parts.Length - 1];
|
||||
rstr = Regex.Replace(rstr, "[^0-9]", "");
|
||||
rev = int.Parse(rstr);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
|
||||
//replace the template and dump the results if needed
|
||||
templateContents = templateContents.Replace("$WCREV$", rev.ToString());
|
||||
WriteTextIfChanged(outfile, templateContents);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
|
||||
//This is stolen from MSBuild Community Tasks
|
||||
static class ToolPathUtil
|
||||
{
|
||||
public static bool SafeFileExists(string path, string toolName)
|
||||
{
|
||||
return SafeFileExists(Path.Combine(path, toolName));
|
||||
}
|
||||
|
||||
public static bool SafeFileExists(string file)
|
||||
{
|
||||
try { return File.Exists(file); }
|
||||
catch { } // eat exception
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string MakeToolName(string name)
|
||||
{
|
||||
return (Environment.OSVersion.Platform == PlatformID.Unix) ?
|
||||
name : name + ".exe";
|
||||
}
|
||||
|
||||
public static string FindInRegistry(string toolName)
|
||||
{
|
||||
try
|
||||
{
|
||||
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + toolName, false);
|
||||
if (key != null)
|
||||
{
|
||||
string possiblePath = key.GetValue(null) as string;
|
||||
if (SafeFileExists(possiblePath))
|
||||
return Path.GetDirectoryName(possiblePath);
|
||||
}
|
||||
}
|
||||
catch (System.Security.SecurityException) { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string FindInPath(string toolName)
|
||||
{
|
||||
string pathEnvironmentVariable = Environment.GetEnvironmentVariable("PATH") ?? string.Empty;
|
||||
string[] paths = pathEnvironmentVariable.Split(new[] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string path in paths)
|
||||
{
|
||||
if (SafeFileExists(path, toolName))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string FindInProgramFiles(string toolName, params string[] commonLocations)
|
||||
{
|
||||
foreach (string location in commonLocations)
|
||||
{
|
||||
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), location);
|
||||
if (SafeFileExists(path, toolName))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string FindInLocalPath(string toolName, string localPath)
|
||||
{
|
||||
if (localPath == null)
|
||||
return null;
|
||||
|
||||
string path = new DirectoryInfo(localPath).FullName;
|
||||
if (SafeFileExists(localPath, toolName))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
@echo off
|
||||
|
||||
set TEMPFILE="%TEMP%\BIZBUILD-SVN-%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%"
|
||||
set SVNREV="%~1\svnrev.cs"
|
||||
|
||||
rem try generating svnrev from svn now. this will fail if svn is nonexistent, so...
|
||||
"%~1\SubWCRev.exe" "%~1\..\." "%~1\svnrev_template" %TEMPFILE% > NUL
|
||||
|
||||
rem generate a svnrev with sed using no revision number, in case svn isnt available
|
||||
if not exist %TEMPFILE% (
|
||||
"%~1\sed.exe" s/\$WCREV\$/0/ < "%~1\svnrev_template" > %TEMPFILE%
|
||||
)
|
||||
|
||||
rem ... ignore the error
|
||||
SET ERRORLEVEL=0
|
||||
|
||||
|
||||
rem if we didnt even have a svnrev, then go ahead and copy it
|
||||
if not exist %SVNREV% (
|
||||
copy /y %TEMPFILE% %SVNREV% > NUL
|
||||
) else if exist %TEMPFILE% (
|
||||
rem check to see whether its any different, so we dont touch unchanged files
|
||||
fc /b %TEMPFILE% %SVNREV% > NUL
|
||||
if ERRORLEVEL 2 (
|
||||
echo Updated svnrev file
|
||||
copy /y %TEMPFILE% %SVNREV% > NUL
|
||||
goto SKIP
|
||||
)
|
||||
if ERRORLEVEL 1 (
|
||||
echo Updated svnrev file
|
||||
copy /y %TEMPFILE% %SVNREV% > NUL
|
||||
goto SKIP
|
||||
)
|
||||
if ERRORLEVEL 0 (
|
||||
echo svnrev is indicating no changes
|
||||
goto SKIP
|
||||
)
|
||||
|
||||
|
||||
) else (
|
||||
echo Ran into a weird error writing subwcrev output to tempfile: %TEMPFILE%
|
||||
)
|
||||
|
||||
:SKIP
|
||||
|
||||
rem <zero> make subwcrev process more reliable. sorry for leaving so many tempfiles, but life's too short
|
||||
rem del %TEMPFILE%
|
||||
|
||||
rem always let build proceed
|
||||
SET ERRORLEVEL=0
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Version/sed.exe
BIN
Version/sed.exe
Binary file not shown.
|
@ -36,7 +36,7 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>"$(ProjectDir)subwcrev.bat" "$(ProjectDir)"</PreBuildEvent>
|
||||
<PreBuildEvent>"$(ProjectDir)..\Build\BizHawk.Build.Tool.exe" SVN_REV --wc "$(ProjectDir).." --template "$(ProjectDir)svnrev_template" --out "$(ProjectDir)svnrev.cs"</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
Loading…
Reference in New Issue