Commit 28438812 authored by unknown's avatar unknown

Use My::Platform

Put all path conversions in one file
Convert the --tmpdir  passed to "mysqld --verbose --help"


mysql-test/lib/My/Find.pm:
  Use My::Platform
mysql-test/lib/My/SafeProcess.pm:
  use My::Platform
mysql-test/lib/mtr_cases.pm:
  Use My::Platform
mysql-test/lib/mtr_misc.pl:
  Move 'mtr_native_path' to My::Platform
mysql-test/lib/My/Platform.pm:
  New BitKeeper file ``mysql-test/lib/My/Platform.pm''
mysql-test/lib/t/Platform.t:
  New BitKeeper file ``mysql-test/lib/t/Platform.t''
parent bbc8726d
...@@ -23,14 +23,14 @@ package My::Find; ...@@ -23,14 +23,14 @@ package My::Find;
use strict; use strict;
use Carp; use Carp;
use My::Platform;
use base qw(Exporter); use base qw(Exporter);
our @EXPORT= qw(my_find_bin my_find_dir); our @EXPORT= qw(my_find_bin my_find_dir);
our $vs_config_dir; our $vs_config_dir;
my $is_win= ($^O eq "MSWin32" or $^O eq "cygwin"); my $bin_extension= ".exe" if IS_WINDOWS;
my $bin_extension= ".exe" if $is_win;
# #
# my_find_bin - find an executable with "name_1...name_n" in # my_find_bin - find an executable with "name_1...name_n" in
...@@ -56,7 +56,7 @@ sub my_find_bin { ...@@ -56,7 +56,7 @@ sub my_find_bin {
# Find and return the first executable # Find and return the first executable
# ------------------------------------------------------- # -------------------------------------------------------
foreach my $path (my_find_paths($base, $paths, $names, $bin_extension)) { foreach my $path (my_find_paths($base, $paths, $names, $bin_extension)) {
return $path if ( -x $path or ($is_win and -f $path) ); return $path if ( -x $path or (IS_WINDOWS and -f $path) );
} }
find_error($base, $paths, $names); find_error($base, $paths, $names);
} }
...@@ -120,7 +120,7 @@ sub my_find_paths { ...@@ -120,7 +120,7 @@ sub my_find_paths {
# ------------------------------------------------------- # -------------------------------------------------------
# Windows specific # Windows specific
# ------------------------------------------------------- # -------------------------------------------------------
if ($is_win) { if (IS_WINDOWS) {
# Add the default extra build dirs unless a specific one has # Add the default extra build dirs unless a specific one has
# already been selected # already been selected
push(@extra_dirs, push(@extra_dirs,
......
# -*- cperl -*-
# Copyright (C) 2004-2006 MySQL AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package My::Platform;
use strict;
use base qw(Exporter);
our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL
native_path posix_path mixed_path);
BEGIN {
if ($^O eq "cygwin") {
# Make sure cygpath works
if ((system("cygpath > /dev/null 2>&1") >> 8) != 1){
die "Could not execute 'cygpath': $!";
}
eval 'sub IS_CYGWIN { 1 }';
}
else {
eval 'sub IS_CYGWIN { 0 }';
}
if ($^O eq "MSWin32") {
eval 'sub IS_WIN32PERL { 1 }';
}
else {
eval 'sub IS_WIN32PERL { 0 }';
}
}
BEGIN {
if (IS_CYGWIN or IS_WIN32PERL) {
eval 'sub IS_WINDOWS { 1 }';
}
else {
eval 'sub IS_WINDOWS { 0 }';
}
}
#
# native_path
# Convert from path format used by perl to the underlying
# operating systems format
#
# NOTE
# Used when running windows binaries (that expect windows paths)
# in cygwin perl (that uses unix paths)
#
sub mixed_path {
my ($path)= @_;
if (IS_CYGWIN){
return unless defined $path;
$path= `cygpath -m $path`;
chomp $path;
}
return $path;
}
sub native_path {
my ($path)= @_;
$path=~ s/\//\\/g
if (IS_CYGWIN or IS_WIN32PERL);
return $path;
}
sub posix_path {
my ($path)= @_;
if (IS_CYGWIN){
return unless defined $path;
$path= `cygpath $path`;
chomp $path;
}
return $path;
}
1;
...@@ -56,35 +56,10 @@ use My::SafeProcess::Base; ...@@ -56,35 +56,10 @@ use My::SafeProcess::Base;
use base 'My::SafeProcess::Base'; use base 'My::SafeProcess::Base';
use My::Find; use My::Find;
use My::Platform;
my %running; my %running;
BEGIN {
if ($^O eq "MSWin32") {
eval 'sub IS_WIN32PERL () { 1 }';
}
else {
eval 'sub IS_WIN32PERL () { 0 }';
}
if ($^O eq "cygwin") {
eval 'sub IS_CYGWIN () { 1 }';
# Make sure cygpath works
if ((system("cygpath > /dev/null 2>&1") >> 8) != 1){
die "Could not execute 'cygpath': $!";
}
eval 'sub fixpath {
my ($path)= @_;
return unless defined $path;
$path= `cygpath -w $path`;
chomp $path;
return $path;
}';
}
else {
eval 'sub IS_CYGWIN () { 0 }';
}
}
END { END {
# Kill any children still running # Kill any children still running
for my $proc (values %running){ for my $proc (values %running){
...@@ -163,12 +138,10 @@ sub new { ...@@ -163,12 +138,10 @@ sub new {
# } # }
if (IS_CYGWIN){ if (IS_CYGWIN){
# safe_procss is a windows program and need $path= native_path($path);
# windows paths $input= native_path($input);
$path= fixpath($path); $output= native_path($output);
$input= fixpath($input); $error= native_path($error);
$output= fixpath($output);
$error= fixpath($error);
} }
my @safe_args; my @safe_args;
......
...@@ -53,6 +53,7 @@ sub collect_option { ...@@ -53,6 +53,7 @@ sub collect_option {
use File::Basename; use File::Basename;
use IO::File(); use IO::File();
use My::Config; use My::Config;
use My::Platform;
require "mtr_match.pl"; require "mtr_match.pl";
require "mtr_misc.pl"; require "mtr_misc.pl";
...@@ -744,7 +745,7 @@ sub collect_one_test_case { ...@@ -744,7 +745,7 @@ sub collect_one_test_case {
my $master_sh= "$testdir/$tname-master.sh"; my $master_sh= "$testdir/$tname-master.sh";
if ( -f $master_sh ) if ( -f $master_sh )
{ {
if ( $main::is_win32_perl ) if ( IS_WIN32PERL )
{ {
$tinfo->{'skip'}= 1; $tinfo->{'skip'}= 1;
$tinfo->{'comment'}= "No tests with sh scripts on Windows"; $tinfo->{'comment'}= "No tests with sh scripts on Windows";
...@@ -762,7 +763,7 @@ sub collect_one_test_case { ...@@ -762,7 +763,7 @@ sub collect_one_test_case {
my $slave_sh= "$testdir/$tname-slave.sh"; my $slave_sh= "$testdir/$tname-slave.sh";
if ( -f $slave_sh ) if ( -f $slave_sh )
{ {
if ( $main::is_win32_perl ) if ( IS_WIN32PERL )
{ {
$tinfo->{'skip'}= 1; $tinfo->{'skip'}= 1;
$tinfo->{'comment'}= "No tests with sh scripts on Windows"; $tinfo->{'comment'}= "No tests with sh scripts on Windows";
......
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
use strict; use strict;
sub mtr_native_path($); use My::Platform;
sub mtr_init_args ($); sub mtr_init_args ($);
sub mtr_add_arg ($$@); sub mtr_add_arg ($$@);
sub mtr_args2str($@); sub mtr_args2str($@);
...@@ -30,27 +31,6 @@ sub mtr_file_exists(@); ...@@ -30,27 +31,6 @@ sub mtr_file_exists(@);
sub mtr_exe_exists(@); sub mtr_exe_exists(@);
sub mtr_exe_maybe_exists(@); sub mtr_exe_maybe_exists(@);
##############################################################################
#
# Misc
#
##############################################################################
# Convert path to OS native format
sub mtr_native_path($)
{
my $path= shift;
# MySQL version before 5.0 still use cygwin, no need
# to convert path
return $path
if ($::mysql_version_id < 50000);
$path=~ s/\//\\/g
if ($::is_win32);
return $path;
}
############################################################################## ##############################################################################
# #
...@@ -70,14 +50,14 @@ sub mtr_add_arg ($$@) { ...@@ -70,14 +50,14 @@ sub mtr_add_arg ($$@) {
# Quote args if args contain space # Quote args if args contain space
$format= "\"$format\"" $format= "\"$format\""
if ($::is_win32 and grep(/\s/, @fargs)); if (IS_WINDOWS and grep(/\s/, @fargs));
push(@$args, sprintf($format, @fargs)); push(@$args, sprintf($format, @fargs));
} }
sub mtr_args2str($@) { sub mtr_args2str($@) {
my $exe= shift or die; my $exe= shift or die;
return join(" ", mtr_native_path($exe), @_); return join(" ", native_path($exe), @_);
} }
############################################################################## ##############################################################################
...@@ -109,7 +89,7 @@ sub mtr_path_exists (@) { ...@@ -109,7 +89,7 @@ sub mtr_path_exists (@) {
sub mtr_script_exists (@) { sub mtr_script_exists (@) {
foreach my $path ( @_ ) foreach my $path ( @_ )
{ {
if($::is_win32) if(IS_WINDOWS)
{ {
return $path if -f $path; return $path if -f $path;
} }
...@@ -149,10 +129,10 @@ sub mtr_file_exists (@) { ...@@ -149,10 +129,10 @@ sub mtr_file_exists (@) {
sub mtr_exe_maybe_exists (@) { sub mtr_exe_maybe_exists (@) {
my @path= @_; my @path= @_;
map {$_.= ".exe"} @path if $::is_win32; map {$_.= ".exe"} @path if IS_WINDOWS;
foreach my $path ( @path ) foreach my $path ( @path )
{ {
if($::is_win32) if(IS_WINDOWS)
{ {
return $path if -f $path; return $path if -f $path;
} }
......
# -*- cperl -*-
use Test::More qw(no_plan);
use strict;
use_ok ("My::Platform");
use My::Platform;
use File::Temp qw / tempdir /;
my $dir = tempdir( CLEANUP => 1 );
print "Running on Windows\n" if (IS_WINDOWS);
print "Using ActiveState perl\n" if (IS_WIN32PERL);
print "Using cygwin perl\n" if (IS_CYGWIN);
print "dir: '$dir'\n";
print "native: '".native_path($dir)."'\n";
print "mixed: '".mixed_path($dir)."'\n";
print "posix: '".posix_path($dir)."'\n";
...@@ -43,16 +43,13 @@ use My::File::Path; # Patched version of File::Path ...@@ -43,16 +43,13 @@ use My::File::Path; # Patched version of File::Path
use File::Basename; use File::Basename;
use File::Copy; use File::Copy;
use File::Temp qw / tempdir /; use File::Temp qw / tempdir /;
use My::Platform;
use My::SafeProcess; use My::SafeProcess;
use My::ConfigFactory; use My::ConfigFactory;
use My::Options; use My::Options;
use mtr_cases; use mtr_cases;
use mtr_report; use mtr_report;
our $is_win32_perl= ($^O eq "MSWin32"); # ActiveState Win32 Perl
our $is_cygwin= ($^O eq "cygwin"); # Cygwin Perl
our $is_win32= ($is_win32_perl or $is_cygwin);
require "lib/mtr_process.pl"; require "lib/mtr_process.pl";
require "lib/mtr_io.pl"; require "lib/mtr_io.pl";
require "lib/mtr_gcov.pl"; require "lib/mtr_gcov.pl";
...@@ -400,12 +397,11 @@ sub command_line_setup { ...@@ -400,12 +397,11 @@ sub command_line_setup {
} }
# Find the absolute path to the test directory # Find the absolute path to the test directory
$glob_mysql_test_dir= cwd(); $glob_mysql_test_dir= cwd();
if ( $is_cygwin ) if (IS_CYGWIN)
{ {
# Windows programs like 'mysqld' needs Windows paths # Use mixed path format i.e c:/path/to/
$glob_mysql_test_dir= `cygpath -m "$glob_mysql_test_dir"`; $glob_mysql_test_dir= mixed_path($glob_mysql_test_dir);
chomp($glob_mysql_test_dir);
} }
# In most cases, the base directory we find everything relative to, # In most cases, the base directory we find everything relative to,
...@@ -568,7 +564,7 @@ sub command_line_setup { ...@@ -568,7 +564,7 @@ sub command_line_setup {
# Version 4.1 and --vardir was specified # Version 4.1 and --vardir was specified
# Only supported as a symlink from var/ # Only supported as a symlink from var/
# by setting up $opt_mem that symlink will be created # by setting up $opt_mem that symlink will be created
if ( ! $is_win32 ) if ( ! IS_WINDOWS )
{ {
# Only platforms that have native symlinks can use the vardir trick # Only platforms that have native symlinks can use the vardir trick
$opt_mem= $opt_vardir; $opt_mem= $opt_vardir;
...@@ -584,7 +580,7 @@ sub command_line_setup { ...@@ -584,7 +580,7 @@ sub command_line_setup {
# We make the path absolute, as the server will do a chdir() before usage # We make the path absolute, as the server will do a chdir() before usage
unless ( $opt_vardir =~ m,^/, or unless ( $opt_vardir =~ m,^/, or
($is_win32 and $opt_vardir =~ m,^[a-z]:/,i) ) (IS_WINDOWS and $opt_vardir =~ m,^[a-z]:/,i) )
{ {
# Make absolute path, relative test dir # Make absolute path, relative test dir
$opt_vardir= "$glob_mysql_test_dir/$opt_vardir"; $opt_vardir= "$glob_mysql_test_dir/$opt_vardir";
...@@ -620,16 +616,15 @@ sub command_line_setup { ...@@ -620,16 +616,15 @@ sub command_line_setup {
if ( $opt_embedded_server ) if ( $opt_embedded_server )
{ {
$opt_embedded_server= 1; $opt_embedded_server= 1;
if ( $is_win32 ) if ( IS_WINDOWS )
{ {
# Add the location for libmysqld.dll to the path. # Add the location for libmysqld.dll to the path.
my $separator= ";"; my $separator= ";";
my $lib_mysqld= my $lib_mysqld=
mtr_path_exists(vs_config_dirs('libmysqld','')); mtr_path_exists(vs_config_dirs('libmysqld',''));
if ( $is_cygwin ) if ( IS_CYGWIN )
{ {
$lib_mysqld= `cygpath "$lib_mysqld"`; $lib_mysqld= posix_path($lib_mysqld);
chomp($lib_mysqld);
$separator= ":"; $separator= ":";
} }
$ENV{'PATH'}= "$ENV{'PATH'}".$separator.$lib_mysqld; $ENV{'PATH'}= "$ENV{'PATH'}".$separator.$lib_mysqld;
...@@ -802,7 +797,17 @@ sub collect_mysqld_features { ...@@ -802,7 +797,17 @@ sub collect_mysqld_features {
# #
# --datadir must exist, mysqld will chdir into it # --datadir must exist, mysqld will chdir into it
# #
my $list= `$exe_mysqld --no-defaults --datadir=$tmpdir --language=$path_language --skip-grant-tables --verbose --help`; my $args;
mtr_init_args(\$args);
mtr_add_arg($args, "--no-defaults");
mtr_add_arg($args, "--datadir=%s", mixed_path($tmpdir));
mtr_add_arg($args, "--language=%s", $path_language);
mtr_add_arg($args, "--skip-grant-tables");
mtr_add_arg($args, "--verbose");
mtr_add_arg($args, "--help");
my $cmd= join(" ", $exe_mysqld, @$args);
my $list= `$cmd`;
foreach my $line (split('\n', $list)) foreach my $line (split('\n', $list))
{ {
...@@ -964,7 +969,7 @@ sub client_debug_arg($$) { ...@@ -964,7 +969,7 @@ sub client_debug_arg($$) {
sub mysql_fix_arguments () { sub mysql_fix_arguments () {
return "" if ( $is_win32 ); return "" if ( IS_WINDOWS );
my $exe= my $exe=
mtr_script_exists("$basedir/scripts/mysql_fix_privilege_tables", mtr_script_exists("$basedir/scripts/mysql_fix_privilege_tables",
...@@ -1202,7 +1207,7 @@ sub environment_setup { ...@@ -1202,7 +1207,7 @@ sub environment_setup {
$ENV{'MYSQL_BINLOG'}= client_arguments("mysqlbinlog"); $ENV{'MYSQL_BINLOG'}= client_arguments("mysqlbinlog");
$ENV{'MYSQL'}= client_arguments("mysql"); $ENV{'MYSQL'}= client_arguments("mysql");
$ENV{'MYSQL_UPGRADE'}= client_arguments("mysql_upgrade"); $ENV{'MYSQL_UPGRADE'}= client_arguments("mysql_upgrade");
$ENV{'MYSQLADMIN'}= mtr_native_path($exe_mysqladmin); $ENV{'MYSQLADMIN'}= native_path($exe_mysqladmin);
$ENV{'MYSQL_CLIENT_TEST'}= mysql_client_test_arguments(); $ENV{'MYSQL_CLIENT_TEST'}= mysql_client_test_arguments();
$ENV{'MYSQL_FIX_SYSTEM_TABLES'}= mysql_fix_arguments(); $ENV{'MYSQL_FIX_SYSTEM_TABLES'}= mysql_fix_arguments();
$ENV{'EXE_MYSQL'}= $exe_mysql; $ENV{'EXE_MYSQL'}= $exe_mysql;
...@@ -1214,7 +1219,7 @@ sub environment_setup { ...@@ -1214,7 +1219,7 @@ sub environment_setup {
my $exe_bug25714= my $exe_bug25714=
mtr_exe_maybe_exists(vs_config_dirs('tests', 'bug25714'), mtr_exe_maybe_exists(vs_config_dirs('tests', 'bug25714'),
"$basedir/tests/bug25714"); "$basedir/tests/bug25714");
$ENV{'MYSQL_BUG25714'}= mtr_native_path($exe_bug25714); $ENV{'MYSQL_BUG25714'}= native_path($exe_bug25714);
# ---------------------------------------------------- # ----------------------------------------------------
# mysql_fix_privilege_tables.sql # mysql_fix_privilege_tables.sql
...@@ -1231,7 +1236,7 @@ sub environment_setup { ...@@ -1231,7 +1236,7 @@ sub environment_setup {
mtr_exe_exists(vs_config_dirs('extra', 'my_print_defaults'), mtr_exe_exists(vs_config_dirs('extra', 'my_print_defaults'),
"$path_client_bindir/my_print_defaults", "$path_client_bindir/my_print_defaults",
"$basedir/extra/my_print_defaults"); "$basedir/extra/my_print_defaults");
$ENV{'MYSQL_MY_PRINT_DEFAULTS'}= mtr_native_path($exe_my_print_defaults); $ENV{'MYSQL_MY_PRINT_DEFAULTS'}= native_path($exe_my_print_defaults);
# ---------------------------------------------------- # ----------------------------------------------------
# perror # perror
...@@ -1239,7 +1244,7 @@ sub environment_setup { ...@@ -1239,7 +1244,7 @@ sub environment_setup {
my $exe_perror= mtr_exe_exists(vs_config_dirs('extra', 'perror'), my $exe_perror= mtr_exe_exists(vs_config_dirs('extra', 'perror'),
"$basedir/extra/perror", "$basedir/extra/perror",
"$path_client_bindir/perror"); "$path_client_bindir/perror");
$ENV{'MY_PERROR'}= mtr_native_path($exe_perror); $ENV{'MY_PERROR'}= native_path($exe_perror);
# Create an environment variable to make it possible # Create an environment variable to make it possible
# to detect that valgrind is being used from test cases # to detect that valgrind is being used from test cases
...@@ -1491,7 +1496,7 @@ sub vs_config_dirs ($$) { ...@@ -1491,7 +1496,7 @@ sub vs_config_dirs ($$) {
$exe = "" if not defined $exe; $exe = "" if not defined $exe;
# Don't look in these dirs when not on windows # Don't look in these dirs when not on windows
return () unless $is_win32; return () unless IS_WINDOWS;
if ($opt_vs_config) if ($opt_vs_config)
{ {
...@@ -2614,7 +2619,7 @@ sub mysqld_arguments ($$$) { ...@@ -2614,7 +2619,7 @@ sub mysqld_arguments ($$$) {
# When mysqld is run by a root user(euid is 0), it will fail # When mysqld is run by a root user(euid is 0), it will fail
# to start unless we specify what user to run as, see BUG#30630 # to start unless we specify what user to run as, see BUG#30630
my $euid= $>; my $euid= $>;
if (!$is_win32 and $euid == 0 and if (!IS_WINDOWS and $euid == 0 and
(grep(/^--user/, @$extra_opts)) == 0) { (grep(/^--user/, @$extra_opts)) == 0) {
mtr_add_arg($args, "%s--user=root", $prefix); mtr_add_arg($args, "%s--user=root", $prefix);
} }
...@@ -2672,7 +2677,7 @@ sub mysqld_arguments ($$$) { ...@@ -2672,7 +2677,7 @@ sub mysqld_arguments ($$$) {
mtr_add_arg($args, "%s%s", $prefix, "--core-file"); mtr_add_arg($args, "%s%s", $prefix, "--core-file");
} }
if ( $is_win32 ){ if ( IS_WINDOWS ){
mtr_add_arg($args, "%s--log-error=%s", $prefix, $mysqld->{"path_myerr"}); mtr_add_arg($args, "%s--log-error=%s", $prefix, $mysqld->{"path_myerr"});
} }
...@@ -3259,8 +3264,7 @@ sub start_mysqltest ($) { ...@@ -3259,8 +3264,7 @@ sub start_mysqltest ($) {
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# export MYSQL_TEST variable containing <path>/mysqltest <args> # export MYSQL_TEST variable containing <path>/mysqltest <args>
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
$ENV{'MYSQL_TEST'}= $ENV{'MYSQL_TEST'}= mtr_args2str($exe_mysqltest, @$args);
mtr_native_path($exe_mysqltest) . " " . join(" ", @$args);
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Add arguments that should not go into the MYSQL_TEST env var # Add arguments that should not go into the MYSQL_TEST env var
......
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