Home | History | Annotate | Download | only in scripts
      1 #!/usr/bin/perl
      2 
      3 # This script should be pointed to a valid llvm.build folder that
      4 # was created using the "build-llvm.pl" shell script. It will create
      5 # a new llvm.zip file that can be checked into the respository
      6 # at lldb/llvm.zip
      7 
      8 use strict;
      9 use Cwd 'abs_path';
     10 use File::Basename;
     11 use File::Temp qw/ tempfile tempdir /;
     12 our $debug = 1;
     13 
     14 
     15 sub do_command
     16 {
     17 	my $cmd = shift;
     18 	my $description = @_ ? shift : "command";
     19 	my $die_on_fail = @_ ? shift : undef;
     20 	$debug and print "% $cmd\n";
     21 	system ($cmd);
     22 	if ($? == -1) 
     23 	{
     24         $debug and printf ("error: %s failed to execute: $!\n", $description);
     25 		$die_on_fail and $? and exit(1);
     26 		return $?;
     27     }
     28     elsif ($? & 127) 
     29 	{
     30         $debug and printf("error: %s child died with signal %d, %s coredump\n", 
     31 						  $description, 
     32 						  ($? & 127),  
     33 						  ($? & 128) ? 'with' : 'without');
     34 		$die_on_fail and $? and exit(1);
     35 		return $?;
     36     }
     37     else 
     38 	{
     39 		my $exit = $? >> 8;
     40 		if ($exit)
     41 		{
     42 			$debug and printf("error: %s child exited with value %d\n", $description, $exit);
     43 			$die_on_fail and exit(1);
     44 		}
     45 		return $exit;
     46     }
     47 }
     48 
     49 sub do_rsync_paths
     50 {
     51     while (@_)
     52 	{
     53 		my $rsync_src = shift @_;
     54 		my $rsync_dst = shift @_;
     55 		print "rsync_src = '$rsync_src'\n";
     56 		print "rsync_dst = '$rsync_dst'\n";
     57         
     58         if (!-d $rsync_dst)
     59         {
     60             mkdir $rsync_dst;
     61         }
     62         
     63 		if (-e $rsync_src)
     64 		{
     65 			my ($rsync_dst_file, $rsync_dst_dir) = fileparse ($rsync_dst);
     66 			print "rsync_dst_dir = '$rsync_dst_dir'\n";
     67 			-e $rsync_dst_dir or do_command ("mkdir -p '$rsync_dst_dir'");			
     68 			do_command ("rsync -amvC --exclude='*.tmp' --exclude='*.txt' --exclude='*.TXT' --exclude='*.td' --exclude='\.dir' --exclude=Makefile '$rsync_src' '$rsync_dst'");
     69 		}
     70         else
     71         {
     72             die "$rsync_src does not exist!\n";
     73         }
     74 	}
     75 }
     76 
     77 if (@ARGV > 4)
     78 {
     79 	my $llvm_source_dir = abs_path(shift @ARGV);	# The llvm source that contains full llvm and clang sources
     80 	my $llvm_build_dir  = abs_path(shift @ARGV);     # The llvm build directory that contains headers and 
     81 	my $lldb_build_dir  = abs_path(shift @ARGV);     # the build directory that contains the fat libEnhancedDisassembly.dylib
     82 	my $llvm_zip_file   = abs_path(shift @ARGV);
     83 
     84     printf("LLVM sources : '%s'\n", $llvm_source_dir);
     85     printf("LLVM build   : '%s'\n", $llvm_build_dir);
     86     printf("LLDB build   : '%s'\n", $lldb_build_dir);
     87     printf("LLVM zip file: '%s'\n", $llvm_zip_file);
     88 
     89 	-e $llvm_build_dir or die "LLVM build directory doesn't exist: '$llvm_build_dir': $!\n";
     90 
     91 	my $temp_dir = tempdir( CLEANUP => 1 );
     92 	print "temp dir = '$temp_dir'\n";
     93   	my $llvm_checkpoint_dir = "$temp_dir/llvm";
     94 	mkdir "$llvm_checkpoint_dir" or die "Couldn't make 'llvm' in '$temp_dir'\n";
     95 	
     96 	my @generic_rsync_src_dst_paths =
     97 	(
     98 		"$llvm_source_dir/include", "$llvm_checkpoint_dir",
     99 		"$llvm_source_dir/tools/clang/include", "$llvm_checkpoint_dir/tools/clang",
    100 	);
    101     
    102     do_rsync_paths (@generic_rsync_src_dst_paths);
    103 
    104 	for my $arch (@ARGV)
    105     {
    106         my @specific_rsync_src_dst_paths =
    107         (
    108             "$llvm_build_dir/$arch/include", "$llvm_checkpoint_dir/$arch",
    109             "$llvm_build_dir/$arch/tools/clang/include", "$llvm_checkpoint_dir/$arch/tools/clang",
    110         );
    111         
    112         do_rsync_paths (@specific_rsync_src_dst_paths);
    113 
    114         do_command ("cp '$llvm_build_dir/$arch/libllvmclang.a' '$llvm_checkpoint_dir/$arch/libllvmclang.a'", "Copying .a file", 1);
    115 
    116     }
    117 
    118 	#do_command ("cp '$llvm_build_dir/libllvmclang.a' '$llvm_checkpoint_dir'", "Copying libllvmclang.a", 1);
    119 	do_command ("rm -rf '$llvm_zip_file'", "Removing old llvm checkpoint file '$llvm_zip_file'", 1);
    120 	do_command ("(cd '$temp_dir' ; zip -r '$llvm_zip_file' 'llvm')", "Zipping llvm checkpoint directory '$llvm_checkpoint_dir' to '$llvm_zip_file'", 1);
    121 }
    122 else
    123 {
    124 	print "USAGE\n\tcheckpoint-llvm.pl <llvm-sources> <llvm-build> <lldb-build> <llvm-zip> <arch1> [<arch2> ...]\n\n";
    125 	print "EXAMPLE\n\tcd lldb\n\t./scripts/checkpoint-llvm.pl llvm build/llvm build/BuildAndIntegration llvm.zip x86_64 i386\n";
    126 }
    127