Add msbuild task to update git_version.h

This commit is contained in:
Thomas Goyne 2012-11-08 21:03:14 -08:00
parent c759beda96
commit 3cf2a39884
4 changed files with 145 additions and 10 deletions

View File

@ -44,6 +44,11 @@
<AdditionalOptions>/Zm150 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<!-- Update git_version.h -->
<UsingTask TaskName="ExecShellScript" AssemblyFile="$(AegisubBinaryDir)\BuildTasks.dll" />
<Target Name="UpdateVersion" BeforeTargets="ClCompile">
<ExecShellScript Command="build/version.sh .." />
</Target>
<!-- Project References -->
<ItemGroup>
<ProjectReference Include="..\csrihelper\csrihelper.vcxproj">
@ -454,4 +459,4 @@
<ImportGroup Label="ExtensionTargets">
<Import Project="$(MSBuildThisFileDirectory)Aegisub.targets" />
</ImportGroup>
</Project>
</Project>

View File

@ -0,0 +1,84 @@
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// Aegisub Project http://www.aegisub.org/
module BuildTasks
open System
open System.Diagnostics
open Microsoft.Build.Evaluation
open Microsoft.Build.Framework
open Microsoft.Build.Utilities
exception ShellException of string
let searchPath file =
Environment.GetEnvironmentVariable("path").Split ';'
|> Seq.map (fun p -> IO.Path.Combine(p, file))
|> Seq.filter IO.File.Exists
|> Seq.append [""]
|> Seq.nth 1
let propertyMap (be : IBuildEngine) =
use reader = Xml.XmlReader.Create(be.ProjectFileOfTaskNode)
let project = new Project(reader)
project.AllEvaluatedProperties
|> Seq.filter (fun x -> not x.IsEnvironmentProperty)
|> Seq.filter (fun x -> not x.IsGlobalProperty)
|> Seq.filter (fun x -> not x.IsReservedProperty)
|> Seq.map (fun x -> (x.Name, x.EvaluatedValue))
|> Map.ofSeq
type ShellWrapper(props : Map<String, String>) =
let sh =
match props.TryFind "MsysBasePath" with
| None | Some "" -> searchPath "sh.exe"
| Some path -> sprintf "%s\\bin\\sh.exe" path
let cwd = function
| null | "" -> props.["AegisubSourceBase"]
| x -> x
member this.call scriptName workingDir =
if not <| IO.File.Exists sh then
raise <| ShellException "sh.exe not found. Make sure the MSYS root is set to a correct location."
let info = new ProcessStartInfo(FileName = sh
, Arguments = scriptName
, WorkingDirectory = cwd workingDir
, RedirectStandardOutput = true
, UseShellExecute = false)
use p = new Process(StartInfo = info)
ignore(p.Start())
p.WaitForExit()
if p.ExitCode <> 0 then
raise <| ShellException(p.StandardOutput.ReadToEnd())
type ExecShellScript() =
inherit Task()
member val WorkingDirectory = "" with get, set
member val Command = "" with get, set
override this.Execute() =
try
let sw = ShellWrapper (propertyMap this.BuildEngine)
this.Log.LogMessage("Calling '{0}'", this.Command);
sw.call this.Command this.WorkingDirectory
true
with ShellException(e) ->
this.Log.LogError(e)
false

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
<Platform>AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>15c79e75-f5f6-451d-b870-94ed02af257e</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>BuildTakss</RootNamespace>
<AssemblyName>BuildTasks</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Name>BuildTasks</Name>
<ProjectName>BuildTasks</ProjectName>
</PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)..\paths.props" />
<PropertyGroup>
<OutputPath>$(AegisubBinaryDir)</OutputPath>
<IntermediateOutputPath>$(AegisubObjectDir)</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Engine" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BuildTasks.fs" />
</ItemGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" />
</Project>

View File

@ -1,9 +0,0 @@
cd %~dp0..
sh build/version.sh ..
if %ERRORLEVEL% NEQ 0 goto :fail
goto :eof
:fail
ECHO Aegisub requires that sh and git be on the windows command line path for version checking.
> build\git_version.h echo #define BUILD_GIT_VERSION_NUMBER 0
>> build\git_version.h echo #define BUILD_GIT_VERSION_STR "unknown"