[llvm-commits] [llvm] r75833 - /llvm/trunk/utils/UpdateCMakeLists.pl

Ted Kremenek kremenek at apple.com
Wed Jul 15 14:10:58 PDT 2009


Author: kremenek
Date: Wed Jul 15 16:10:57 2009
New Revision: 75833

URL: http://llvm.org/viewvc/llvm-project?rev=75833&view=rev
Log:
Add script 'UpdateCMakeLists.pl'. This script can be used (manually) to update
the list of files in the CMakeLists.txt files.

It works by scanning (starting from the working directory from which it is run)
all subdirectories containing CMakeLists.txt files. It then updates the list of
C and C++ files in the 'add_llvm_library' and 'add_clang_library' lists. Sources
file lists are emitted in lexical order.

Added:
    llvm/trunk/utils/UpdateCMakeLists.pl   (with props)

Added: llvm/trunk/utils/UpdateCMakeLists.pl
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/UpdateCMakeLists.pl?rev=75833&view=auto

==============================================================================
--- llvm/trunk/utils/UpdateCMakeLists.pl (added)
+++ llvm/trunk/utils/UpdateCMakeLists.pl Wed Jul 15 16:10:57 2009
@@ -0,0 +1,118 @@
+#!/usr/bin/env perl
+use strict;
+use File::Find;
+use File::Copy;
+use Digest::MD5;
+
+my @fileTypes = ("cpp", "c");
+my %dirFiles;
+my %dirCMake;
+
+sub GetFiles {
+  my $dir = shift;
+  my $x = $dirFiles{$dir};  
+  if (!defined $x) {
+    $x = [];
+    $dirFiles{$dir} = $x;
+  }  
+  return $x;
+}
+
+sub ProcessFile {
+  my $file = $_;
+  my $dir = $File::Find::dir;
+  # Record if a CMake file was found.
+  if ($file eq "CMakeLists.txt") {
+    $dirCMake{$dir} = $File::Find::name;
+    return 0;
+  }
+  # Grab the extension of the file.
+  $file =~ /\.([^.]+)$/;
+  my $ext = $1;
+  my $files;
+  foreach my $x (@fileTypes) {
+    if ($ext eq $x) {
+      if (!defined $files) {
+        $files = GetFiles($dir);
+      }
+      push @$files, $file;
+      return 0;
+    }
+  }
+  return 0;
+}
+
+sub EmitCMakeList {
+  my $dir = shift;
+  my $files = $dirFiles{$dir};
+  
+  if (!defined $files) {
+    return;
+  }
+  
+  foreach my $file (sort @$files) {
+    print OUT "  ";
+    print OUT $file;
+    print OUT "\n";
+  }  
+}
+
+sub UpdateCMake {
+  my $cmakeList = shift;
+  my $dir = shift;
+  my $cmakeListNew = $cmakeList . ".new";
+  open(IN, $cmakeList);
+  open(OUT, ">", $cmakeListNew);
+  my $foundLibrary = 0;
+  
+  while(<IN>) {
+    if (!$foundLibrary) {
+      print OUT $_;
+      if (/^add_clang_library\(/ || /^add_llvm_library\(/) {
+        $foundLibrary = 1;
+        EmitCMakeList($dir);
+      }
+    }
+    else {
+      if (/\)/) {
+        print OUT $_;
+        $foundLibrary = 0;
+      }
+    }
+  }
+
+  close(IN);
+  close(OUT);
+
+  open(FILE, $cmakeList) or
+    die("Cannot open $cmakeList when computing digest\n");
+  binmode FILE;
+  my $digestA = Digest::MD5->new->addfile(*FILE)->hexdigest;
+  close(FILE);
+    
+  open(FILE, $cmakeListNew) or
+    die("Cannot open $cmakeListNew when computing digest\n");
+  binmode FILE;
+  my $digestB = Digest::MD5->new->addfile(*FILE)->hexdigest;
+  close(FILE);
+  
+  if ($digestA != $digestB) {
+    move($cmakeListNew, $cmakeList);
+    return 1;    
+  }
+  
+  unlink($cmakeListNew);
+  return 0;
+}
+
+sub UpdateCMakeFiles {
+  foreach my $dir (sort keys %dirCMake) {
+    if (UpdateCMake($dirCMake{$dir}, $dir)) {
+      print "Updated: $dir\n";
+    }
+  }
+}
+
+find({ wanted => \&ProcessFile, follow => 1 }, '.');
+UpdateCMakeFiles();
+

Propchange: llvm/trunk/utils/UpdateCMakeLists.pl

------------------------------------------------------------------------------
    svn:executable = *





More information about the llvm-commits mailing list