[tasque/transition: 72/213] Add automatic checkout of submodule during build



commit f6b9d526458c6bc4abd222c38abe35becb07de1e
Author: Antonius Riha <antoniusriha gmail com>
Date:   Tue Jul 10 16:53:47 2012 +0200

    Add automatic checkout of submodule during build

 build/LoadGitSubmodules.cs |   78 ++++++++++++++++++++++++++++++++++++++++++++
 build/build.csproj         |    6 +++
 2 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/build/LoadGitSubmodules.cs b/build/LoadGitSubmodules.cs
new file mode 100644
index 0000000..acf1c51
--- /dev/null
+++ b/build/LoadGitSubmodules.cs
@@ -0,0 +1,78 @@
+// 
+// LoadGitSubmodules.cs
+//  
+// Author:
+//       Antonius Riha <antoniusriha gmail com>
+// 
+// Copyright (c) 2012 Antonius Riha
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using System.Diagnostics;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Tasque.Build
+{
+	public class LoadGitSubmodules : Task
+	{
+		[Required]
+		public ITaskItem SolutionDirectory {
+			get { return solutionDirectory; }
+			set {
+				solutionDirectory = value;
+				slnDir = value.ItemSpec;
+			}
+		}
+		
+		public override bool Execute ()
+		{
+			var startInfo = new ProcessStartInfo ("git", "submodule update --init");
+			startInfo.WorkingDirectory = slnDir;
+			startInfo.UseShellExecute = false;
+			startInfo.RedirectStandardError = true;
+			startInfo.RedirectStandardOutput = true;
+			startInfo.CreateNoWindow = true;
+			
+			try {
+				var p = new Process ();
+				p.StartInfo = startInfo;
+				p.OutputDataReceived += (sender, e) => { if (e.Data != null) Log.LogMessage (e.Data); };
+				p.ErrorDataReceived += (sender, e) => { if (e.Data != null) Log.LogError (e.Data); };
+				p.Start ();
+				p.BeginOutputReadLine ();
+				p.BeginErrorReadLine ();
+				
+				p.WaitForExit (20000);
+				if (p.ExitCode != 0)
+					return false;
+				
+			} catch (Exception e) {
+				Log.LogErrorFromException (e, true);
+				return false;
+			}
+			
+			return true;
+		}
+		
+		string slnDir;
+		ITaskItem solutionDirectory;
+	}
+}
+
diff --git a/build/build.csproj b/build/build.csproj
index 26a94cc..840c02b 100644
--- a/build/build.csproj
+++ b/build/build.csproj
@@ -120,6 +120,7 @@
   <!-- Project and tasks imports -->
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <UsingTask AssemblyFile="lib\Tasque.Build.dll" TaskName="Tasque.Build.SetDataAtBuildTime" />
+  <UsingTask AssemblyFile="lib\Tasque.Build.dll" TaskName="Tasque.Build.LoadGitSubmodules" />
   <ItemGroup>
     <None Include="build.csproj" />
     <None Include="..\tasque.sln">
@@ -160,6 +161,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="SetDataAtBuildTime.cs" />
+    <Compile Include="LoadGitSubmodules.cs" />
   </ItemGroup>
   <ItemGroup>
     <GlobalDefines Include="GlobalDefines.cs" />
@@ -176,11 +178,15 @@
   <ItemGroup>
     <Reference Include="Microsoft.Build.Framework" />
     <Reference Include="Microsoft.Build.Utilities.v4.0" />
+    <Reference Include="System" />
   </ItemGroup>
   <Target Name="AfterBuild">
     <Message Text="Setting up global definitions..." />
     <SetDataAtBuildTime AuthorsFile="@(Authors)" CopyingFile="@(License)" GlobalDefinesFile="@(GlobalDefines)" GlobalDefinesFileIn="@(GlobalDefinesIn)" Version="$(ReleaseVersion)" Website="$(Website)" />
     <Message Text="Finished setting up global definitions." />
+    <Message Text="Load submodules..." />
+    <LoadGitSubmodules SolutionDirectory="$(MSBuildProjectDirectory)\.." />
+    <Message Text="Finished loading submodules." />
   </Target>
   <ProjectExtensions>
     <MonoDevelop>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]