Use My::Platform

Put all path conversions in one file
Convert the --tmpdir  passed to "mysqld --verbose --help"
parent bf98940d
......@@ -23,14 +23,14 @@ package My::Find;
use strict;
use Carp;
use My::Platform;
use base qw(Exporter);
our @EXPORT= qw(my_find_bin my_find_dir);
our $vs_config_dir;
my $is_win= ($^O eq "MSWin32" or $^O eq "cygwin");
my $bin_extension= ".exe" if $is_win;
my $bin_extension= ".exe" if IS_WINDOWS;
#
# my_find_bin - find an executable with "name_1...name_n" in
......@@ -56,7 +56,7 @@ sub my_find_bin {
# Find and return the first executable
# -------------------------------------------------------
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);
}
......@@ -120,7 +120,7 @@ sub my_find_paths {
# -------------------------------------------------------
# Windows specific
# -------------------------------------------------------
if ($is_win) {
if (IS_WINDOWS) {
# Add the default extra build dirs unless a specific one has
# already been selected
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;
use base 'My::SafeProcess::Base';
use My::Find;
use My::Platform;
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 {
# Kill any children still running
for my $proc (values %running){
......@@ -163,12 +138,10 @@ sub new {
# }
if (IS_CYGWIN){
# safe_procss is a windows program and need
# windows paths
$path= fixpath($path);
$input= fixpath($input);
$output= fixpath($output);
$error= fixpath($error);
$path= native_path($path);
$input= native_path($input);
$output= native_path($output);
$error= native_path($error);
}
my @safe_args;
......
......@@ -53,6 +53,7 @@ sub collect_option {
use File::Basename;
use IO::File();
use My::Config;
use My::Platform;
require "mtr_match.pl";
require "mtr_misc.pl";
......@@ -744,7 +745,7 @@ sub collect_one_test_case {
my $master_sh= "$testdir/$tname-master.sh";
if ( -f $master_sh )
{
if ( $main::is_win32_perl )
if ( IS_WIN32PERL )
{
$tinfo->{'skip'}= 1;
$tinfo->{'comment'}= "No tests with sh scripts on Windows";
......@@ -762,7 +763,7 @@ sub collect_one_test_case {
my $slave_sh= "$testdir/$tname-slave.sh";
if ( -f $slave_sh )
{
if ( $main::is_win32_perl )
if ( IS_WIN32PERL )
{
$tinfo->{'skip'}= 1;
$tinfo->{'comment'}= "No tests with sh scripts on Windows";
......
......@@ -20,7 +20,8 @@
use strict;
sub mtr_native_path($);
use My::Platform;
sub mtr_init_args ($);
sub mtr_add_arg ($$@);
sub mtr_args2str($@);
......@@ -30,27 +31,6 @@ sub mtr_file_exists(@);
sub mtr_exe_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 ($$@) {
# Quote args if args contain space
$format= "\"$format\""
if ($::is_win32 and grep(/\s/, @fargs));
if (IS_WINDOWS and grep(/\s/, @fargs));
push(@$args, sprintf($format, @fargs));
}
sub mtr_args2str($@) {
my $exe= shift or die;
return join(" ", mtr_native_path($exe), @_);
return join(" ", native_path($exe), @_);
}
##############################################################################
......@@ -109,7 +89,7 @@ sub mtr_path_exists (@) {
sub mtr_script_exists (@) {
foreach my $path ( @_ )
{
if($::is_win32)
if(IS_WINDOWS)
{
return $path if -f $path;
}
......@@ -149,10 +129,10 @@ sub mtr_file_exists (@) {
sub mtr_exe_maybe_exists (@) {
my @path= @_;
map {$_.= ".exe"} @path if $::is_win32;
map {$_.= ".exe"} @path if IS_WINDOWS;
foreach my $path ( @path )
{
if($::is_win32)
if(IS_WINDOWS)
{
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
use File::Basename;
use File::Copy;
use File::Temp qw / tempdir /;
use My::Platform;
use My::SafeProcess;
use My::ConfigFactory;
use My::Options;
use mtr_cases;
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_io.pl";
require "lib/mtr_gcov.pl";
......@@ -400,12 +397,11 @@ sub command_line_setup {
}
# Find the absolute path to the test directory
$glob_mysql_test_dir= cwd();
if ( $is_cygwin )
$glob_mysql_test_dir= cwd();
if (IS_CYGWIN)
{
# Windows programs like 'mysqld' needs Windows paths
$glob_mysql_test_dir= `cygpath -m "$glob_mysql_test_dir"`;
chomp($glob_mysql_test_dir);
# Use mixed path format i.e c:/path/to/
$glob_mysql_test_dir= mixed_path($glob_mysql_test_dir);
}
# In most cases, the base directory we find everything relative to,
......@@ -568,7 +564,7 @@ sub command_line_setup {
# Version 4.1 and --vardir was specified
# Only supported as a symlink from var/
# 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
$opt_mem= $opt_vardir;
......@@ -584,7 +580,7 @@ sub command_line_setup {
# We make the path absolute, as the server will do a chdir() before usage
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
$opt_vardir= "$glob_mysql_test_dir/$opt_vardir";
......@@ -620,16 +616,15 @@ sub command_line_setup {
if ( $opt_embedded_server )
{
$opt_embedded_server= 1;
if ( $is_win32 )
if ( IS_WINDOWS )
{
# Add the location for libmysqld.dll to the path.
my $separator= ";";
my $lib_mysqld=
mtr_path_exists(vs_config_dirs('libmysqld',''));
if ( $is_cygwin )
if ( IS_CYGWIN )
{
$lib_mysqld= `cygpath "$lib_mysqld"`;
chomp($lib_mysqld);
$lib_mysqld= posix_path($lib_mysqld);
$separator= ":";
}
$ENV{'PATH'}= "$ENV{'PATH'}".$separator.$lib_mysqld;
......@@ -802,7 +797,17 @@ sub collect_mysqld_features {
#
# --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))
{
......@@ -964,7 +969,7 @@ sub client_debug_arg($$) {
sub mysql_fix_arguments () {
return "" if ( $is_win32 );
return "" if ( IS_WINDOWS );
my $exe=
mtr_script_exists("$basedir/scripts/mysql_fix_privilege_tables",
......@@ -1202,7 +1207,7 @@ sub environment_setup {
$ENV{'MYSQL_BINLOG'}= client_arguments("mysqlbinlog");
$ENV{'MYSQL'}= client_arguments("mysql");
$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_FIX_SYSTEM_TABLES'}= mysql_fix_arguments();
$ENV{'EXE_MYSQL'}= $exe_mysql;
......@@ -1214,7 +1219,7 @@ sub environment_setup {
my $exe_bug25714=
mtr_exe_maybe_exists(vs_config_dirs('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
......@@ -1231,7 +1236,7 @@ sub environment_setup {
mtr_exe_exists(vs_config_dirs('extra', 'my_print_defaults'),
"$path_client_bindir/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
......@@ -1239,7 +1244,7 @@ sub environment_setup {
my $exe_perror= mtr_exe_exists(vs_config_dirs('extra', 'perror'),
"$basedir/extra/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
# to detect that valgrind is being used from test cases
......@@ -1491,7 +1496,7 @@ sub vs_config_dirs ($$) {
$exe = "" if not defined $exe;
# Don't look in these dirs when not on windows
return () unless $is_win32;
return () unless IS_WINDOWS;
if ($opt_vs_config)
{
......@@ -2614,7 +2619,7 @@ sub mysqld_arguments ($$$) {
# 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
my $euid= $>;
if (!$is_win32 and $euid == 0 and
if (!IS_WINDOWS and $euid == 0 and
(grep(/^--user/, @$extra_opts)) == 0) {
mtr_add_arg($args, "%s--user=root", $prefix);
}
......@@ -2672,7 +2677,7 @@ sub mysqld_arguments ($$$) {
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"});
}
......@@ -3259,8 +3264,7 @@ sub start_mysqltest ($) {
# ----------------------------------------------------------------------
# export MYSQL_TEST variable containing <path>/mysqltest <args>
# ----------------------------------------------------------------------
$ENV{'MYSQL_TEST'}=
mtr_native_path($exe_mysqltest) . " " . join(" ", @$args);
$ENV{'MYSQL_TEST'}= mtr_args2str($exe_mysqltest, @$args);
# ----------------------------------------------------------------------
# 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