[Libreoffice-commits] .: Branch 'libreoffice-3-5' - bin/lo-pack-sources

Petr Mladek pmladek at kemper.freedesktop.org
Tue Dec 13 06:29:28 PST 2011


 bin/lo-pack-sources |  134 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 79 insertions(+), 55 deletions(-)

New commits:
commit 44b671fac456af63a85fe3ee61438fc0046c7099
Author: Petr Mladek <pmladek at suse.cz>
Date:   Tue Dec 13 15:18:10 2011 +0100

    lo-pack-sources: allow to generate .xz source tarballs by default
    
    Add --bzip2 and --xz options to select the compression. Both options
    can be used togetger to generate both types of tarballs in one call.
    XZ compession is used by default.
    
    Also renamed "lo*build" strings to "lo*core" to fit the current name
    of the top level source directory.

diff --git a/bin/lo-pack-sources b/bin/lo-pack-sources
index 1ecf2b7..d1786d3 100755
--- a/bin/lo-pack-sources
+++ b/bin/lo-pack-sources
@@ -10,11 +10,11 @@ use File::Temp qw/ tempfile tempdir /;
 # get libreoffice-build version from the given libreoffice-build sources
 sub get_config_version($)
 {
-    my ($lo_build_dir) = @_;
+    my ($lo_core_dir) = @_;
     my $version;
 
-    open (CONFIGURE, "$lo_build_dir/configure.in") ||
-        die "can't open \"$lo_build_dir/configure.in\" for reading: $!\n";
+    open (CONFIGURE, "$lo_core_dir/configure.in") ||
+        die "can't open \"$lo_core_dir/configure.in\" for reading: $!\n";
 
     while (my $line = <CONFIGURE>) {
         chomp $line;
@@ -177,32 +177,32 @@ sub generate_version_file($$$)
     close VERFILE;
 }
 
-sub release_lo_piece($$)
+sub generate_tarball($$$)
 {
-    my ($lo_piece_dir, $piece_tarball_name) = @_;
+    my ($dir, $tarball, $tar_compress_option) = @_;
 
-    print "Creating $piece_tarball_name.tar.bz2...";
-    system ("cd $lo_piece_dir && " .
-            "tar -cjf $piece_tarball_name.tar.bz2 --checkpoint * 2>&1 | awk '{ ORS=\"\" ; if (++nlines\%50 == 0) printf \".\"; fflush() }' && " .
+    print "Creating $tarball...";
+    system ("cd $dir && " .
+            "tar -c $tar_compress_option -f $tarball --checkpoint * 2>&1 | awk '{ ORS=\"\" ; if (++nlines\%50 == 0) printf \".\"; fflush() }' && " .
             "cd - >/dev/null 2>&1") && die "Error: releasing failed: $!\n";
     print "\n";
 }
 
-sub generate_md5($$$)
+sub generate_md5($$)
 {
-    my ($dir, $tarball_name, $tarball_suffix) = @_;
+    my ($dir, $filename) = @_;
 
     print "Generating MD5...\n";
     system ("cd $dir && " .
-            "md5sum $tarball_name$tarball_suffix >$tarball_name$tarball_suffix.md5 && " .
+            "md5sum $filename >$filename.md5 && " .
             "cd - >/dev/null 2>&1") && die "Error: releasing failed: $!\n";
 }
 
 sub default_releases_state_file($)
 {
-    my ($lo_build_dir) = @_;
+    my ($lo_core_dir) = @_;
 
-    my $rootdir = $lo_build_dir;
+    my $rootdir = $lo_core_dir;
     $rootdir =~ s/^(.*?)\/?[^\/]+\/?$/$1/;
 
     my $releases_state_file;
@@ -217,9 +217,9 @@ sub default_releases_state_file($)
 
 sub default_releases_archive($)
 {
-    my ($lo_build_dir) = @_;
+    my ($lo_core_dir) = @_;
 
-    my $rootdir = $lo_build_dir;
+    my $rootdir = $lo_core_dir;
     $rootdir =~ s/^(.*?)\/?[^\/]+\/?$/$1/;
 
     my $releases_archive_dir;
@@ -318,36 +318,39 @@ sub check_if_tarball_already_released($$$)
     check_if_file_exists("$releases_archive_dir/$tarball", $force) if (defined $releases_archive_dir);
 }
 
-sub check_if_already_released($$$$$$)
+sub check_if_already_released($$$$$$$$)
 {
-    my ($lo_build_tarball_name, $p_piece_tarball_name, $releases_archive_dir, $force, $pack_lo_build, $pack_lo_pieces) = @_;
+    my ($lo_core_tarball_name, $p_piece_tarball_name, $releases_archive_dir, $force, $bzip2, $xz, $pack_lo_core, $pack_lo_pieces) = @_;
 
-    check_if_tarball_already_released("$lo_build_tarball_name.tar.gz", $releases_archive_dir, $force) if ($pack_lo_build);
+    check_if_tarball_already_released("$lo_core_tarball_name.tar.gz", $releases_archive_dir, $force) if ($pack_lo_core);
 
     if ($pack_lo_pieces) {
         foreach my $tarball_name ( values %{$p_piece_tarball_name} ) {
-            check_if_tarball_already_released("$tarball_name.tar.bz2", $releases_archive_dir, $force);
+            check_if_tarball_already_released("$tarball_name.tar.bz2", $releases_archive_dir, $force) if (defined $bzip2);
+            check_if_tarball_already_released("$tarball_name.tar.xz", $releases_archive_dir, $force) if (defined $xz);
         }
     }
 }
 
-sub prepare_lo_piece_tarball($$$$$)
+sub prepare_piece_sources($$$$)
 {
-    my ($piece_dir, $release_version, $md5, $piece, $piece_tarball_name) = @_;
+    my ($piece_dir, $release_version, $piece, $piece_tarball_name) = @_;
 
+    # prepare sources
     my $temp_dir = copy_lo_piece_to_tempdir($piece_dir, $piece, $piece_tarball_name);
     generate_lo_piece_changelog($piece_dir, "$temp_dir/$piece_tarball_name", $piece);
     run_autoreconf("$temp_dir/$piece_tarball_name", $piece) if ($piece eq 'core');
     generate_version_file("$temp_dir/$piece_tarball_name", $piece, $release_version) if ($piece eq 'core');
-    release_lo_piece($temp_dir, $piece_tarball_name);
-    generate_md5($temp_dir, $piece_tarball_name, ".tar.bz2") if (defined $md5);
 
     return $temp_dir;
 }
 
-sub move_tarball_to_final_location($$$$)
+sub pack_piece_sources($$$$$)
 {
-    my ($temp_dir, $releases_archive_dir, $md5, $tarball) = @_;
+    my ($temp_dir, $md5, $tarball, $tar_compress_option, $releases_archive_dir) = @_;
+
+    generate_tarball($temp_dir, $tarball, $tar_compress_option);
+    generate_md5($temp_dir, $tarball) if (defined $md5);
 
     save_file($temp_dir, ".", "$tarball");
     save_file($temp_dir, ".", "$tarball.md5") if (defined $md5);
@@ -355,30 +358,37 @@ sub move_tarball_to_final_location($$$$)
         save_file($temp_dir, $releases_archive_dir, "$tarball");
         save_file($temp_dir, $releases_archive_dir, "$tarball.md5") if (defined $md5);
     }
+    unlink ("$temp_dir/$tarball");
+    unlink ("$temp_dir/$tarball.md5") if (defined $md5);
+}
 
+sub generate_piece_tarball($$$$$$$$)
+{
+    my ($piece_dir, $release_version, $piece, $md5, $bzip2, $xz, $piece_tarball_name, $releases_archive_dir) = @_;
+
+    my $temp_dir = prepare_piece_sources($piece_dir, $release_version, $piece, $piece_tarball_name);
+    pack_piece_sources($temp_dir, $md5, "$piece_tarball_name.tar.bz2", "--bzip2", $releases_archive_dir) if (defined $bzip2);
+    pack_piece_sources($temp_dir, $md5, "$piece_tarball_name.tar.xz", "--xz", $releases_archive_dir) if (defined $xz);
     remove_tempdir($temp_dir);
 }
 
 
-sub generate_tarballs($$$$$$$$$)
+sub generate_tarballs($$$$$$$$$$$)
 {
-    my ($source_dir, $releases_archive_dir, $release_version, $md5, $lo_build_tarball_name, $p_piece_tarball_name, $pack_lo_build, $pack_lo_pieces, $is_lo_build_dir) = @_;
+    my ($source_dir, $releases_archive_dir, $release_version, $md5, $bzip2, $xz, $lo_core_tarball_name, $p_piece_tarball_name, $pack_lo_core, $pack_lo_pieces, $is_lo_core_dir) = @_;
 
-    if ($pack_lo_build) {
-        my $temp_dir=prepare_lo_piece_tarball($source_dir, $release_version, $md5, "core", $lo_build_tarball_name);
-        move_tarball_to_final_location($temp_dir, $releases_archive_dir, $md5, "$lo_build_tarball_name.tar.bz2");
+    if ($pack_lo_core) {
+        generate_piece_tarball($source_dir, $release_version, "core", $md5, $bzip2, $xz, $lo_core_tarball_name, $releases_archive_dir);
     }
 
     if ($pack_lo_pieces) {
         my $piece_dir = $source_dir;
         foreach my $piece ( keys %{$p_piece_tarball_name} ) {
             print "\n--- Generating $piece ---\n";
-            $piece_dir = "$source_dir/clone/$piece" if ($is_lo_build_dir);
-            my $temp_dir=prepare_lo_piece_tarball($piece_dir, $release_version, $md5, $piece, $p_piece_tarball_name->{$piece});
-            move_tarball_to_final_location($temp_dir, $releases_archive_dir, $md5, "$p_piece_tarball_name->{$piece}.tar.bz2");
+            $piece_dir = "$source_dir/clone/$piece" if ($is_lo_core_dir);
+            generate_piece_tarball($piece_dir, $release_version, $piece, $md5, $bzip2, $xz, $p_piece_tarball_name->{$piece}, $releases_archive_dir);
         }
     }
-
 }
 
 
@@ -387,47 +397,54 @@ sub usage()
     print "This tool helps to pack the libreoffice-build and piece sources\n\n" .
 
           "Usage:\n".
-          "\tlo-pack-sources [--help] [--force] [--version]\n" .
-          "\t [--set-version=<ver>] [--inc-version] [--md5]\n" .
-          "\t [--no-lo-build] [--no-lo-pieces] [--piece=<piece>]\n" .
+          "\tlo-pack-sources [--help]\n" .
+          "\t  [--force] [--md5] [--bzip2] [--xz]\n" .
+          "\t [--version][--set-version=<ver>] [--inc-version]\n" .
+          "\t [--no-lo-core] [--no-lo-pieces] [--piece=<piece>]\n" .
           "\t [dir]\n\n" .
 
           "Options:\n\n" .
           "\t--help: print this help\n" .
           "\t--force: replace an already existing release of the same version\n" .
+          "\t--md5: generate md5 sum for the final tarball\n" .
+          "\t--bzip2: generate tarballs compressed by bzip2\n" .
+          "\t--xz: generate tarballs compressed by xz (default)\n" .
+          "\t--md5: generate md5 sum for the final tarball\n" .
+          "\t--md5: generate md5 sum for the final tarball\n" .
           "\t--version: just print version of the released package but do not\n" .
           "\t\trelease it; the version is affected by the other options, e.g.\n" .
           "\t\t--inc-version\n" .
           "\t--set-version: force another version\n" .
           "\t--inc-version: increment the latest version; there is a difference\n" .
           "\t\tbetween test release (default) and final (not yet supported)\n" .
-          "\t--md5: generate md5 sum for the final tarball\n" .
-          "\t--no-lo-build: do not pack the libreoffice-build tarball\n" .
-          "\t--no-lo-pieces: do not pack the libreoffice-build piece sources\n" .
-          "\t--piece=<piece>: pack just a single piece, .e.g. \"writer\",\n" .
+          "\t--no-lo-core: do not pack the libreoffice-core tarball\n" .
+          "\t--no-lo-pieces: do not pack the extra LO piece sources\n" .
+          "\t--piece=<piece>: pack just a single piece, .e.g. \"help\",\n" .
           "\tdir: path of the source directory, either libreoffice-build or piece\n";
 }
 
 
 my $ptf;
 my $md5;
+my $bzip2;
+my $xz;
 my $inc_version;
 my $config_version;
 my $set_version;
 my $get_config_version;
 my $release_version;
-my $pack_lo_build=1;
+my $pack_lo_core=1;
 my $pack_lo_pieces=1;
 my $source_dir;
 my $releases_archive_dir;
 my $releases_state_file;
 my $state_config_version;
 my $state_release_version;
-my $lo_build_tarball_name;
-my $lo_build_tempdir;
+my $lo_core_tarball_name;
+my $lo_core_tempdir;
 my $force;
 my $verbose=1;
-my $is_lo_build_dir=0;
+my $is_lo_core_dir=0;
 my @pieces=("binfilter", "dictionaries", "help", "translations");
 my %piece_tarball_name;
 
@@ -443,6 +460,10 @@ for my $arg (@ARGV) {
         $force=1;
     } elsif ($arg eq '--md5') {
         $md5=1;
+    } elsif ($arg eq '--bzip2') {
+        $bzip2=1;
+    } elsif ($arg eq '--xz') {
+        $xz=1;
     } elsif ($arg eq '--version') {
         $get_config_version=1;
         $verbose = undef;
@@ -450,15 +471,15 @@ for my $arg (@ARGV) {
         $inc_version=1
     } elsif ($arg =~ m/--set-version=(.*)/) {
           $set_version="$1";
-    } elsif ($arg eq '--no-lo-build') {
-        $pack_lo_build=0;
+    } elsif ($arg eq '--no-lo-core') {
+        $pack_lo_core=0;
     } elsif ($arg eq '--no-lo-pieces') {
         $pack_lo_pieces=0;
     } elsif ($arg =~ m/--piece=(.*)/) {
           # process just one piece and do not pack libreoffice-build
           @pieces=();
           push @pieces, "$1";
-          $pack_lo_build=0;
+          $pack_lo_core=0;
     } elsif ($arg =~ /^-/ ) {
         die "Error: unknown option: $arg\n";
     } else {
@@ -483,15 +504,15 @@ unless ( -d "$source_dir" ) {
 }
 
 # check if it is a valid libreoffice-core directory
-$is_lo_build_dir=1 if (-f "$source_dir/autogen.sh" && -f "$source_dir/set_soenv.in");
+$is_lo_core_dir=1 if (-f "$source_dir/autogen.sh" && -f "$source_dir/set_soenv.in");
 
 # all tarballs are generated from the libreoffice-core directory
-if (@pieces > 1 && $is_lo_build_dir == 0 ) {
+if (@pieces > 1 && $is_lo_core_dir == 0 ) {
     die "Error: \"$source_dir\" is not a valid libreoffice-core directory\n";
 }
 
 # just a single piece tarball can be generated from piece directory; version must be explicitly set in this case
-if (@pieces == 1  &&  $is_lo_build_dir == 0  &&  ! defined $set_version ) {
+if (@pieces == 1  &&  $is_lo_core_dir == 0  &&  ! defined $set_version ) {
     die "Error: version must be set using the --set-version=<version> option\n" unless (defined $set_version);
 }
 
@@ -499,6 +520,9 @@ if (defined $set_version && defined $inc_version) {
     die "Error: --set-version and --inc-version options can't be used together\n";
 }
 
+# default compression
+$xz = 1 unless (defined $xz || defined $bzip2);
+
 
 ###################
 # Main logic
@@ -507,7 +531,7 @@ if (defined $set_version && defined $inc_version) {
 
 print "Source: $source_dir\n" if ($verbose);
 
-if ($is_lo_build_dir) {
+if ($is_lo_core_dir) {
     # detect some paths
     $releases_state_file = default_releases_state_file($source_dir) unless (defined $releases_state_file);
     $releases_archive_dir = default_releases_archive($source_dir) unless (defined $releases_archive_dir);
@@ -526,7 +550,7 @@ if ($is_lo_build_dir) {
 }
 
 # define tarball names
-$lo_build_tarball_name = "libreoffice-core-$release_version";
+$lo_core_tarball_name = "libreoffice-core-$release_version";
 foreach my $piece (@pieces) {
     if (-d "$source_dir/clone/$piece") {
         $piece_tarball_name{$piece} = "libreoffice-$piece-$release_version";
@@ -543,13 +567,13 @@ print "New version       : $release_version\n" if ($verbose);
 if ( defined $get_config_version ) {
     print "$release_version\n";
 } else {
-    check_if_already_released($lo_build_tarball_name, \%piece_tarball_name, $releases_archive_dir, $force, $pack_lo_build, $pack_lo_pieces);
+    check_if_already_released($lo_core_tarball_name, \%piece_tarball_name, $releases_archive_dir, $force, $bzip2, $xz, $pack_lo_core, $pack_lo_pieces);
 
     # give a chance to stop the process
     print ("\nWaiting 3 seconds...\n");
     sleep 3;
 
-    generate_tarballs($source_dir, $releases_archive_dir, $release_version, $md5, $lo_build_tarball_name, \%piece_tarball_name, $pack_lo_build, $pack_lo_pieces, $is_lo_build_dir);
+    generate_tarballs($source_dir, $releases_archive_dir, $release_version, $md5, $bzip2, $xz, $lo_core_tarball_name, \%piece_tarball_name, $pack_lo_core, $pack_lo_pieces, $is_lo_core_dir);
 
     if ( defined $releases_state_file ) {
         save_releases_state($releases_state_file, $config_version, $release_version);


More information about the Libreoffice-commits mailing list