cgal/Maintenance/release_building/create_release

634 lines
18 KiB
Perl
Executable File

#!/sw/bin/perl
use strict;
use Cwd;
use File::Copy;
use File::Basename;
use File::Find;
#
# This script creates an internal release for CGAL.
#----------------------------------------------------------------#
# initialization #
#----------------------------------------------------------------#
my $TEMPFILE="TEMPFILE.$$";
my @package_versions = ();
my (
$PACKAGEDIR,
$ALL_RESULTS_DIR,
$LOCKFILE,
$last_version_file,
$VERSION_NR,
$VERSION,
$MAIN_DIR,
$PARENT_DIR,
$WEBDIR,
$VERSIONSDIR,
$release_date
);
my $TESTING = 0;
if ($TESTING) {
print STDERR "Testing !!!\n\n";
$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';
$WEBDIR='/users/www/CGAL/Members/Develop/updates';
$VERSIONSDIR='/projects/CGAL/Releases/Versions';
}
my $SCRIPTDIR=
'/projects/CGAL/admin_scripts';
my $MISCPACKAGEDIR=
'/users/www/CGAL/Members/Develop/updates/packages';
my $LOCKCMD=
'/sw/bin/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 3 and last 2 lines generated by unzip -l.
shift @zip_contents;
shift @zip_contents;
shift @zip_contents;
pop @zip_contents;
pop @zip_contents;
foreach $ITEM (@_) {
foreach $zipped_file (@zip_contents) {
if ( $zipped_file =~ m|\s($ITEM.*)\s| ) {
push(@to_unzip,($1));
}
}
}
system('unzip', '-q', $package, @to_unzip);
# 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', 'examples', '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;
}
#---------------------------------------------------------------#
# CreateSrcTestDir
#---------------------------------------------------------------#
sub CreateSrcTestDir()
{
system('cp', '-r', 'src', 'test');
rename('test/src/makefile_lib','test/src/makefile');
open(CGAL_TEST,">test/src/cgal_test");
print CGAL_TEST <<'EOF';
#! /bin/sh
# This is a script for the CGAL test suite. Such a script must obey
# the following rules:
#
# - the name of the script is cgal_test
# - for every target two one line messages are written to the file 'error.txt'
# the first one indicates if the compilation was successful
# the second one indicates if the execution was successful
# if one of the two was not successful, the line should start with 'ERROR:'
# - running the script should not require any user interaction
# - the script should clean up object files and executables
ERRORFILE=error.txt
#---------------------------------------------------------------------#
# compile_and_run <target>
#---------------------------------------------------------------------#
compile()
{
echo "Compiling $1 ... "
SUCCES="y"
if eval 'make CGAL_MAKEFILE=$CGAL_MAKEFILE \
TESTSUITE_CXXFLAGS="$TESTSUITE_CXXFLAGS" \
TESTSUITE_LDFLAGS="$TESTSUITE_LDFLAGS" -k $1' ; then
echo " compilation of $1 succeeded" >> $ERRORFILE
else
echo " ERROR: compilation of $1 failed" >> $ERRORFILE
SUCCES=""
fi
eval "2>&1 make CGAL_MAKEFILE=$CGAL_MAKEFILE clean > /dev/null "
}
#---------------------------------------------------------------------#
# remove the previous error file
#---------------------------------------------------------------------#
rm -f $ERRORFILE
touch $ERRORFILE
#---------------------------------------------------------------------#
# compile and run the tests
#---------------------------------------------------------------------#
if [ $# -ne 0 ] ; then
for file in $* ; do
compile $file
done
else
compile lib_no_install
fi
EOF
close(CGAL_TEST);
chmod 0755, 'test/src/cgal_test';
}
#---------------------------------------------------------------#
# 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/${DIR}_Examples");
}
}
system("$SCRIPTDIR/C2dsp *");
chdir '..';
}
#---------------------------------------------------------------#
# CreateDemoTestDirs
#---------------------------------------------------------------#
sub CreateDemoTestDirs()
{
my $DIR;
print "Creating demo test directories ...\n";
chdir 'demo' or return;
foreach $DIR (glob("*")) {
print "$DIR\n";
if ( -d $DIR ) {
system('cp', '-r', "$DIR", "../test/${DIR}_Demo");
system('cp',"$SCRIPTDIR/demo_cgal_test",
"../test/${DIR}_Demo/cgal_test");
}
}
chdir '..';
}
#---------------------------------------------------------------#
# list_test_directories
#---------------------------------------------------------------#
# list_test_directories <package>
#
# drukt de test en examples directories 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;
}
if ( $zipped_file =~ m|\bexamples/([^/\n]+)| ) {
$test_dirs{$1} = 1;
}
if ( $zipped_file =~ m|\bdemo/([^/\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","stlport","winutils","auxiliary",
"developer_scripts","scripts","cgal_config.bat",
"install.txt","INSTALL.win32");
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");
}
if ( -f 'version' && -d "demo/$direc"
&& ! -f "demo/$direc/version") {
copy('version', "demo/$direc");
}
}
unlink 'version';
}
closedir PACKAGEDIR;
}
#---------------------------------------------------------------#
# install_misc
# install all components of this package, without filtering.
#---------------------------------------------------------------#
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', 'submission_info';
}
#---------------------------------------------------------------#
# make_src_makefiles
#---------------------------------------------------------------#
sub make_src_makefiles()
{
my ($DIR, $BASEDIR);
$BASEDIR = cwd();
chdir 'src';
system("$SCRIPTDIR/create_src_makefiles");
chdir $BASEDIR;
}
#---------------------------------------------------------------#
# make_testscripts
#---------------------------------------------------------------#
sub make_testscripts()
{
my ($DIR, $BASEDIR);
$BASEDIR = cwd();
print "creating and checking makefiles ...\n";
chdir 'test';
foreach $DIR (glob("*")) {
if ( -d $DIR ) {
chdir $DIR;
if ( -f 'Makefile') {
rename 'Makefile', 'makefile';
}
if ( -f 'makefile' ) {
open MAKEFILE, "makefile";
open NEW_MAKEFILE, ">makefile.new";
while (<MAKEFILE>) {
s/\.o\b/\$(OBJ_EXT)/g;
s/-g\b/\$(DEBUG_OPT)/g;
print NEW_MAKEFILE $_;
}
close NEW_MAKEFILE;
close MAKEFILE;
rename("makefile.new","makefile");
} else {
my $options = '-t';
if ( -f 'create_makefile_options') {
if (open(OPTIONS, "<create_makefile_options")) {
$_ = <OPTIONS>;
chomp;
if (/^[\w\s-]+$/) { $options = $_;
} else {
print STDERR "Rejected create_makefile_options in $DIR\n";
}
close OPTIONS;
}
}
system("$SCRIPTDIR/create_makefile", $options);
}
if ( ! -f 'cgal_test' ) {
system("$SCRIPTDIR/create_cgal_test");
}
chdir '..';
}
}
chdir $BASEDIR;
chdir 'examples';
foreach $DIR (glob("*")) {
if ( -d $DIR ) {
chdir $DIR;
if ( -f 'Makefile') {
rename 'Makefile', 'makefile';
}
if ( -f 'makefile' ) {
open MAKEFILE, "makefile";
open NEW_MAKEFILE, ">makefile.new";
while (<MAKEFILE>) {
s/\.o\b/\$(OBJ_EXT)/g;
s/-g\b/\$(DEBUG_OPT)/g;
print NEW_MAKEFILE $_;
}
close NEW_MAKEFILE;
close MAKEFILE;
rename("makefile.new","makefile");
} else {
my $options = '-d';
if ( -f 'create_makefile_options') {
if (open(OPTIONS, "<create_makefile_options")) {
$_ = <OPTIONS>;
chomp;
if (/^[\w\s-]+$/) { $options = $_;
} else {
print STDERR "Rejected create_makefile_options in $DIR\n";
}
close OPTIONS;
}
}
system("$SCRIPTDIR/create_makefile", $options);
}
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;
my $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;
make_src_makefiles;
CreateSrcTestDir;
CreateExampleTestDirs;
CreateDemoTestDirs;
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");
if (! $TESTING) {
system("cp", "$VERSION.tar.gz", "$WEBDIR");
system("cp", "versions_$VERSION", "$VERSIONSDIR");
}
system('rm', '-rf', "$VERSION");