Do-compile 22.3 KB
Newer Older
1
#!/usr/bin/perl -w
unknown's avatar
unknown committed
2

3
use File::Basename;
unknown's avatar
unknown committed
4
use Getopt::Long;
5
use Sys::Hostname;
6 7 8 9

@config_options= ();
@make_options= ();

10
$opt_distribution=$opt_user=$opt_config_env=$opt_config_extra_env="";
11
$opt_dbd_options=$opt_perl_options=$opt_config_options=$opt_make_options=$opt_suffix="";
12
$opt_tmp=$opt_version_suffix="";
unknown's avatar
unknown committed
13
$opt_bundled_zlib=$opt_help=$opt_delete=$opt_debug=$opt_stage=$opt_no_test=$opt_no_perl=$opt_one_error=$opt_with_low_memory=$opt_fast_benchmark=$opt_static_client=$opt_static_server=$opt_static_perl=$opt_sur=$opt_with_small_disk=$opt_local_perl=$opt_tcpip=$opt_build_thread=$opt_use_old_distribution=$opt_enable_shared=$opt_no_crash_me=$opt_no_strip=$opt_with_cluster=$opt_with_debug=$opt_no_benchmark=$opt_no_mysqltest=$opt_without_embedded=$opt_readline=0;
14
$opt_innodb=$opt_bdb=$opt_raid=$opt_libwrap=$opt_clearlogs=0;
unknown's avatar
unknown committed
15

16 17 18
GetOptions(
	"bdb",
	"build-thread=i",
19
	"bundled-zlib",
unknown's avatar
unknown committed
20
	"config-env=s" => \@config_env,
21
	"config-extra-env=s" => \@config_extra_env,
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
	"config-options=s" => \@config_options,
	"dbd-options=s",
	"debug",
	"delete",
	"distribution=s",
	"enable-shared",
	"fast-benchmark",
	"help|Information",
	"innodb",
	"libwrap",
	"local-perl",
	"make-options=s" => \@make_options,
	"no-crash-me",
	"no-perl",
	"no-strip",
unknown's avatar
unknown committed
37 38 39
	"no-test",
	"no-mysqltest",
	"no-benchmark",
40
	"one-error",
41 42 43
	"perl-files=s",
	"perl-options=s",
	"raid",
44
	"readline",
45 46 47 48 49 50 51 52 53 54 55
	"stage=i",
	"static-client",
	"static-perl",
	"static-server",
	"suffix=s",
	"sur",
	"tcpip",
	"tmp=s",
	"use-old-distribution",
	"user=s",
	"version-suffix=s",
56
	"with-cluster",
unknown's avatar
unknown committed
57
	"with-debug",
58 59 60
	"with-low-memory",
	"with-other-libc=s",
	"with-small-disk",
61
	"without-embedded",
62
	"clearlogs",
63 64 65
) || usage();

usage() if ($opt_help);
unknown's avatar
unknown committed
66 67
usage() if (!$opt_distribution);

68 69 70 71 72 73 74 75 76 77 78 79
if (@make_options > 0)
{
	chomp(@make_options);
	$opt_make_options= join(" ", @make_options);
}

if (@config_options > 0)
{
	chomp(@config_options);
	$opt_config_options= join(" ", @config_options);
}

unknown's avatar
unknown committed
80 81 82 83 84 85
if (@config_env > 0)
{
	chomp(@config_env);
	$opt_config_env= join(" ", @config_env);
}

86 87 88 89 90 91
if (@config_extra_env > 0)
{
	chomp(@config_extra_env);
	$opt_config_extra_env= join(" ", @config_extra_env);
}

92
$host= hostname();
unknown's avatar
unknown committed
93
chomp($uname=`uname`);
unknown's avatar
unknown committed
94 95
$full_host_name=$host;
$connect_option= ($opt_tcpip ? "--host=$host" : "");
unknown's avatar
unknown committed
96
$host =~ /^([^.-]*)/;
unknown's avatar
unknown committed
97
$host=$1 . $opt_suffix;
unknown's avatar
unknown committed
98
$email="$opt_user\@mysql.com";
unknown's avatar
unknown committed
99
chomp($pwd = `pwd`);
100
$VER= basename($opt_distribution);
unknown's avatar
unknown committed
101
$VER=~ /mysql.*-([1-9]\.[0-9]{1,2}\.[0-9]{1,2}.*)\.tar*/; $version=$1;
102
$release="";			# Shut up perl
unknown's avatar
unknown committed
103 104
($major, $minor, $release) = split(/\./,$version);
$log="$pwd/Logs/$host-$major.$minor$opt_version_suffix.log";
unknown's avatar
unknown committed
105
$opt_distribution =~ /(mysql[^\/]*)\.tar/;
unknown's avatar
unknown committed
106 107 108 109 110 111 112
$ver=$1;
$gcc_version=which("gcc");
if (defined($gcc_version) && ! $opt_config_env)
{
  $tmp=`$gcc_version -v 2>&1`;
  if ($tmp =~ /version 2\.7\./)
  {
unknown's avatar
unknown committed
113
    $opt_config_env= 'CC=gcc CFLAGS="-O2 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O2 -fno-omit-frame-pointer"';
unknown's avatar
unknown committed
114
  }
115 116 117 118
  elsif ($tmp =~ /version 3\.0\./)
  {
    $opt_config_env= 'CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti"';
  }
unknown's avatar
unknown committed
119 120
  else
  {
unknown's avatar
unknown committed
121
    $opt_config_env= 'CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti"';
unknown's avatar
unknown committed
122 123
  }
}
unknown's avatar
unknown committed
124

125 126
$opt_config_env.=" $opt_config_extra_env";

unknown's avatar
unknown committed
127
$new_opt_tmp=0;
unknown's avatar
unknown committed
128 129
if ($opt_tmp)
{
130
  unless (-d $opt_tmp)
unknown's avatar
unknown committed
131 132 133 134
  {
    safe_system("mkdir $opt_tmp");
    $new_opt_tmp=1;
  }
unknown's avatar
unknown committed
135 136 137 138 139 140
  $ENV{'TMPDIR'}=$opt_tmp;
}
else
{
  $opt_tmp="/tmp";
}
unknown's avatar
unknown committed
141
$bench_tmpdir="$opt_tmp/my_build-$host";
unknown's avatar
unknown committed
142
$ENV{'PATH'}= "$pwd/$host/bin:" . $ENV{'PATH'}; 
unknown's avatar
unknown committed
143
$make=which("gmake","make");	# Can't use -j here!
unknown's avatar
unknown committed
144 145 146 147 148
$tar=which("gtar","tar");
$sendmail=find("/usr/lib/sendmail","/usr/sbin/sendmail");
$sur= $opt_sur ? "/my/local/bin/sur" : "";
delete $ENV{'MYSQL_PWD'};	# Reset possibly password
delete $ENV{'MY_BASEDIR_VERSION'};
unknown's avatar
unknown committed
149
$ENV{'MYSQL_TCP_PORT'}= $mysql_tcp_port= 3334 + $opt_build_thread*2;
unknown's avatar
unknown committed
150
$ENV{'MYSQL_UNIX_PORT'}=$mysql_unix_port="$opt_tmp/mysql$opt_suffix.build";
unknown's avatar
unknown committed
151
$ENV{"PERL5LIB"}="$pwd/$host/perl5:$pwd/$host/perl5/site_perl";
152
$slave_port=$mysql_tcp_port+16;
153
$ndbcluster_port= 9350 + $opt_build_thread*2;
unknown's avatar
unknown committed
154
$manager_port=$mysql_tcp_port+1;
unknown's avatar
unknown committed
155
$mysqladmin_args="--no-defaults -u root --connect_timeout=5 --shutdown_timeout=20";
156

unknown's avatar
unknown committed
157
if ($opt_stage == 0 || $opt_clearlogs)
unknown's avatar
unknown committed
158 159 160 161 162 163 164 165 166 167 168 169
{
  system("mkdir Logs") if (! -d "Logs");
  system("mv $log ${log}-old") if (-f $log);
  unlink($log);
}

open(LOG,">>$log") || abort("Can't open log file, error $?");
select LOG;
$|=1;
select STDOUT;
$|=1;

170
info("Compiling MySQL$opt_version_suffix at $host$opt_suffix, stage: $opt_stage\n");
171 172 173
info("LD_LIBRARY_PATH is $ENV{LD_LIBRARY_PATH}");
info("PATH is $ENV{PATH}");

unknown's avatar
unknown committed
174
log_timestamp();
175

176 177 178 179 180 181 182 183 184 185 186
$md5_result= safe_system("perl $ENV{HOME}/my_md5sum -c ${opt_distribution}.md5");

if ($md5_result != 0)
{
  abort("MD5 check failed for $opt_distribution!");
}
else
{
  info("SUCCESS: MD5 checks for $opt_distribution");
}

187 188
if (-x "$host/bin/mysqladmin")
{
unknown's avatar
unknown committed
189 190 191 192 193
  log_system("$host/bin/mysqladmin $mysqladmin_args -S $mysql_unix_port -s shutdown");
  log_system("$host/bin/mysqladmin $mysqladmin_args -P $mysql_tcp_port -h $host -s shutdown");
  log_system("$host/bin/mysqladmin $mysqladmin_args -P $slave_port -h $host -s shutdown");
  log_system("$host/bin/mysqladmin $mysqladmin_args -P 9306 -h $host -s shutdown");
  log_system("$host/bin/mysqladmin $mysqladmin_args -P 9307 -h $host -s shutdown");
194
}
unknown's avatar
unknown committed
195
kill_all("mysqlmanager");
unknown's avatar
unknown committed
196 197 198 199 200
#
# Kill all old processes that are in the build directories
# This is to find any old mysqld servers left from previous builds
kill_all("$pwd/host/mysql");
kill_all("$pwd/host/test");
unknown's avatar
unknown committed
201 202 203

if ($opt_stage == 0)
{
unknown's avatar
unknown committed
204
  log_timestamp();
unknown's avatar
unknown committed
205
  print "$host: Removing old distribution\n" if ($opt_debug);
unknown's avatar
unknown committed
206 207 208 209
  if (!$opt_use_old_distribution)
  {
    system("mkdir $host") if (! -d $host);
    system("touch $host/mysql-fix-for-glob");
210
    rm_all(<$host/mysql*>);
unknown's avatar
unknown committed
211 212
    system("mkdir $host/bin") if (! -d "$host/bin");
  }
unknown's avatar
unknown committed
213 214 215 216
  rm_all("$host/test");
  system("mkdir $host/test") if (! -d "$host/test");
}

217
safe_cd($host);
unknown's avatar
unknown committed
218
if ($opt_stage == 0 && ! $opt_use_old_distribution)
unknown's avatar
unknown committed
219 220
{
  safe_system("gunzip < $opt_distribution | $tar xf -");
unknown's avatar
unknown committed
221 222

  # Fix file times; This is needed because the time for files may be
223 224 225 226 227
  # in the future.  The following is done this way to ensure that
  # we don't get any errors from xargs touch
  system("touch timestamp");
  sleep(2);
  system("touch timestamp2");
228 229 230
  system("find . -newer timestamp -print | xargs touch");
  unlink("timestamp");
  unlink("timestamp2");
unknown's avatar
unknown committed
231 232
  sleep(2);
  # Ensure that files we don't want to rebuild are newer than other files
233
  safe_cd($ver);
unknown's avatar
unknown committed
234 235 236 237 238 239 240
  foreach $name ("configure",
		 "Docs/include.texi",
		 "Docs/*.html", "Docs/manual.txt", "Docs/mysql.info",
		 "sql/sql_yacc.h", "sql/sql_yacc.cc")
  {
    system("touch $name");
  }
241 242
  # Fix some file modes in BDB tables that makes life harder.
  system("chmod -R u+rw .");
unknown's avatar
unknown committed
243
}
unknown's avatar
unknown committed
244

245
safe_cd("$pwd/$host/$ver");
246 247 248 249

#
# Configure the sources
#
unknown's avatar
unknown committed
250
if ($opt_stage <= 1)
unknown's avatar
unknown committed
251
{
252
  # Fix files if this is in another timezone than the build host
unknown's avatar
unknown committed
253
  log_timestamp();
unknown's avatar
unknown committed
254
  unlink("config.cache");
unknown's avatar
unknown committed
255 256
  unlink("bdb/build_unix/config.cache");
  unlink("innobase/config.cache");
unknown's avatar
unknown committed
257
  log_system("$make clean") if ($opt_use_old_distribution);
258 259
  $opt_config_options.= " --disable-shared" if (!$opt_enable_shared); # Default for binary versions
  $opt_config_options.= " --with-berkeley-db" if ($opt_bdb);
260
  $opt_config_options.= " --with-zlib-dir=bundled" if ($opt_bundled_zlib);
261
  $opt_config_options.= " --with-client-ldflags=-all-static" if ($opt_static_client);
unknown's avatar
unknown committed
262
	$opt_config_options.= " --with-debug" if ($opt_with_debug);
263 264 265 266
  $opt_config_options.= " --with-libwrap" if ($opt_libwrap);
  $opt_config_options.= " --with-low-memory" if ($opt_with_low_memory);
  $opt_config_options.= " --with-mysqld-ldflags=-all-static" if ($opt_static_server);
  $opt_config_options.= " --with-raid" if ($opt_raid);
267 268 269 270 271 272
	if ($opt_readline)
	{
  	$opt_config_options.= " --with-readline";
	}
	else
	{
273
		$opt_config_options.= " --with-libedit";
274
	}
275
  $opt_config_options.= " --with-embedded-server" unless ($opt_without_embedded);
276
  $opt_config_options.= " --with-ndbcluster" if ($opt_with_cluster);
277

278 279
  # Only enable InnoDB when requested (required to be able to
  # build the "Classic" packages that do not include InnoDB)
unknown's avatar
unknown committed
280 281 282 283 284 285 286 287
  if ($opt_innodb)
  {
    $opt_config_options.= " --with-innodb";
  }
  else
  {
    $opt_config_options.= " --without-innodb";
  }
288

289 290
  if ($opt_with_other_libc)
  {
291 292
    $opt_with_other_libc= " --with-other-libc=$opt_with_other_libc";
    $opt_config_options.= $opt_with_other_libc;
293
  }
294

295 296
  $prefix="/usr/local/mysql";
  check_system("$opt_config_env ./configure --prefix=$prefix --localstatedir=$prefix/data --libexecdir=$prefix/bin --with-comment=\"Official MySQL$opt_version_suffix binary\" --with-extra-charsets=complex --with-server-suffix=\"$opt_version_suffix\" --enable-thread-safe-client --enable-local-infile $opt_config_options","Thank you for choosing MySQL");
unknown's avatar
unknown committed
297 298 299 300 301 302
  if (-d "$pwd/$host/include-mysql")
  {
    safe_system("cp -r $pwd/$host/include-mysql/* $pwd/$host/$ver/include");
  }
}

303 304 305
#
# Compile the binaries
#
unknown's avatar
unknown committed
306 307
if ($opt_stage <= 2)
{
308
  my ($command);
unknown's avatar
unknown committed
309
  log_timestamp();
unknown's avatar
unknown committed
310
  unlink($opt_distribution) if ($opt_delete && !$opt_use_old_distribution);
311 312 313
  $command=$make;
  $command.= " $opt_make_options" if (defined($opt_make_options) && $opt_make_options ne "");
  safe_system($command);
314
  print LOG "Do-compile: Build successful\n";
unknown's avatar
unknown committed
315 316 317
}

#
318
# Create the binary distribution
unknown's avatar
unknown committed
319 320 321
#
if ($opt_stage <= 3)
{
322
  my $flags= "";
unknown's avatar
unknown committed
323
  log_timestamp();
324
  log_system("rm -fr mysql-{3,4,5}* $pwd/$host/mysql*.t*gz");
325 326 327 328 329
  # No need to add the debug symbols, if the binaries are not stripped (saves space)
  unless ($opt_with_debug || $opt_no_strip)
  {
    log_system("nm -n sql/mysqld | gzip -9 -v 2>&1 > sql/mysqld.sym.gz | cat");
  }
330

331
  $flags.= " --no-strip" if ($opt_no_strip || $opt_with_debug);
332
  $flags.= " --with-ndbcluster" if ($opt_with_cluster);
333
  check_system("scripts/make_binary_distribution --tmp=$opt_tmp --suffix=$opt_suffix $flags",".tar.gz created");
334
  safe_system("mv mysql*.t*gz $pwd/$host");
unknown's avatar
unknown committed
335 336 337 338 339 340 341 342
  if (-f "client/.libs/mysqladmin")
  {
    safe_system("cp client/.libs/mysqladmin $pwd/$host/bin");
  }
  else
  {
    safe_system("cp client/mysqladmin $pwd/$host/bin");
  }  
unknown's avatar
unknown committed
343
  safe_system("$make clean") if ($opt_with_small_disk);
unknown's avatar
unknown committed
344 345
}

346 347
$tar_file=<$pwd/$host/mysql*.t*gz>;
abort ("Could not find tarball!") unless ($tar_file);
348

unknown's avatar
unknown committed
349
# Generate the MD5 for the binary distribution
350 351 352
$tar_file=~ /(mysql[^\/]*)\.(tar\.gz|tgz)/;
$tar_file_lite= "$1.$2";
system("cd $pwd/$host; perl $ENV{HOME}/my_md5sum $tar_file_lite > ${tar_file_lite}.md5");
unknown's avatar
unknown committed
353

354 355 356
#
# Unpack the binary distribution
#
unknown's avatar
unknown committed
357 358
if ($opt_stage <= 4 && !$opt_no_test)
{
unknown's avatar
unknown committed
359
  log_timestamp();
unknown's avatar
unknown committed
360 361 362 363 364
  rm_all(<$pwd/$host/test/*>);
  safe_cd("$pwd/$host/test");
  safe_system("gunzip < $tar_file | $tar xf -");
}

365
$tar_file =~ /(mysql[^\/]*)\.(tar\.gz|tgz)/;
unknown's avatar
unknown committed
366 367
$ver=$1;
$test_dir="$pwd/$host/test/$ver";
unknown's avatar
unknown committed
368 369 370
$ENV{"LD_LIBRARY_PATH"}= ("$test_dir/lib" .
			  (defined($ENV{"LD_LIBRARY_PATH"}) ?
			   ":" . $ENV{"LD_LIBRARY_PATH"} : ""));
371 372 373
#
# Run the test suite
#
unknown's avatar
unknown committed
374
if ($opt_stage <= 5 && !$opt_no_test && !$opt_no_mysqltest)
unknown's avatar
unknown committed
375
{
376
  my $flags= "";
377
  my $force= "";
378
  $flags.= " --with-ndbcluster" if ($opt_with_cluster);
unknown's avatar
unknown committed
379
  $flags.= " --force" if (!$opt_one_error);
unknown's avatar
unknown committed
380
  log_timestamp();
381
  system("mkdir $bench_tmpdir") if (! -d $bench_tmpdir);
unknown's avatar
unknown committed
382
  safe_cd("${test_dir}/mysql-test");
unknown's avatar
unknown committed
383
  check_system("./mysql-test-run $flags --tmpdir=$bench_tmpdir --master_port=$mysql_tcp_port --slave_port=$slave_port --ndbcluster_port=$ndbcluster_port --manager-port=$manager_port --no-manager --sleep=10", "tests were successful");
384
  # 'mysql-test-run' writes its own final message for log evaluation.
unknown's avatar
unknown committed
385 386
}

387
#
388
# Start the server if we are going to run any of the benchmarks
389
#
unknown's avatar
unknown committed
390
if (!$opt_no_test && !$opt_no_benchmark)
unknown's avatar
unknown committed
391
{
unknown's avatar
unknown committed
392
  my $extra;
unknown's avatar
unknown committed
393
  safe_cd($test_dir);
unknown's avatar
unknown committed
394
  log_system("./bin/mysqladmin $mysqladmin_args -S $mysql_unix_port -s shutdown") || info("There was no mysqld running\n");
unknown's avatar
unknown committed
395 396
  sleep(2);
  log_system("rm -f  ./data/mysql/*");
397
  check_system("scripts/mysql_install_db --no-defaults --skip-locking","https://order");
unknown's avatar
unknown committed
398 399 400
  $extra="";
  if ($opt_bdb)
  {
401
    $extra.=" --bdb_cache_size=16M --bdb_max_lock=240000"
unknown's avatar
unknown committed
402 403 404
  }
  if ($opt_innodb)
  {
unknown's avatar
unknown committed
405
    $extra.=" --innodb_data_file_path=ibdata1:100M:autoextend";
unknown's avatar
unknown committed
406
  }
unknown's avatar
unknown committed
407
  safe_system("./bin/mysqld --no-defaults --basedir . --datadir ./data --skip-locking $extra >> $log 2>&1 &");
unknown's avatar
unknown committed
408 409 410
  sleep(2);
}

411 412 413
#
# Compile and install the required Perl modules
#
unknown's avatar
unknown committed
414 415
if ($opt_stage <= 7 && $opt_perl_files && !$opt_no_perl && !$opt_no_test &&
    !$opt_no_benchmark)
unknown's avatar
unknown committed
416
{
unknown's avatar
unknown committed
417
  log_timestamp();
unknown's avatar
unknown committed
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
  safe_cd($test_dir);
  rm_all("perl");
  safe_system("mkdir perl");
  $ENV{'IN_MYSQL_DISTRIBUTION'}=1;
  $ENV{'MYSQL_BUILD'}=$test_dir;

  foreach $module (split(/,/,$opt_perl_files))
  {
    my $options;
    safe_cd("$test_dir/perl");
    if ($opt_debug)
    {
      safe_system("gunzip < $pwd/$module | tar xvf -");
    }
    else
    {
      safe_system("gunzip < $pwd/$module | tar xf -");
    }
    $module =~ m|([^/]+)\.tar\.gz|;
    $module = $1;
    safe_cd($module);
    $options="";
    $options= "--mysql-install --noprompt --mysql-incdir=$test_dir/include --mysql-libdir=$test_dir/lib -nomsql-install -nomsql1-install --mysql-test-db=test $opt_dbd_options" if ($module =~ /Msql-Mysql/);
    $options.= " PREFIX=$pwd/$host INSTALLPRIVLIB=$pwd/$host/perl5 INSTALLSCRIPT=$pwd/$host/bin INSTALLSITELIB=$pwd/$host/perl5/site_perl INSTALLBIN=$pwd/$host/bin INSTALLMAN1DIR=$pwd/$host/man INSTALLMAN3DIR=$pwd/$host/man/man3" if ($opt_local_perl);
    $options.= " $opt_perl_options" if (defined($opt_perl_options));
    safe_system($opt_static_perl ? "perl Makefile.PL -static $options" : "perl Makefile.PL $options");
    safe_system("$make ; $sur $make install");
  }
}

448 449 450
#
# Run crash-me test
#
451
if ($opt_stage <= 8 && !$opt_no_test && !$opt_no_crash_me)
unknown's avatar
unknown committed
452
{
unknown's avatar
unknown committed
453
  log_timestamp();
unknown's avatar
unknown committed
454 455
  safe_cd("$test_dir/sql-bench");
  log_system("rm -f limits/mysql.cfg");
456
  safe_system("perl ./crash-me --force --batch-mode $connect_option");
unknown's avatar
unknown committed
457 458
}

459 460 461
#
# Run sql-bench Benchmarks
#
unknown's avatar
unknown committed
462
if ($opt_stage <= 9 && !$opt_no_test && !$opt_no_benchmark)
unknown's avatar
unknown committed
463
{
unknown's avatar
unknown committed
464
  log_timestamp();
unknown's avatar
unknown committed
465 466 467
  safe_cd("$test_dir/sql-bench");
  log_system("rm -f output/*");
  $tmp= $opt_fast_benchmark ? "--fast --user root --small-test" : "";
468
  check_system("perl ./run-all-tests --log --die-on-errors $connect_option $tmp","RUN-mysql");
469 470
	# Run additional fast test with dynamic-row tables
  check_system("perl ./run-all-tests --log --suffix=\"_dynamic_rows\" --die-on-errors $connect_option --fast --user=root --small-test --create-options=\"row_format=dynamic\"","RUN-mysql");
unknown's avatar
unknown committed
471 472
  if ($opt_innodb)
  {
473
    check_system("perl ./run-all-tests --log --suffix=\"_innodb\" --die-on-errors $connect_option $tmp --create-options=\"type=innodb\"","RUN-mysql");
unknown's avatar
unknown committed
474
  }
475 476
  if ($opt_bdb)
  {
477
    check_system("perl ./run-all-tests --log --suffix=\"_bdb\" --die-on-errors $connect_option $tmp --create-options=\"type=bdb\"","RUN-mysql");
478
  }
unknown's avatar
unknown committed
479 480
}

unknown's avatar
unknown committed
481 482 483
rm_all($bench_tmpdir);
rm_all("$opt_tmp") if ($new_opt_tmp);

484
log_system("$pwd/$host/bin/mysqladmin $mysqladmin_args -S $mysql_unix_port shutdown");
unknown's avatar
unknown committed
485 486 487 488 489 490 491 492 493 494
print LOG "ok\n";
close LOG;
print "$host: ok\n";

exit 0;


sub usage
{
print <<EOF;
495
$0  version 1.6
unknown's avatar
unknown committed
496 497 498

$0 takes the following options:

499 500 501
--bdb
Compile with support for Berkeley DB tables

502 503 504 505 506
--build-thread=<1,2,3...>
When running several Do-compile runs in parallel, each build
should have its own thread ID, so running the test suites
does not cause conflicts with duplicate TCP port numbers.

507
--config-env=<environment for configure>
508 509
To set up the environment, like 'CC=cc CXX=gcc CXXFLAGS=-O3'

510 511 512 513
--config-extra-env <environment for configure>
Additional flags for environment (not CC or CXX). Should be used when one
wants Do-compile to propose proper CC and CXX flags.

514
--config-options=<options>
515 516 517 518 519 520 521 522 523 524 525
To add some extra options to configure (e.g. '--with-perl=yes')

--dbd-options <options>
Options for Makefile.PL when configuring msql-mysql-modules.

--debug
Print all shell commands on stdout.

--delete
Delete the distribution file.

526
--distribution=<distribution_file>
527 528 529 530 531 532 533 534
Name of the MySQL source distribution file.

--enable-shared
Compile with shared libraries

--fast-benchmark
Run fast benchmark only to speed up testing

unknown's avatar
unknown committed
535 536 537
--help or --Information
Show this help

unknown's avatar
unknown committed
538 539 540
--innodb
Compile with support for Innodb tables

541 542
--libwrap
Compile with TCP wrapper support
unknown's avatar
unknown committed
543

544 545
--local-perl
Install Perl modules locally
unknown's avatar
unknown committed
546

547
--make-options=<options>
548
Options to make after configure. (Like 'CXXLD=gcc')
unknown's avatar
unknown committed
549

550 551
--no-crash-me
Do not run the "crash-me" test
unknown's avatar
unknown committed
552

553 554 555 556
--no-strip
Do not strip the binaries included in the binary distribution

--no-test
unknown's avatar
unknown committed
557 558 559 560 561 562
Do not run any tests.

--no-benchmark
Do not run the benchmark test (written in perl)

--no-mysqltest
563 564 565 566
Do not run the mysql-test-run test (Same as 'make test')

--one-error
Terminate the mysql-test-run test after the first difference (default: use '--force')
unknown's avatar
unknown committed
567

568 569 570 571
--no-perl
Do not compile or install Perl modules, use the system installed ones

--perl-files=<list of files>
unknown's avatar
unknown committed
572 573
Compile and install the given perl modules.

574
--perl-options=<options>
575
Build Perl modules with the additional options
unknown's avatar
unknown committed
576

577 578
--raid
Compile with RAID support
unknown's avatar
unknown committed
579

580 581 582 583
--readline
Compile against readline library instead of libedit

--stage=[1-6]
584
Start script from some specific point.
unknown's avatar
unknown committed
585

586 587
--static-client
Build statically linked client binaries
unknown's avatar
unknown committed
588

589 590 591 592 593 594 595 596 597
--static-perl
Build statically linked Perl modules

--static-server
Build statically linked server binary

--tcpip
Connect to the server to be tested via TCP/IP instead of socket

598
--tmp=<directory>
599 600 601 602 603 604
Use a different temporary directory than /tmp

--use-old-distribution
Do not clean up the build environment and extract a fresh source
distribution, use an existing one instead.

605
--user=<user_name>
606 607
Mail 'user_name'\@mysql.com if something went wrong.
If user is empty then no mail is sent.
608

609
--version-suffix=suffix
610
Set name suffix (e.g. 'com' or '-max') for a distribution
611

612
--with cluster
613
Compile and test with NDB Cluster enabled
614

unknown's avatar
unknown committed
615 616 617
--with-debug
Build binaries with debug information (implies "--no-strip")

unknown's avatar
unknown committed
618 619 620
--with-low-memory
Use less memory when compiling.

621
--with-other-libc=<path to libc>
622 623
Link against libc and other standard libraries installed in the specified
non-standard location overriding default.
unknown's avatar
unknown committed
624

625 626 627
--with-small-disk
Clean up the build environment before testing the binary distribution
(to save disk space)
628 629 630

--without-embedded
Don't compile the embedded server.
unknown's avatar
unknown committed
631 632 633 634 635 636 637
EOF
exit 1;
} 

sub abort
{
  my($message)=@_;
638
  my($mail_header_file);
unknown's avatar
unknown committed
639 640
  print LOG "\n$message\n";
  print "$host: $message\n" if ($opt_debug);
unknown's avatar
unknown committed
641
  print LOG "Aborting\n";
unknown's avatar
unknown committed
642 643 644 645 646 647
  close LOG;

  if ($opt_user)
  {
    $mail_header_file="$opt_tmp/do-command.$$";
    open(TMP,">$mail_header_file");
unknown's avatar
unknown committed
648
    print TMP "From: mysqldev\@$full_host_name\n";
unknown's avatar
unknown committed
649
    print TMP "To: $email\n";
unknown's avatar
unknown committed
650
    print TMP "Subject: $host($uname): $ver$opt_version_suffix compilation failed\n\n";
unknown's avatar
unknown committed
651
    close TMP;
652
    system("tail -n 40 $log > $log.mail");
653
    system("cat $mail_header_file $log.mail | $sendmail -t -f $email");
unknown's avatar
unknown committed
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
    unlink($mail_header_file);
    unlink("$log.mail");
  }
  exit 1;
}

sub info
{
  my($message)=@_;
  print LOG "$message\n";
  print "$host: $message\n";
}

sub log_system
{
  my($com)=@_;
  print "$host: $com\n" if ($opt_debug);
  if (defined($log))
  {
    print LOG "$com\n";
    system("$com >> $log 2>&1") &&
      print LOG ("Info: couldn't execute command, error: " . ($? / 256) ."\n");
  }
  else
  {
    system($com) && print "$host: Couldn't execute command, error: " . ($? / 256) ."\n";
  }
}


sub safe_system
{
  my($com,$res)=@_;
  print LOG "$com\n";
  print "$host: $com\n" if ($opt_debug);
unknown's avatar
unknown committed
689 690 691 692
  my $result= system("$com >> $log 2>&1");
  abort("error: Couldn't execute command, error: " . ($? / 256)) unless $result == 0;

  return $result;
unknown's avatar
unknown committed
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
}

sub check_system
{
  my($com,$res)=@_;
  my ($error,$found);
  print LOG "$com\n";
  print "$host: $com\n" if ($opt_debug);
  open (COM, "$com 2>&1 < /dev/null|") || abort("Got error " . ($?/256) ." opening pipe");
  $found=0;
  while (<COM>)
  {
    print LOG $_;
    if (index($_,$res) >= 0)
    {
      $found=1;
      last;
    }
  }
  close COM;
  abort("Couldn't find '$res' in the command result") if (!$found);
  print "$host: Command ok\n" if ($opt_debug);
}

sub safe_cd
{
  my($dir)=@_;
  print LOG "cd $dir\n";
  print "$host: cd $dir\n" if ($opt_debug);
  chdir($dir) || abort("Can't cd to $dir");
}

sub which
{
  my(@progs)=@_;
  foreach $prog (@progs)
  {
730
    chomp($found=`which $prog | head -n 1`);
unknown's avatar
unknown committed
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
    if ($? == 0 && $found ne "" && index($found," ") == -1)
    {
      $found =~ s|/+|/|g;	# Make nicer output
      return $found;
    }
  }
  return undef();
}

sub find
{
  my (@progs)=@_;
  foreach $prog (@progs)
  {
    return $prog if (-x $prog);
  }
  return undef();  
}

#
# Remove recursively all from a directory
# This is needed because problems with NFS and open files
#

sub rm_all
{
  my(@rm_files)=@_;
  my($dir,$current_dir,@files,@dirs);
  $current_dir = `pwd`; chomp($current_dir);

  foreach $dir (@rm_files)
  {
    if (-d $dir)
    {
      chdir($dir) || abort("Can't cd to $dir");
      print "$host: Removing from $dir\n" if ($opt_debug);
      while (<* .*>)
      {
	next if ($_ eq "." x (length($_)));
	if (-d $_)
	{
#	  die "Can't remove directory that starts with ." if ($_ =~ /^\./ && $_ ne ".libs"); # Safety
	  push (@dirs,$_);
	}
	else
	{
	  push (@files,$_);
	}
      }
      if ($#files >= 0)
      {
	system("rm -f " . join(" ",@files)) && abort("Can't remove files from $dir");
      }
      foreach $dir (@dirs)
      {
	rm_all($dir);
      }
      chdir($current_dir) || abort("Can't cd to $current_dir");
      log_system("rmdir $dir");
    }
    else
    {
      system("rm -f $dir") && abort("Can't remove file $dir");
    }
  }
}
unknown's avatar
unknown committed
797 798 799 800

sub kill_all
{
  my ($pattern) = @_;
unknown's avatar
unknown committed
801
  my ($USER,$BSD,$LINUX, $pscmd, $user, $os, $pid);
unknown's avatar
unknown committed
802
  $user=$ENV{'USER'};
unknown's avatar
unknown committed
803 804
  $os=defined($ENV{'OS'}) ? $ENV{'OS'} : "unknown";
  $BSD = -f '/vmunix' || $os eq "SunOS4" || $^O eq 'darwin';
unknown's avatar
unknown committed
805 806 807
  $LINUX = $^O eq 'linux';
  $pscmd = $BSD ? "/bin/ps -auxww" : $LINUX ? "/bin/ps axuw" : "/bin/ps -ef";

unknown's avatar
unknown committed
808 809 810 811 812
  if (!open(PS, "$pscmd|"))
  {
    print "Warning: Can't run $pscmd: $!\n";
    exit;
  }
unknown's avatar
unknown committed
813 814 815 816 817 818 819

  # Catch any errors with eval.  A bad pattern, for instance.
 process:
  while ($cand = <PS>)
  {
    chop($cand);
    ($pid_user, $pid) = split(' ', $cand);
unknown's avatar
unknown committed
820
    next if $pid eq $$;
821 822
    next process if (! ($cand =~ $pattern) || $pid_user ne $user);
    print LOG "Killing $_\n";
unknown's avatar
unknown committed
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
    &killpid($pid);
  }
}

sub killpid
{
  local($pid) = @_;
  kill 15, $pid;
  for (1..5)
  {
    sleep 2;
    return if kill(0, $pid) == 0;
  }
  kill 9, $pid;
  for (1..5) {
    sleep 2;
    return if kill(0, $pid) == 0;
  }
  print LOG "$pid will not die!\n";
}
unknown's avatar
unknown committed
843 844 845 846 847 848 849 850 851 852 853

#
# return the current date as a string (YYYY-MM-DD HH:MM:SS)
#
sub log_timestamp
{
  my @ta=localtime(time());
  print LOG sprintf("%4d-%02d-%02d %02d:%02d:%02d\n",
		    $ta[5]+1900, $ta[4]+1, $ta[3], $ta[2], $ta[1], $ta[0]);

}