[Lldb-commits] [lldb] r203594 - Detect when llvm or clang sources have changed and rebuild llvm/clang automatically.

Greg Clayton gclayton at apple.com
Tue Mar 11 11:24:33 PDT 2014


Author: gclayton
Date: Tue Mar 11 13:24:32 2014
New Revision: 203594

URL: http://llvm.org/viewvc/llvm-project?rev=203594&view=rev
Log:
Detect when llvm or clang sources have changed and rebuild llvm/clang automatically.


Modified:
    lldb/trunk/scripts/build-llvm.pl

Modified: lldb/trunk/scripts/build-llvm.pl
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/build-llvm.pl?rev=203594&r1=203593&r2=203594&view=diff
==============================================================================
--- lldb/trunk/scripts/build-llvm.pl (original)
+++ lldb/trunk/scripts/build-llvm.pl Tue Mar 11 13:24:32 2014
@@ -11,7 +11,9 @@
 use strict;
 use File::Basename;
 use File::Glob ':glob';
+use File::Slurp;
 use List::Util qw[min max];
+use Digest::MD5 qw(md5_hex);
 
 our $llvm_srcroot = $ENV{SCRIPT_INPUT_FILE_0};
 our $llvm_dstroot = $ENV{SCRIPT_INPUT_FILE_1};
@@ -49,7 +51,10 @@ else
 {
     die "Unsupported LLVM configuration: '$llvm_configuration'\n";
 }
-
+our @llvm_repositories = (
+    "$llvm_srcroot",
+    "$llvm_srcroot/tools/clang"
+);
 our @archive_files = (
     "$llvm_configuration/lib/libclang.a",
     "$llvm_configuration/lib/libclangAnalysis.a",
@@ -157,6 +162,28 @@ sub build_llvm
     #my $extra_svn_options = $debug ? "" : "--quiet";
     # Make the llvm build directory
     my $arch_idx = 0;
+    
+    # Calculate if the current source digest so we can compare it to each architecture
+    # build folder
+    my @llvm_md5_strings;
+    foreach my $repo (@llvm_repositories)
+    {
+        if (-d "$repo/.svn")
+        {
+            push(@llvm_md5_strings, `svn info '$repo'`);
+            push(@llvm_md5_strings, `svn diff '$repo'`);
+        }
+        elsif (-d "$repo/.git")
+        {
+            push(@llvm_md5_strings, `cd '$repo'; git branch -v`);
+            push(@llvm_md5_strings, `cd '$repo'; git diff`);
+        }
+    }
+    #print "LLVM MD5 will be generated from:\n";
+    #print @llvm_md5_strings;
+    my $llvm_hex_digest = md5_hex(@llvm_md5_strings);
+
+    #print "llvm MD5: $llvm_hex_digest\n";
     foreach my $arch (@archs)
     {
         my $llvm_dstroot_arch = "${llvm_dstroot}/${arch}";
@@ -165,6 +192,8 @@ sub build_llvm
         my $do_configure = 0;
         my $do_make = 0;
         my $is_arm = $arch =~ /^arm/;
+        my $save_arch_digest = 1;
+        my $arch_digest_file = "$llvm_dstroot_arch/md5";
 
         my $llvm_dstroot_arch_archive = "$llvm_dstroot_arch/$llvm_clang_basename";
         print "LLVM architecture root for ${arch} exists at '$llvm_dstroot_arch'...";
@@ -173,6 +202,7 @@ sub build_llvm
             print "YES\n";
             $do_configure = !-e "$llvm_dstroot_arch/config.log";
 
+            my @archive_modtimes;
             # dstroot for llvm build exists, make sure all .a files are built
             for my $llvm_lib (@archive_files)
             {
@@ -182,13 +212,65 @@ sub build_llvm
                     $do_make = 1;
                 }
             }
-            if (!-e $llvm_dstroot_arch_archive)
+            if ($do_make == 0)
             {
-                $do_make = 1;
+                if (-e $arch_digest_file)
+                {
+                    my $arch_hex_digest = read_file($arch_digest_file);
+                    if ($arch_hex_digest eq $llvm_hex_digest)
+                    {
+                        # No sources have been changed or updated
+                        $save_arch_digest = 0;
+                    }
+                    else
+                    {
+                        # Sources have changed, or svn has been updated
+                        print "Sources have changed, rebuilding...\n";
+                        $do_make = 1;
+                    }
+                }
+                else
+                {
+                    # No MD5 digest, we need to make
+                    print "Missing MD5 digest file '$arch_digest_file', rebuilding...\n";
+                    $do_make = 1;
+                }
+                
+                if ($do_make == 0)
+                {
+                    if (-e $llvm_dstroot_arch_archive)
+                    {
+                        # the final archive exists, check the modification times on all .a files that
+                        # make the final archive to make sure we don't need to rebuild
+                        my $llvm_dstroot_arch_archive_modtime = (stat($llvm_dstroot_arch_archive))[9];
+                        for my $llvm_lib (@archive_files)
+                        {
+                            if (-e "$llvm_dstroot_arch/$llvm_lib")
+                            {
+                                if ($llvm_dstroot_arch_archive_modtime < (stat("$llvm_dstroot_arch/$llvm_lib"))[9])
+                                {
+                                    print "'$llvm_dstroot_arch/$llvm_lib' is newer than '$llvm_dstroot_arch_archive', rebuilding...\n";
+                                    $do_make = 1;
+                                    last;
+                                }
+                            }
+                        }
+
+                        if ($do_make == 0)
+                        {
+                            print "LLVM architecture archive for ${arch} is '$llvm_dstroot_arch_archive' and is up to date.\n";
+                        }
+                    }
+                    else
+                    {
+                        $do_make = 1;
+                    }
+                }
             }
-            else
+            
+            if ($do_make)
             {
-                print "LLVM architecture archive for ${arch} is '$llvm_dstroot_arch_archive'\n";
+                unlink($llvm_dstroot_arch_archive);
             }
         }
         else
@@ -235,6 +317,11 @@ sub build_llvm
                 }
             }
         }
+        
+        if ($save_arch_digest)
+        {
+            write_file($arch_digest_file, \$llvm_hex_digest);
+        }
 
         if ($do_configure)
         {





More information about the lldb-commits mailing list