cgal/Packages/Maintenance/release_building/create_release

426 lines
12 KiB
Plaintext
Executable File

#!/net/bin/perl5
use strict;
use Cwd;
use File::Copy;
use File::Basename;
use File::Find;
#
# This script creates an internal release for CGAL.
#----------------------------------------------------------------#
# initialization #
#----------------------------------------------------------------#
$::TEMPFILE="TEMPFILE.$$";
@::package_versions = ();
$::TESTING = 0;
if ($::TESTING) {
$::PACKAGEDIR='/users/geert/CGAL/tmp/packages';
$::ALL_RESULTS_DIR='/users/geert/CGAL/tmp/results';
$::LOCKFILE='/users/geert/CGAL/tmp/collect_submission.lock';
$::last_version_file = '/users/geert/CGAL/tmp/last_internal_release';
} else {
$::PACKAGEDIR='/users/www/CGAL/Members/Develop/updates/packages';
$::ALL_RESULTS_DIR='/users/www/CGAL/Members/Develop/testsuite';
$::LOCKFILE='/projects/CGAL/submissions/autohandle/data/collect_submission.lock';
$::last_version_file = '/projects/CGAL/lib/last_internal_release';
}
$::SCRIPTDIR=
'/users/www/CGAL/Members/Develop/scripts';
$::MISCPACKAGEDIR=
'/users/www/CGAL/Members/Develop/updates/packages';
$::LOCKCMD=
'/projects/CGAL/submissions/autohandle/scripts/lockfile';
#----------------------------------------------------------------#
# unzip_files #
#----------------------------------------------------------------#
#
# unzip_files <zipfile> <directories>
#
sub unzip_files($@)
{
my $package = shift;
my ($ITEM, @zip_contents,@to_unzip,$zipped_file);
@zip_contents = `unzip -l $package`;
# remove the first 2 and last 2 lines generated by unzip -l.
shift @zip_contents;
shift @zip_contents;
pop @zip_contents;
pop @zip_contents;
foreach $ITEM (@_) {
foreach $zipped_file (@zip_contents) {
if ( $zipped_file =~ m|(\b$ITEM.*\b)| ) {
push(@to_unzip,($1));
}
}
}
system('unzip', '-qq', $package, @to_unzip);
}
#----------------------------------------------------------------#
# check_and_update_file #
#----------------------------------------------------------------#
sub check_and_update_file($$)
{
my ($filename, $filename_with_dir) = @_;
my $header_type = 0;
my $lines_exceeding_length = 0;
my $has_line_directives = 0;
unlink $::TEMPFILE;
open SOURCE_FILE, "<$filename" || die "Error opening $filename_with_dir: $!\n";
open TEMPFILE, ">$::TEMPFILE" || die;
while ( <SOURCE_FILE> ) {
$header_type = 1
if m|^Copyright \(c\) \d{4](,\s?\d{4})* The CGAL Consortium|;
$header_type = 2
if m|^// Copyright \(c\) \d{4}(,\s?\d{4})* The CGAL Consortium|;
$lines_exceeding_length +=1 if length $_ > 80;
$has_line_directives = 1 if m|^\s*#\s*line\s|;
s<^\s*//\s*file\s*:.*$><// file : $filename_with_dir>;
s<^\s*// release\b.*$><// release : \$CGAL_Revision: $::VERSION \$>;
s<^\s*// release_date.*$><$::release_date>;
print TEMPFILE $_;
}
close SOURCE_FILE || die "Error closing $filename_with_dir: $!";
close TEMPFILE || die "Error closing temporary file: $!\n";
rename($::TEMPFILE, $filename )
|| system('mv', "$::TEMPFILE", "$filename")
|| warn "Could not update file $filename_with_dir\n";
if ($header_type == 0) {
print FILE_CHECKS "$filename_with_dir has unrecognised header.\n";
} elsif ($header_type == 1) {
print FILE_CHECKS "$filename_with_dir has old style header.\n";
}
if ($lines_exceeding_length) {
print FILE_CHECKS "$filename_with_dir has $lines_exceeding_length",
" lines over 80 characters.\n";
}
if ($has_line_directives) {
print FILE_CHECKS "$filename_with_dir has line directives.\n";
}
}
#----------------------------------------------------------------#
# set_file_headers #
#----------------------------------------------------------------#
sub set_file_headers()
{
print "Setting file headers...\n";
chdir $::MAIN_DIR;
$::release_date =
`date '+// release_date : \$CGAL_Date: %Y/%m/%d \$'`;
chomp($::release_date);
open(FILE_CHECKS,">$::PARENT_DIR/code_check_$::VERSION");
find(\&file_header_setting, 'include', 'src', 'config/testfiles');
close FILE_CHECKS;
chdir $::MAIN_DIR;
}
sub file_header_setting
{
my ($filename,$dev,$ino,$mode,$nlink,$uid,$gid,$filetype);
$filename = $_;
if ( ! /\.[h|C]$/ ||
! (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($filename)) ||
! -f _ ) {
return;
}
check_and_update_file($filename, $File::Find::name);
}
#---------------------------------------------------------------#
# set the version information in the config.h include file.
#---------------------------------------------------------------#
sub set_version_in_config()
{
my $V = substr($::VERSION,5);
chdir "$::MAIN_DIR/include/CGAL" or die;
open(SOURCE_FILE, '<config.h') or die "Error opening config.h: $!";
open(TEMPFILE, ">$::TEMPFILE") or die;
while ( <SOURCE_FILE> ) {
s|^\s*\#\s*define\s+CGAL_VERSION\b.*$|#define CGAL_VERSION $V|;
s|^\s*\#\s*define\s*CGAL_VERSION_NR\b.*$|#define CGAL_VERSION_NR $::VERSION_NR|;
print TEMPFILE $_;
}
close SOURCE_FILE || die "Error closing config.h_with_dir: $!";
close TEMPFILE || die "Error closing temporary file: $!\n";
rename($::TEMPFILE, 'config.h' )
|| system('mv', "$::TEMPFILE", 'config.h')
|| warn "Could not update file config.h";
chdir '../..' or die;
}
#---------------------------------------------------------------#
# CreateExampleTestDirs
#---------------------------------------------------------------#
sub CreateExampleTestDirs()
{
my $DIR;
print "Creating example test directories ...\n";
chdir 'examples' or return;
foreach $DIR (glob("*")) {
print "$DIR\n";
if ( -d $DIR ) {
system('cp', '-r', "$DIR", "../test/Examples$DIR");
}
}
chdir '..';
}
#---------------------------------------------------------------#
# list_test_directories
#---------------------------------------------------------------#
# list_test_directories <package>
#
# drukt de testdirectories af die in de submission aanwezig zijn
sub list_test_directories($)
{
my $filename = shift;
my (@zip_contents,$zipped_file,%test_dirs);
@zip_contents = `unzip -l $filename`;
shift @zip_contents;
shift @zip_contents;
pop @zip_contents;
pop @zip_contents;
foreach $zipped_file (@zip_contents) {
if ( $zipped_file =~ m|\btest/([^/\n]+)| ) {
$test_dirs{$1} = 1;
}
}
return keys %test_dirs;
}
#---------------------------------------------------------------#
# install_packages
#---------------------------------------------------------------#
# install_packages
sub install_packages()
{
my ($filenaam, $direc, %is_permitted_package, $package_name);
print "Installing packages ...\n";
open PACKAGES_TO_INCLUDE, "$::PACKAGEDIR/include_in_release" or die;
while (<PACKAGES_TO_INCLUDE>) {
chomp;
s/\s*//g;
next if /^$/;
$is_permitted_package{$_}=1;
}
close PACKAGES_TO_INCLUDE;
opendir PACKAGEDIR, $::PACKAGEDIR or return;
while (defined($package_name = readdir(PACKAGEDIR)) ) {
next unless $is_permitted_package{$package_name};
$filenaam = "$::PACKAGEDIR/$package_name/$package_name.zip";
if (! -f $filenaam) {
print STDERR "WARNING: $filenaam does not exist.\n";
next;
}
print "$filenaam\n";
unzip_files("$filenaam", "include", "test", "examples", "demo", "src", "version","doc_tex");
if (-f 'version') {
open CUR_VERSION, 'version';
while (<CUR_VERSION>) {
next if /^\s*$/;
chomp;
push @::package_versions, "$package_name : $_\n";
last;
}
close CUR_VERSION;
}
foreach $direc ( list_test_directories($filenaam)) {
if ( -f 'version' && -d "test/$direc" && ! -f "test/$direc/version") {
copy('version', "test/$direc");
}
if ( -f 'version' && -d "examples/$direc"
&& ! -f "examples/$direc/version") {
copy('version', "examples/$direc");
}
}
unlink 'version';
}
closedir PACKAGEDIR;
}
#---------------------------------------------------------------#
# install_misc
#---------------------------------------------------------------#
sub install_misc()
{
system 'unzip', '-oqq', "$::MISCPACKAGEDIR/Auxiliary/Auxiliary.zip";
system 'unzip', '-oqq', "$::MISCPACKAGEDIR/Configuration/Configuration.zip";
system 'unzip', '-oqq', "$::MISCPACKAGEDIR/Installation/Installation.zip";
system 'unzip', '-oqq', "$::MISCPACKAGEDIR/Scripts/Scripts.zip";
unlink 'version', 'description.txt', 'long_description.txt', 'changes.txt';
}
#---------------------------------------------------------------#
# make_testscripts
#---------------------------------------------------------------#
sub make_testscripts()
{
my ($DIR, $BASEDIR);
$BASEDIR = cwd();
chdir 'test';
foreach $DIR (glob("*")) {
if ( -d $DIR ) {
print "checking makefile and cgal_test in $DIR\n";
chdir $DIR;
if ( ! -f 'makefile' ) {
print "creating makefile ...\n";
system("$::SCRIPTDIR/create_makefile", '-t');
}
if ( ! -f 'cgal_test' ) {
print "creating cgal_test ...\n";
system("$::SCRIPTDIR/create_cgal_test");
}
chdir '..';
}
}
chdir $BASEDIR;
}
#---------------------------------------------------------------#
# make_results_page
# Create a directory (with subdirectories) where the results are to be put.
# Copy the version files of the packages used for this release to
# the result directories.
#---------------------------------------------------------------#
sub make_results_page()
{
my $direc;
$::THIS_RELEASE_RESULTS = "$::ALL_RESULTS_DIR/$::VERSION";
mkdir "$::THIS_RELEASE_RESULTS", 0775
|| die "Cannot create test results directory";
chdir ("$::MAIN_DIR/test") or return;
foreach $direc (glob("*")) {
if ( -d "$direc" && -f "$direc/version" ) {
mkdir("$::THIS_RELEASE_RESULTS/$direc", 0775);
copy("$direc/version", "$::THIS_RELEASE_RESULTS/$direc")
or warn "Could not copy test/$direc/version to $::THIS_RELEASE_RESULTS/$direc $!";
}
}
}
#---------------------------------------------------------------#
# check_call
#
# checks if this program is called with the right arguments,
# in particular if the version number is high enough.
#---------------------------------------------------------------#
sub wrong_usage()
{
print STDERR "usage: $0 <version-no>\n";
print STDERR " where version-no is <major>-<minor>-<internal>\n";
print STDERR " E.g.: $0 2-3-12\n";
}
sub check_call()
{
my ($major, $minor, $internal);
if ($#ARGV !=0) {
wrong_usage();
exit(1);
}
if ( ($major, $minor, $internal) =
($ARGV[0] =~ m/^(\d{1,3})-(\d{1,3})-(\d{1,2})$/)) {
$major = $major + 0;
$minor = $minor + 0;
$internal = $internal + 0;
$::VERSION_NR = ((1000 + $major)*1000 + $minor)*1000 + $internal;
$::VERSION = "CGAL-$major.$minor-I-$internal";
} else {
wrong_usage();
die "Illegal version number $ARGV[0]";
}
print "Version: $::VERSION ($::VERSION_NR)\n";
open VERSION, $::last_version_file or return;
$_ = <VERSION>;
defined($_) or die "corrupted file $::last_version_file";
close VERSION;
/\s*(\d+)\s*(\d+)\s*(\d+)\s*$/ or die "corrupted file $::last_version_file";
die "major version number too low" if ( $major < $1);
if ($major == $1) {
die "minor version number too low" if ( $minor < $2);
if ($minor == $2) {
die "internal version number too low" if ( $internal <= $3);
}
}
open VERSION, ">$::last_version_file" or die;
print VERSION "$major $minor $internal\n" or die;
close VERSION or die;
}
sub termination_signal_handler {
unlink $::LOCKFILE;
exit 1;
}
sub lock()
{
if (system("$::LOCKCMD", "-r", '10', "$::LOCKFILE") != 0) {
print STDERR <<"TOTHIER";
The script could not proceed because
it could not acquire the needed lock on file $::LOCKFILE.
TOTHIER
exit 1;
}
$SIG{INT} = \&termination_signal_handler;
$SIG{TERM} = \&termination_signal_handler;
}
sub unlock()
{
unlink $::LOCKFILE;
$SIG{INT} = 'DEFAULT';
$SIG{TERM} = 'DEFAULT';
}
$::PARENT_DIR=cwd();
umask(002);
if ($::PARENT_DIR ne '/private/CGAL') {
die "$0 should only be called from directory /private/CGAL on goya.\n";
}
check_call;
mkdir "$::VERSION",0775 or die;
open VERSIONS, ">versions_$::VERSION";
chdir $::VERSION or die;
$::MAIN_DIR=cwd();
lock;
install_packages();
install_misc;
unlock;
print VERSIONS sort @::package_versions;
close VERSIONS;
CreateExampleTestDirs;
make_testscripts;
set_file_headers if !$::TESTING;
set_version_in_config;
make_results_page;
chdir $::PARENT_DIR or die;
system("tar cf - $::VERSION | gzip > $::VERSION.tar.gz");