|
| 1 | +#!/usr/bin/env perl |
| 2 | +# |
| 3 | +# (C) 2008 by Argonne National Laboratory. |
| 4 | +# See COPYRIGHT in top-level directory. |
| 5 | +# |
| 6 | + |
| 7 | +use strict; |
| 8 | +use warnings; |
| 9 | + |
| 10 | +use Cwd qw( cwd getcwd realpath ); |
| 11 | +use Getopt::Long; |
| 12 | +use File::Temp qw( tempdir ); |
| 13 | + |
| 14 | +my $arg = 0; |
| 15 | +my $branch = ""; |
| 16 | +my $version = ""; |
| 17 | +my $append_commit_id; |
| 18 | +my $root = cwd(); |
| 19 | +my $with_autoconf = ""; |
| 20 | +my $with_automake = ""; |
| 21 | +my $git_repo = ""; |
| 22 | +my $with_mpi = ""; |
| 23 | + |
| 24 | +my $logfile = "release.log"; |
| 25 | + |
| 26 | +sub usage |
| 27 | +{ |
| 28 | + print "Usage: $0 [OPTIONS]\n\n"; |
| 29 | + print "OPTIONS:\n"; |
| 30 | + |
| 31 | + print "\t--git-repo path to root of the git repository (required)\n"; |
| 32 | + print "\t--branch git branch to be packaged (required)\n"; |
| 33 | + print "\t--version tarball version (required)\n"; |
| 34 | + print "\t--with-mpi mpi installation (optional)\n"; |
| 35 | + print "\t--append-commit-id append git commit description (optional)\n"; |
| 36 | + |
| 37 | + print "\n"; |
| 38 | + |
| 39 | + exit 1; |
| 40 | +} |
| 41 | + |
| 42 | +sub check_package |
| 43 | +{ |
| 44 | + my $pack = shift; |
| 45 | + |
| 46 | + print "===> Checking for package $pack... "; |
| 47 | + if (`which $pack` eq "") { |
| 48 | + print "not found\n"; |
| 49 | + exit; |
| 50 | + } |
| 51 | + print "done\n"; |
| 52 | +} |
| 53 | + |
| 54 | + |
| 55 | +sub check_autotools_version |
| 56 | +{ |
| 57 | + my $tool = shift; |
| 58 | + my $req_ver = shift; |
| 59 | + my $curr_ver; |
| 60 | + |
| 61 | + $curr_ver = `$tool --version | head -1 | cut -f4 -d' ' | xargs echo -n`; |
| 62 | + if ("$curr_ver" ne "$req_ver") { |
| 63 | + print("\tERROR: $tool version mismatch ($req_ver) required\n\n"); |
| 64 | + exit; |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +# will also chdir to the top level of the git repository |
| 69 | +sub check_git_repo { |
| 70 | + my $repo_path = shift; |
| 71 | + |
| 72 | + print "===> chdir to $repo_path\n"; |
| 73 | + chdir $repo_path; |
| 74 | + |
| 75 | + print "===> Checking git repository sanity... "; |
| 76 | + unless (`git rev-parse --is-inside-work-tree 2> /dev/null` eq "true\n") { |
| 77 | + print "ERROR: $repo_path is not a git repository\n"; |
| 78 | + exit 1; |
| 79 | + } |
| 80 | + # I'm not strictly sure that this is true, but it's not too burdensome right |
| 81 | + # now to restrict it to complete (non-bare repositories). |
| 82 | + unless (`git rev-parse --is-bare-repository 2> /dev/null` eq "false\n") { |
| 83 | + print "ERROR: $repo_path is a *bare* repository (need working tree)\n"; |
| 84 | + exit 1; |
| 85 | + } |
| 86 | + |
| 87 | + print "done\n"; |
| 88 | +} |
| 89 | + |
| 90 | + |
| 91 | +sub run_cmd |
| 92 | +{ |
| 93 | + my $cmd = shift; |
| 94 | + |
| 95 | + #print("===> running cmd=|$cmd| from ".getcwd()."\n"); |
| 96 | + system("$cmd >> $root/$logfile 2>&1"); |
| 97 | + if ($?) { |
| 98 | + die "unable to execute ($cmd), \$?=$?. Stopped"; |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +GetOptions( |
| 103 | + "branch=s" => \$branch, |
| 104 | + "version=s" => \$version, |
| 105 | + "append-commit-id!" => \$append_commit_id, |
| 106 | + "with-autoconf" => \$with_autoconf, |
| 107 | + "with-automake" => \$with_automake, |
| 108 | + "git-repo=s" => \$git_repo, |
| 109 | + "with-mpi=s" => \$with_mpi, |
| 110 | + "help" => \&usage, |
| 111 | +) or die "unable to parse options, stopped"; |
| 112 | + |
| 113 | +if (scalar(@ARGV) != 0) { |
| 114 | + usage(); |
| 115 | +} |
| 116 | + |
| 117 | +if (!$branch || !$version) { |
| 118 | + usage(); |
| 119 | +} |
| 120 | + |
| 121 | +check_package("git"); |
| 122 | +check_package("autoconf"); |
| 123 | +check_package("automake"); |
| 124 | +check_package("libtool"); |
| 125 | +print("\n"); |
| 126 | + |
| 127 | +## IMPORTANT: Changing the autotools versions can result in ABI |
| 128 | +## breakage. So make sure the ABI string in the release tarball is |
| 129 | +## updated when you do that. |
| 130 | +check_autotools_version("autoconf", "2.69"); |
| 131 | +check_autotools_version("automake", "1.15"); |
| 132 | +check_autotools_version("libtool", "2.4.6"); |
| 133 | +print("\n"); |
| 134 | + |
| 135 | +my $tdir = tempdir(CLEANUP => 1); |
| 136 | +my $local_git_clone = "${tdir}/oshmpi-clone"; |
| 137 | + |
| 138 | +# clone git repo |
| 139 | +print("===> Cloning git repo... "); |
| 140 | +run_cmd("git clone ${git_repo} -b ${branch} --recursive ${local_git_clone}"); |
| 141 | +print("done\n"); |
| 142 | + |
| 143 | +# chdirs to $local_git_clone if valid |
| 144 | +check_git_repo($local_git_clone); |
| 145 | +print("\n"); |
| 146 | + |
| 147 | +my $current_ver = `git show ${branch}:maint/version.m4 | grep OSHMPI_VERSION_m4 | \ |
| 148 | + sed -e 's/^.*\\[OSHMPI_VERSION_m4\\],\\[\\(.*\\)\\].*/\\1/g'`; |
| 149 | +if ("$current_ver" ne "$version\n") { |
| 150 | + print("\tWARNING: maint/version does not match user version\n\n"); |
| 151 | +} |
| 152 | + |
| 153 | +if ($append_commit_id) { |
| 154 | + my $desc = `git describe --always ${branch}`; |
| 155 | + chomp $desc; |
| 156 | + $version .= "-${desc}"; |
| 157 | +} |
| 158 | + |
| 159 | +# apply patches to submodules |
| 160 | +#print("===> Patching submodules... "); |
| 161 | +#run_cmd("./maint/apply_patch.bash"); |
| 162 | + |
| 163 | +my $expdir = "${tdir}/oshmpi-${version}"; |
| 164 | + |
| 165 | +# Clean up the log file |
| 166 | +system("rm -f ${root}/$logfile"); |
| 167 | + |
| 168 | +# Check out the appropriate branch |
| 169 | +print("===> Exporting code from git... "); |
| 170 | +run_cmd("rm -rf ${expdir}"); |
| 171 | +run_cmd("mkdir -p ${expdir}"); |
| 172 | +run_cmd("git archive ${branch} --prefix='oshmpi-${version}/' | tar -x -C $tdir"); |
| 173 | +run_cmd("git submodule foreach --recursive \'git archive HEAD --prefix='' | tar -x -C `echo \${toplevel}/\${path} | sed -e s/clone/${version}/`'"); |
| 174 | +print("done\n"); |
| 175 | + |
| 176 | +print("===> Create release date and version information... "); |
| 177 | +chdir($local_git_clone); |
| 178 | +my $date = `git log -1 --format=%ci`; |
| 179 | +chomp $date; |
| 180 | + |
| 181 | +chdir($expdir); |
| 182 | +system(qq(perl -p -i -e 's/\\[OSHMPI_RELEASE_DATE_m4\\],\\[unreleased development copy\\]/[OSHMPI_RELEASE_DATE_m4],[$date]/g' ./maint/version.m4)); |
| 183 | +print("done\n"); |
| 184 | + |
| 185 | +# Remove content that is not being released |
| 186 | +print("===> Removing content that is not being released... "); |
| 187 | +chdir($expdir); |
| 188 | +print("done\n"); |
| 189 | + |
| 190 | +# Create configure |
| 191 | +print("===> Creating configure in the main codebase... "); |
| 192 | +chdir($expdir); |
| 193 | +{ |
| 194 | + my $cmd = "./autogen.sh"; |
| 195 | + run_cmd($cmd); |
| 196 | +} |
| 197 | +print("done\n"); |
| 198 | + |
| 199 | +# Execute configure and make dist |
| 200 | +print("===> Running configure... "); |
| 201 | +run_cmd("./configure --prefix=$expdir/install CC=$with_mpi/bin/mpicc"); |
| 202 | +print("done\n"); |
| 203 | + |
| 204 | +print("===> Making the final tarball... "); |
| 205 | +run_cmd("make dist"); |
| 206 | +run_cmd("cp -a oshmpi-${version}.tar.gz ${root}/"); |
| 207 | +print("done\n"); |
| 208 | + |
| 209 | +# make sure we are outside of the tempdir so that the CLEANUP logic can run |
| 210 | +chdir("${tdir}/.."); |
0 commit comments