pg_upgrade test mods for Windows/Mingw

Started by Andrew Dunstanover 13 years ago5 messages
#1Andrew Dunstan
andrew@dunslane.net
1 attachment(s)

The attached patch is what I had to do to get pg_upgrade's "make check"
to run on Windows under Mingw. Mostly the changes have to do with
getting paths right between Windows and MSys, or calling generated .bat
files instead of shell scripts.

cheers

andrew

Attachments:

pg_upgrade_test.patchtext/x-patch; name=pg_upgrade_test.patchDownload
diff --git a/contrib/pg_upgrade/test.sh b/contrib/pg_upgrade/test.sh
index 31e30af..fc2304a 100644
--- a/contrib/pg_upgrade/test.sh
+++ b/contrib/pg_upgrade/test.sh
@@ -43,13 +43,23 @@ if [ "$1" = '--install' ]; then
 	export EXTRA_REGRESS_OPTS
 fi
 
-: ${oldbindir=$bindir}
-
 : ${oldsrc=../..}
-oldsrc=`cd "$oldsrc" && pwd`
-newsrc=`cd ../.. && pwd`
 
-PATH=$bindir:$PATH
+if [ `uname -a | sed 's/.* //'` = Msys ] ; then
+	cp $libdir/libpq.dll $bindir
+	osbindir=`cd $bindir && pwd`
+	bindir=`cd $bindir && pwd -W`
+	oldsrc=`cd "$oldsrc" && pwd -W`
+	newsrc=`cd ../.. && pwd -W`
+else
+	osbindir=$bindir
+	oldsrc=`cd "$oldsrc" && pwd`
+	newsrc=`cd ../.. && pwd`
+fi
+
+: ${oldbindir=$bindir}
+
+PATH=$osbindir:$PATH
 export PATH
 
 PGDATA=$temp_root/data
@@ -104,10 +114,19 @@ mv "${PGDATA}" "${PGDATA}.old"
 
 initdb
 
+if [ `uname -a | sed 's/.* //'` = Msys ] ; then 
+	PGDATA=`cd $PGDATA && pwd -W`
+fi
+
 pg_upgrade -d "${PGDATA}.old" -D "${PGDATA}" -b "$oldbindir" -B "$bindir"
 
 pg_ctl start -l "$logdir/postmaster2.log" -w
-sh ./analyze_new_cluster.sh
+
+if  [ `uname -a | sed 's/.* //'` = Msys ] ; then
+	cmd /c analyze_new_cluster.bat
+else
+	sh ./analyze_new_cluster.sh
+fi
 pg_dumpall >"$temp_root"/dump2.sql || pg_dumpall2_status=$?
 pg_ctl -m fast stop
 if [ -n "$pg_dumpall2_status" ]; then
@@ -115,7 +134,15 @@ if [ -n "$pg_dumpall2_status" ]; then
 	exit 1
 fi
 
-sh ./delete_old_cluster.sh
+if  [ `uname -a | sed 's/.* //'` = Msys ] ; then
+	sed -i -e 's,/,\\,g' -e 's,\\s\\q ,/s/q ,' delete_old_cluster.bat 2>/dev/null
+	chmod +w delete_old_cluster.bat
+	cmd /c delete_old_cluster.bat
+	dos2unix "$temp_root"/dump1.sql >/dev/null
+	dos2unix "$temp_root"/dump2.sql >/dev/null
+else
+	sh ./delete_old_cluster.sh
+fi
 
 if diff -q "$temp_root"/dump1.sql "$temp_root"/dump2.sql; then
 	echo PASSED
#2Gurjeet Singh
singh.gurjeet@gmail.com
In reply to: Andrew Dunstan (#1)
Re: pg_upgrade test mods for Windows/Mingw

On Sun, Sep 2, 2012 at 11:29 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

The attached patch is what I had to do to get pg_upgrade's "make check" to
run on Windows under Mingw. Mostly the changes have to do with getting
paths right between Windows and MSys, or calling generated .bat files
instead of shell scripts.

When reading shell script code like this

`uname -a | sed 's/.* //'` = Msys

and

sed -i -e 's,/,\\,g' -e 's,\\s\\q ,/s/q ,' delete_old_cluster.bat
2>/dev/null

I find it easier to understand and maintain if the comments also describe
what is the original string format that this pattern-matching expects,
like:

# We expect `uname -a` output like:
# Windows_NT4.0 Msys

and

# We expect lines of the format:
# abc/xyz/def/
# and we convert them to
# abc\xyz\def

BTW, would `uname -o` eliminate the need of pattern matching in the first
snippet? The Wikipedia [1]http://en.wikipedia.org/wiki/Uname article suggests so.

[1]: http://en.wikipedia.org/wiki/Uname

Best regards,
--
Gurjeet Singh

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Gurjeet Singh (#2)
Re: pg_upgrade test mods for Windows/Mingw

Gurjeet Singh <singh.gurjeet@gmail.com> writes:

[ this needs a comment: ]
`uname -a | sed 's/.* //'` = Msys

Also, how about doing that just once and setting a variable to test
as needed later? Multiple copied-and-pasted instances of line noise
like that are risky.

regards, tom lane

#4Andrew Dunstan
andrew@dunslane.net
In reply to: Gurjeet Singh (#2)
Re: pg_upgrade test mods for Windows/Mingw

On 09/02/2012 11:53 PM, Gurjeet Singh wrote:

On Sun, Sep 2, 2012 at 11:29 PM, Andrew Dunstan <andrew@dunslane.net
<mailto:andrew@dunslane.net>> wrote:

The attached patch is what I had to do to get pg_upgrade's "make
check" to run on Windows under Mingw. Mostly the changes have to
do with getting paths right between Windows and MSys, or calling
generated .bat files instead of shell scripts.

When reading shell script code like this

`uname -a | sed 's/.* //'` = Msys

and

sed -i -e 's,/,\\,g' -e 's,\\s\\q ,/s/q ,' delete_old_cluster.bat
2>/dev/null

I find it easier to understand and maintain if the comments also
describe what is the original string format that this
pattern-matching expects, like:

# We expect `uname -a` output like:
# Windows_NT4.0 Msys

and

# We expect lines of the format:
# abc/xyz/def/
# and we convert them to
# abc\xyz\def

BTW, would `uname -o` eliminate the need of pattern matching in the
first snippet? The Wikipedia [1] article suggests so.

[1] http://en.wikipedia.org/wiki/Uname

Yeah it would. This wasn't intended as a final patch anyway, just as
notice of what I actually had working in case anyone else wanted to try.

cheers

andrew

#5Andrew Dunstan
andrew@dunslane.net
In reply to: Andrew Dunstan (#4)
Re: pg_upgrade test mods for Windows/Mingw

On 09/03/2012 09:16 AM, Andrew Dunstan wrote:

On 09/02/2012 11:53 PM, Gurjeet Singh wrote:

On Sun, Sep 2, 2012 at 11:29 PM, Andrew Dunstan <andrew@dunslane.net
<mailto:andrew@dunslane.net>> wrote:

The attached patch is what I had to do to get pg_upgrade's "make
check" to run on Windows under Mingw. Mostly the changes have to
do with getting paths right between Windows and MSys, or calling
generated .bat files instead of shell scripts.

When reading shell script code like this

`uname -a | sed 's/.* //'` = Msys

and

sed -i -e 's,/,\\,g' -e 's,\\s\\q ,/s/q ,' delete_old_cluster.bat
2>/dev/null

BTW, this last one is a hack. pg_upgrade should make sure that it
outputs backslashed paths for rmdir. (In general, the Windows runtime is
quite happy to accept forward-slashed paths, but certain builtin
commands, such as rmdir are not).

cheers

andrew