lxapigen.pl: Don't overwrite files that didn't change.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 06 Jun 2018 16:19:24 -0400
changeset 114 23577dfa3fad
parent 113 5862f3b41e24
child 115 02f477daafca
lxapigen.pl: Don't overwrite files that didn't change. This prevents a full rebuild every time you add an API.
lxapigen.pl
--- a/lxapigen.pl	Mon May 28 12:57:50 2018 -0400
+++ b/lxapigen.pl	Wed Jun 06 16:19:24 2018 -0400
@@ -87,7 +87,8 @@
 
     # Here we go...
 
-    my $outfname = "$dirname/$module-lx.h";
+    my $finalfname = "$dirname/$module-lx.h";
+    my $outfname = "$finalfname-new";
     open(OUT, '>', $outfname) or die("Failed to open '$outfname' for writing: $!\n");
 
     print OUT <<EOF
@@ -227,6 +228,12 @@
 ;
 
     close(OUT);
+
+    if ((system("diff --brief '$finalfname' '$outfname'") == -1) || ($? != 0)) {
+        rename($outfname, $finalfname) or die("Failed to rename '$outfname' to '$finalfname': $!\n");
+    } else {
+        unlink($outfname);  # they match, just delete the new copy so build system doesn't rebuild everything.
+    }
 }
 
 closedir(DIRH);