From 4330569486f7482d8580c010c1ef82ede246c1cb Mon Sep 17 00:00:00 2001 From: khizmax Date: Sat, 29 Nov 2014 17:50:58 +0300 Subject: [PATCH] New make_distrib scrpt --- make_distrib.pl | 187 ----------------------------------------- tools/make_distrib.bat | 4 + tools/make_distrib.pl | 178 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+), 187 deletions(-) delete mode 100644 make_distrib.pl create mode 100644 tools/make_distrib.bat create mode 100644 tools/make_distrib.pl diff --git a/make_distrib.pl b/make_distrib.pl deleted file mode 100644 index cfd084d4..00000000 --- a/make_distrib.pl +++ /dev/null @@ -1,187 +0,0 @@ -#!/usr/bin/perl - -my $version ; - -my $svnRelPath ; -getRelPath() ; -print "Relative path: $svnRelPath\n" ; -my $upToRoot ; -if ( $svnRelPath =~ /trunk/ ) { - $upToRoot = '..' ; -} -else { - $upToRoot = '..\\..' ; -} -# my $upToRoot = $svnRelPath ; -# $upToRoot =~ s/([^\/]+)/../g ; -# $upToRoot = "../$upToRoot" ; -print "upToRoot: $upToRoot\n" ; - -getVersion() ; -print "Version $version\n" ; - -my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); -$year += 1900 ; - -my $distrPath = "cds-distrib/cds-$version" ; -my $relDistrPath = "$upToRoot/$distrPath" ; - -print "export SVN...\n" ; -exportSVN() ; - -my $nTabsFound = 0 ; - -print "make copyright...\n" ; -makeCopyright() ; -patchFile("$relDistrPath/build/Makefile", 'VERSION=\d+\.\d+\.\d+', "VERSION=$version" ) ; -patchFile("$relDistrPath/doxygen/cds.doxy", 'PROJECT_NUMBER\s*=\s*\d+\.\d+\.\d+', "PROJECT_NUMBER = $version" ) ; -patchFile("$relDistrPath/projects/Win/vc2008/cds.2008.vcproj", 'CDS_USE_VLD', 'xCDS_USE_VLD' ) ; -patchFile("$relDistrPath/projects/Win/vc2008/unit.2008.vcproj", 'CDS_USE_VLD', 'xCDS_USE_VLD' ) ; -patchFile("$relDistrPath/projects/android/jni/Android.mk", 'CDS_LIBRARY_VERSION\s*:=\s*\d+\.\d+\.\d+', - "CDS_LIBRARY_VERSION := $version" ); - -print "Tabs found: $nTabsFound\n" ; - -print "make docs...\n" ; -`cd $relDistrPath && make_docs.bat` ; -`rm -f $relDistrPath/make_distrib.pl` ; -`rm -fr $relDistrPath/scripts` ; -`rm -f $relDistrPath/doxygen/doxygen.log` ; - -print "make zip...\n" ; -`rm -f $relDistrPath/../cds-$version.zip` ; -`cd $relDistrPath/.. && 7za a cds-$version.zip cds-$version` ; - -print "Done\n" ; - -exit ; - -sub getVersion() -{ - open( my $fh, 'cds/version.h' ) or die "ERROR: Cannot find cds/version.h file"; - binmode $fh ; - - while (<$fh>) { - if ( /CDS_VERSION_STRING.+(\d+\.\d+\.\d+)/ ) { - $version = $1 ; - last ; - } - } - close $fh ; - die "ERROR: cannot find version in cds/version.h" unless $version ; -} - -sub getRelPath() -{ - my $svn = `svn info` ; - ($svnRelPath) = $svn =~ /Working\sCopy\sRoot\sPath:\s+(.+)/ ; - - # my ($curDir) = $svn =~ /URL:\s+(.+)/ ; - # my ($rootDir) = $svn =~ /Repository\s+Root:\s+(.+)/ ; - # $rootDir =~ s/\+/\\\+/g ; - - # ($svnRelPath) = $curDir =~ /$rootDir\/(.+)/ ; -} - -sub exportSVN() -{ - `cd $upToRoot && rm -fr $distrPath && svn export $svnRelPath $distrPath` ; -} - -sub makeCopyright() -{ - processDir( "$relDistrPath/cds" ) ; - processDir( "$relDistrPath/src" ) ; - processDir( "$relDistrPath/tests/test-hdr" ) ; - processDir( "$relDistrPath/tests/unit" ) ; - processDir( "$relDistrPath/tests/cppunit" ) ; -} - -sub processDir( $ ) -{ - my $dirName = shift ; - - opendir(my $dh, $dirName) || die "can't opendir $dirName: $!"; - my @files = grep { /^[^\.]/ } readdir($dh); - closedir $dh; - - foreach my $file ( @files ) { - if ( -d "$dirName/$file" ) { - processDir("$dirName/$file") ; - } - elsif ( $file =~ /\.(h|cpp)$/ ) { - processFile( "$dirName/$file" ) ; - } - } -} - -sub processFile( $ ) -{ - my $file = shift ; - - - if ( open( my $fh, $file )) { - binmode $fh ; - my $str = '' ; - while (<$fh>) { - if ( /^\/\/\$\$CDS-header\$\$/ ) { - $str .= -"/* - This file is a part of libcds - Concurrent Data Structures library - See http://libcds.sourceforge.net/ - - (C) Copyright Maxim Khiszinsky (libcds.sf\@gmail.com) 2006-$year - Distributed under the BSD license (see accompanying file license.txt) - - Version $version -*/\n\n" ; - } - elsif ( /^\/\/\$\$CDS-\/\*\$\$/ ) { - $str .= "/*\n" ; - } - elsif ( /^\/\/\$\$CDS-\*\/\$\$/ ) { - $str .= "*/\n" ; - } - else { - $nTabsFound += $_ =~ s/\t/ /g; - $_ =~ s/\s+$// ; - $_ =~ s/\s+;$/;/; - $str .= $_ ; - $str .= "\n" ; - } - } - close $fh ; - - if ( open( my $fh, ">$file" )) { - binmode $fh ; - print $fh $str ; - close $fh ; - } - } -} - -sub patchFile(@) { - my $file = shift ; - my $seek = shift ; - my $repl = shift ; - - if ( open( my $fh, $file )) { - binmode $fh ; - - my $str = '' ; - $str .= $_ while <$fh> ; - close $fh ; - - $str =~ s/$seek/$repl/g ; - - if ( open( my $fh, ">$file" )) { - binmode $fh ; - print $fh $str ; - close $fh ; - } - } -} - - - - diff --git a/tools/make_distrib.bat b/tools/make_distrib.bat new file mode 100644 index 00000000..dcd1d906 --- /dev/null +++ b/tools/make_distrib.bat @@ -0,0 +1,4 @@ + +cd .. +perl -X tools/make_distrib.pl +cd tools \ No newline at end of file diff --git a/tools/make_distrib.pl b/tools/make_distrib.pl new file mode 100644 index 00000000..9be09f0a --- /dev/null +++ b/tools/make_distrib.pl @@ -0,0 +1,178 @@ +#!/usr/bin/perl + +my $curDir = `cd`; + +my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); +$year += 1900; + + +# Get libcds version +my $Version = get_version(); +print "Make libcds-$Version distributive\n"; + +my $DistrDir = get_distrib_dir(); +print "Distrib dir: $DistrDir\n"; + +# Git clone +my $GitBranch = get_git_branch(); +my $GitRepo = get_git_repo(); +print "Clone git: repo=$GitRepo, branch=$GitBranch\n"; +`git clone -b $GitBranch $GitRepo $DistrDir` or die "Error cloning branch $GitBranch to $DistrDir\n"; +print "Remove $DistrDir/.git directory\n"; +`rm -fr $DistrDir/.git`; +`rm -f $DistrDir/.gitignore $DistrDir/tools/brush_cds.pl $DistrDir/tools/make_distrib.pl $DistrDir/tools/make_distrib.bat`; + +print "make copyright...\n" ; +makeCopyright($DistrDir); + +print "patch files...\n"; +patch_file("$DistrDir/build/Makefile", 'VERSION=\d+\.\d+\.\d+', "VERSION=$Version" ) ; +patch_file("$DistrDir/doxygen/cds.doxy", 'PROJECT_NUMBER\s*=\s*\d+\.\d+\.\d+', "PROJECT_NUMBER = $Version" ) ; +patch_file("$DistrDir/projects/android/jni/Android.mk", 'CDS_LIBRARY_VERSION\s*:=\s*\d+\.\d+\.\d+', + "CDS_LIBRARY_VERSION := $Version" ); + +print "Make docs\n"; +`cd $DistrDir/tools && make_docs.bat && rm doxygen.log && cd $curDir`; + +print "make zip...\n" ; +`rm -f $DistrDir/../cds-$Version.zip` ; +`cd $DistrDir/.. && 7za a cds-$Version.zip cds-$Version` ; + +print "Done\n" ; +exit ; + + +sub get_version() +{ + my $version; + open( my $fh, 'cds/version.h' ) or die "ERROR: Cannot find ../cds/version.h file"; + binmode $fh ; + + while (<$fh>) { + if ( /CDS_VERSION_STRING.+(\d+\.\d+\.\d+)/ ) { + $version = $1 ; + last ; + } + } + close $fh ; + die "ERROR: cannot find version in ../cds/version.h" unless $version ; +} + +sub get_distrib_dir() +{ + my $dir = "../cds-distrib/cds-$Version"; + `rm -fr $dir` if -d $dir; + mkdir $dir; + return $dir; +} + +sub get_git_repo() +{ + return '.'; +} + +sub get_git_branch() +{ + my $branchList = `git branch`; + #print "$branchList\n"; + + # Search "v$Version-rc" branch + my ($branch) = $branchList =~ /(v$Version-rc\d*)/g; + return $branch || 'master'; +} + +sub makeCopyright($) +{ + my $distrDir = shift; + processDir( "$distrDir/cds" ) ; + processDir( "$distrDir/src" ) ; + processDir( "$distrDir/tests/test-hdr" ) ; + processDir( "$distrDir/tests/unit" ) ; + processDir( "$distrDir/tests/cppunit" ) ; +} + +sub processDir( $ ) +{ + my $dirName = shift ; + + opendir(my $dh, $dirName) || die "can't opendir $dirName: $!"; + my @files = grep { /^[^\.]/ } readdir($dh); + closedir $dh; + + foreach my $file ( @files ) { + if ( -d "$dirName/$file" ) { + processDir("$dirName/$file") ; + } + elsif ( $file =~ /\.(h|cpp)$/ ) { + processFile( "$dirName/$file" ) ; + } + } +} + +sub processFile( $ ) +{ + my $file = shift ; + + + if ( open( my $fh, $file )) { + binmode $fh ; + my $str = '' ; + while (<$fh>) { + if ( /^\/\/\$\$CDS-header\$\$/ ) { + $str .= +"/* + This file is a part of libcds - Concurrent Data Structures library + Version: $Version + + (C) Copyright Maxim Khizhinsky (libcds.dev\@gmail.com) 2006-$year + Distributed under the BSD license (see accompanying file license.txt) + + Source code repo: http://github.com/khizmx/libcds/ + Download: http://libcds.sourceforge.net/files/ +*/\n" ; + } + elsif ( /^\/\/\$\$CDS-\/\*\$\$/ ) { + $str .= "/*\n" ; + } + elsif ( /^\/\/\$\$CDS-\*\/\$\$/ ) { + $str .= "*/\n" ; + } + else { + $nTabsFound += $_ =~ s/\t/ /g; + $_ =~ s/\s+$// ; + $_ =~ s/\s+;$/;/; + $str .= $_ ; + $str .= "\n" ; + } + } + close $fh ; + + if ( open( my $fh, ">$file" )) { + binmode $fh ; + print $fh $str ; + close $fh ; + } + } +} + +sub patch_file(@) { + my $file = shift ; + my $seek = shift ; + my $repl = shift ; + + if ( open( my $fh, $file )) { + binmode $fh ; + + my $str = '' ; + $str .= $_ while <$fh> ; + close $fh ; + + $str =~ s/$seek/$repl/g ; + + if ( open( my $fh, ">$file" )) { + binmode $fh ; + print $fh $str ; + close $fh ; + } + } +} -- 2.34.1