Commit 9194f5ef authored by unknown's avatar unknown

- Optimized and cleaned up the Do-rpm and Bootstrap Perl scripts

 - Enhanced Do-rpm to support building RPMs with different compilers
   and options


Build-tools/Bootstrap:
   - small optimization (use builtin Perl cwd() function instead of running
     "pwd" twice)
Build-tools/Do-rpm:
   - added options to handle different compilers and compile flags (e.g. when
     compiling on IA64 using the Intel ecc compiler)
   - code cleanups (use more builtin Perl functions instead of forking
     subrocesses)
   - don't try to probe various distribution-specific RPM options - query rpm
     directly instead
   - Pass the MySQL version as an argument, not an option (as it's not
     optional anyway)
parent 01441bc5
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
# written by Lenz Grimmer <lenz@mysql.com> # written by Lenz Grimmer <lenz@mysql.com>
# #
use Cwd;
use Getopt::Long; use Getopt::Long;
Getopt::Long::Configure ("bundling"); Getopt::Long::Configure ("bundling");
...@@ -26,10 +27,9 @@ else ...@@ -26,10 +27,9 @@ else
# Some predefined settings # Some predefined settings
$build_command= "BUILD/compile-pentium-max"; $build_command= "BUILD/compile-pentium-max";
chomp ($LOGFILE= `pwd`); $PWD= cwd();
$LOGFILE.= "/Bootstrap.log"; $LOGFILE= $PWD . "/Bootstrap.log";
chomp ($opt_directory= `pwd`); $opt_docdir= $PWD . "/mysqldoc";
$opt_docdir= $opt_directory . "/mysqldoc";
$opt_build_command= undef; $opt_build_command= undef;
$opt_changelog= undef; $opt_changelog= undef;
$opt_delete= undef; $opt_delete= undef;
...@@ -82,8 +82,7 @@ if (defined $opt_log) ...@@ -82,8 +82,7 @@ if (defined $opt_log)
} }
else else
{ {
chomp ($LOGFILE= `pwd`); $LOGFILE= $PWD . "/" . $opt_log;
$LOGFILE.= "/" . $opt_log;
} }
} }
} }
......
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# Do-rpm - compile RPM packages out of a source tarball and copy the # Do-rpm - compile RPM packages out of a source tarball and move the
# resulting RPM packages into the current directory. # resulting RPM packages into the current directory.
# #
# The script currently assumes the following environment (which should exist # The script currently assumes the following environment (which should exist
...@@ -17,27 +17,43 @@ ...@@ -17,27 +17,43 @@
# written by Lenz Grimmer <lenz@mysql.com> # written by Lenz Grimmer <lenz@mysql.com>
# #
use Cwd;
use File::Basename;
use File::Copy;
use Getopt::Long; use Getopt::Long;
Getopt::Long::Configure ("bundling"); Getopt::Long::Configure ("bundling");
use Sys::Hostname;
$opt_cc= undef;
$opt_cflags= undef;
$opt_clean= undef;
$opt_cxx= undef;
$opt_cxxflags= undef;
$opt_dry_run= undef; $opt_dry_run= undef;
$opt_help= undef; $opt_help= undef;
$opt_log= undef; $opt_log= undef;
$opt_mail= ""; $opt_mail= "";
$opt_verbose= undef; $opt_verbose= undef;
$opt_version= undef;
$MAJOR= $MINOR= $RELEASE= 0;
GetOptions( GetOptions(
"dry-run", "cc=s",
"cflags=s",
"clean|c",
"cxx=s",
"cxxflags=s",
"dry-run|t",
"help|h", "help|h",
"log|l:s", "log|l:s",
"mail|m=s", "mail|m=s",
"verbose|v", "verbose|v",
"version=s",
) || &print_help; ) || &print_help;
defined($VERSION=$ARGV[0]) || print_help("Please provide the MySQL version!");
# Include helper functions # Include helper functions
chomp($PWD= `pwd`); $PWD= cwd();
$LOGGER= "$PWD/logger.pm"; $LOGGER= "$PWD/logger.pm";
if (-f "$LOGGER") if (-f "$LOGGER")
{ {
...@@ -66,10 +82,16 @@ if (defined $opt_log) ...@@ -66,10 +82,16 @@ if (defined $opt_log)
} }
} }
&print_help("") if ($opt_help || !$opt_version); ($MAJOR, $MINOR, $RELEASE)= split(/\./, $VERSION);
$HOST= hostname();
$HOST=~ /^([^.-]*)/;
$HOST= $1;
$LOGFILE= "$PWD/Logs/Do-rpm-$HOST-$MAJOR.$MINOR.log";
&print_help("") if ($opt_help);
# #
# Newer RPM version ship with a separate tool to build RPMs # Newer RPM versions ship with a separate tool "rpmbuild" to build RPMs
# #
if (-x "/usr/bin/rpmbuild") if (-x "/usr/bin/rpmbuild")
{ {
...@@ -80,24 +102,24 @@ else ...@@ -80,24 +102,24 @@ else
$RPM= "/bin/rpm"; $RPM= "/bin/rpm";
} }
foreach $DIR ("/usr/src/packages", "/usr/src/redhat") if ($RPM)
{ {
if (-d $DIR) &logger("Found rpm binary: $RPM");
{ }
$TOPDIR= $DIR; else
last; {
} &abort("Unable to find RPM binary!");
} }
$SPECDIR= $TOPDIR . "/SPECS"; #
$SOURCEDIR= $TOPDIR . "/SOURCES"; # determine some RPM settings for this host
#
chomp($RPMARCH= `$RPM --eval "%{_arch}" 2> /dev/null`);
chomp($RPMDIR= `$RPM --eval "%{_rpmdir}" 2> /dev/null`);
chomp($SOURCEDIR= `$RPM --eval "%{_sourcedir}" 2> /dev/null`);
chomp($SPECDIR= `$RPM --eval "%{_specdir}" 2> /dev/null`);
chomp($SRCRPMDIR= `$RPM --eval "%{_srcrpmdir}" 2> /dev/null`);
$VERSION= $opt_version;
($MAJOR, $MINOR, $RELEASE)= split(/\./, $VERSION);
chomp($HOST= `hostname`);
$HOST=~ /^([^.-]*)/;
$HOST= $1;
$LOGFILE= "$PWD/Logs/Do-rpm-$HOST-$MAJOR.$MINOR.log";
$SOURCEFILE= "mysql-$VERSION.tar.gz"; $SOURCEFILE= "mysql-$VERSION.tar.gz";
$SPECFILE= "$PWD/$HOST/mysql-$VERSION/support-files/mysql-$VERSION.spec"; $SPECFILE= "$PWD/$HOST/mysql-$VERSION/support-files/mysql-$VERSION.spec";
...@@ -112,23 +134,56 @@ foreach $file ($SOURCEFILE, $SPECFILE) ...@@ -112,23 +134,56 @@ foreach $file ($SOURCEFILE, $SPECFILE)
# Install source and spec file # Install source and spec file
# #
&logger("Copying SOURCE and SPEC file to build directories."); &logger("Copying SOURCE and SPEC file to build directories.");
$command= "cp"; copy($SOURCEFILE, $SOURCEDIR)
$command.= " -v" if ($opt_verbose); or &abort("Unable to copy $SOURCEFILE to $SOURCEDIR!");
$command.= " $SOURCEFILE $SOURCEDIR"; copy($SPECFILE, $SPECDIR)
&run_command($command, "Unable to copy $SOURCEFILE to $SOURCEDIR!"); or &abort("Unable to copy $SPECFILE to $SPECDIR!");
$command= "cp";
$command.= " -v" if ($opt_verbose); #
$command.= " $SPECFILE $SPECDIR"; # Set environment variables - these are being used in the
&run_command($command, "Unable to copy $SPECFILE to $SPECDIR!"); # official MySQL RPM spec file
#
&logger("Setting special build environment variables")
if ($opt_cc) or ($opt_cflags) or ($opt_cxxflags) or ($opt_cxx);
$ENV{MYSQL_BUILD_CC}=$opt_cc if ($opt_cc);
$ENV{MYSQL_BUILD_CFLAGS}=$opt_cflags if ($opt_cflags);
$ENV{MYSQL_BUILD_CXXFLAGS}=$opt_cxxflags if ($opt_cxxflags);
$ENV{MYSQL_BUILD_CXX}=$opt_cxx if ($opt_cxx);
# #
# Build the RPMs # Build the RPMs
# #
$command= "$RPM"; $command= "$RPM";
$command.=" -v" if ($opt_verbose); $command.= " -v" if ($opt_verbose);
$command.=" -ba --clean $SPECDIR/$SPECFILE"; $command.= " -ba";
&logger("Builing RPM."); $command.= " --clean" if $opt_clean;
&run_command($command, "Unable to build RPM!"); $command.= " $SPECDIR/";
$command.= basename($SPECFILE);
&logger("Building RPM.");
&run_command($command, "Error while building the RPMs!");
#
# Move the resulting RPMs into the pwd
#
$command= "mv";
$command.= " -v " if ($opt_verbose);
$command.= "$SRCRPMDIR/MySQL*$VERSION*.src.rpm $PWD";
&run_command($command, "Error moving source RPM!");
$command= "mv";
$command.= " -v " if ($opt_verbose);
$command.= "$RPMDIR/$RPMARCH/MySQL*$VERSION*.$RPMARCH.rpm $PWD";
&run_command($command, "Error moving binary RPMs!");
#
# Clean up
#
if ($opt_clean)
{
&logger("Removing spec file and source package");
unlink("$SPECDIR/" . basename($SPECFILE));
unlink("$SOURCEDIR/$SOURCEFILE");
}
&logger("SUCCESS: RPM files successfully created.") if (!$opt_dry_run); &logger("SUCCESS: RPM files successfully created.") if (!$opt_dry_run);
exit 0; exit 0;
...@@ -139,18 +194,24 @@ sub print_help ...@@ -139,18 +194,24 @@ sub print_help
if ($message ne "") if ($message ne "")
{ {
print "\n"; print "\n";
print "ERROR: $message\n"; print "ERROR: $message\n\n}";
} }
print <<EOF; print <<EOF;
Usage: Do-rpm <options> --version=<version> Usage: Do-rpm <options> <version>
Creates a binary RPM package out of a MySQL source distribution and copy the Creates a binary RPM package out of a MySQL source distribution and moves the
resulting RPMs into the current directory. resulting RPMs into the current directory. <version> is the MySQL version
number (e.g. 4.0.11-gamma)
Options: Options:
--dry-run Dry run without executing --cc=<compiler> Use <compiler> to compile C code
--ccflags=<flags> Use special C compiler flags
--cxx=<compiler> Use <compiler> to compile C++ code
--cxxflags=<flags> Use special C++ compiler flags
-c, --clean Clean up after the build
-t, --dry-run Dry run without executing
-h, --help Print this help -h, --help Print this help
-l, --log[=<filename>] Write a log file [to <filename>] -l, --log[=<filename>] Write a log file [to <filename>]
(default is "$LOGFILE") (default is "$LOGFILE")
...@@ -159,7 +220,6 @@ Options: ...@@ -159,7 +220,6 @@ Options:
is enabled) is enabled)
Note that the \@-Sign needs to be quoted! Note that the \@-Sign needs to be quoted!
Example: --mail=user\\\@domain.com Example: --mail=user\\\@domain.com
--version=<version> The MySQL version number (e.g. 4.0.11-gamma)
-v, --verbose Verbose execution -v, --verbose Verbose execution
EOF EOF
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment