From fc78b2363387f6d139690edd3a9411369214b724 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Tue, 18 Mar 2008 18:22:52 +0000 Subject: [PATCH] Make the C# build task more robust. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665576 13f79535-47bb-0310-9956-ffa450edef68 --- lib/csharp/ThriftMSBuildTask/ThriftBuild.cs | 26 +++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs b/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs index a2bb6415..69ae8d3e 100644 --- a/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs +++ b/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs @@ -144,11 +144,18 @@ namespace ThriftMSBuildTask if (File.Exists(lastBuildPath)) { string lastComp = File.ReadAllText(lastBuildPath); - - if (lastComp == lastWrite) + //don't recompile if the thrift library has been updated since lastComp + FileInfo f = new FileInfo(ThriftLibrary.ItemSpec); + string thriftLibTime = f.LastWriteTimeUtc.ToFileTimeUtc().ToString(); + if (lastComp.CompareTo(thriftLibTime) < 0) + { + //new thrift library, do a compile + lastWrite = thriftLibTime; + } + else if (lastComp == lastWrite || (lastComp == thriftLibTime && lastComp.CompareTo(lastWrite) > 0)) { //the .thrift dir hasn't been written to since last compilation, don't need to do anything - LogMessage("ThriftImpl up-to-date", MessageImportance.Normal); + LogMessage("ThriftImpl up-to-date", MessageImportance.High); return true; } } @@ -160,9 +167,13 @@ namespace ThriftMSBuildTask string genDir = Path.Combine(thriftDir, "gen-csharp"); if (Directory.Exists(genDir)) { - Directory.Delete(genDir, true); + try + { + Directory.Delete(genDir, true); + } + catch { /*eh i tried, just over-write now*/} } - + //run the thrift executable to generate C# foreach (string thriftFile in Directory.GetFiles(defDir, "*.thrift")) { @@ -180,6 +191,11 @@ namespace ThriftMSBuildTask LogMessage("thrift.exe failed to compile " + thriftFile, MessageImportance.High); return false; } + if (p.ExitCode != 0) + { + LogMessage("thrift.exe failed to compile " + thriftFile, MessageImportance.High); + return false; + } } Csc csc = new Csc(); -- 2.17.1