Make the C# build task more robust.
authorDavid Reiss <dreiss@apache.org>
Tue, 18 Mar 2008 18:22:52 +0000 (18:22 +0000)
committerDavid Reiss <dreiss@apache.org>
Tue, 18 Mar 2008 18:22:52 +0000 (18:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665576 13f79535-47bb-0310-9956-ffa450edef68

lib/csharp/ThriftMSBuildTask/ThriftBuild.cs

index a2bb641..69ae8d3 100644 (file)
@@ -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();