From 3cf2a39884018e1549a037db0b76d2f8762facca Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 8 Nov 2012 21:03:14 -0800 Subject: [PATCH] Add msbuild task to update git_version.h --- aegisub/build/Aegisub/Aegisub.vcxproj | 7 +- aegisub/build/BuildTasks/BuildTasks.fs | 84 ++++++++++++++++++++++ aegisub/build/BuildTasks/BuildTasks.fsproj | 55 ++++++++++++++ aegisub/build/version.bat | 9 --- 4 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 aegisub/build/BuildTasks/BuildTasks.fs create mode 100644 aegisub/build/BuildTasks/BuildTasks.fsproj delete mode 100644 aegisub/build/version.bat diff --git a/aegisub/build/Aegisub/Aegisub.vcxproj b/aegisub/build/Aegisub/Aegisub.vcxproj index 3a399f5c5..95fbe4280 100644 --- a/aegisub/build/Aegisub/Aegisub.vcxproj +++ b/aegisub/build/Aegisub/Aegisub.vcxproj @@ -44,6 +44,11 @@ /Zm150 %(AdditionalOptions) + + + + + @@ -454,4 +459,4 @@ - \ No newline at end of file + diff --git a/aegisub/build/BuildTasks/BuildTasks.fs b/aegisub/build/BuildTasks/BuildTasks.fs new file mode 100644 index 000000000..550900866 --- /dev/null +++ b/aegisub/build/BuildTasks/BuildTasks.fs @@ -0,0 +1,84 @@ +// Copyright (c) 2012, Thomas Goyne +// +// 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) = + 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 diff --git a/aegisub/build/BuildTasks/BuildTasks.fsproj b/aegisub/build/BuildTasks/BuildTasks.fsproj new file mode 100644 index 000000000..362a83980 --- /dev/null +++ b/aegisub/build/BuildTasks/BuildTasks.fsproj @@ -0,0 +1,55 @@ + + + + + Debug + AnyCPU + 2.0 + 15c79e75-f5f6-451d-b870-94ed02af257e + Library + BuildTakss + BuildTasks + v4.5 + BuildTasks + BuildTasks + + + + $(AegisubBinaryDir) + $(AegisubObjectDir) + + + true + full + false + false + DEBUG;TRACE + 3 + + + pdbonly + true + true + TRACE + 3 + + + + + + + + + + + + + + + + + + 11 + + + diff --git a/aegisub/build/version.bat b/aegisub/build/version.bat deleted file mode 100644 index edafa77ce..000000000 --- a/aegisub/build/version.bat +++ /dev/null @@ -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"