Prechádzať zdrojové kódy

OSGeo4W workflow for GitHub Actions (#692)

Add a new workflow for compiling GRASS GIS with OSGeo4W and MSYS2 on Windows. It also runs unit tests using the `grass.gunittest.main` module and [nc_spm_full_v2alpha2 data set](http://fatra.cnr.ncsu.edu/data/nc_spm_full_v2alpha2.tar.gz).
Huidae Cho 4 rokov pred
rodič
commit
7a5e93310e

+ 143 - 0
.github/workflows/build_osgeo4w.sh

@@ -0,0 +1,143 @@
+#!/bin/sh
+#
+# Usage: build_osgeo4w.sh [-p] [path]
+#
+# By default, the script will look for the source code in the current directory
+# and create bin.x86_64-w64-mingw32\grass$ver.bat (run this batch file to start
+# GRASS GIS) and dist.x86_64-w64-mingw32\etc\env.bat.
+#
+# -p	optionally install GRASS GIS to C:\OSGeo4W64\opt\grass (run
+#	C:\OSGeo4W64\opt\grass\grass$ver.bat) and create an unzippable package
+#	grass$ver-x86_64-w64-mingw32-osgeo4w64-$date.zip
+#
+# path	specify a path to the source code
+#
+
+# stop on errors
+set -e
+
+if [ "$1" = "-p" ]; then
+	package=1
+	shift
+else
+	package=0
+fi
+
+test -d "$1" && cd "$1"
+
+osgeo4w_path=/c/OSGeo4W64
+arch=x86_64-w64-mingw32
+src=`pwd`
+
+# compile
+
+export PATH=/mingw64/bin:/c/OSGeo4W64/bin:/usr/bin
+export PROJ_LIB=$osgeo4w_path/share/proj
+
+OSGEO4W_ROOT_MSYS=$osgeo4w_path \
+./configure \
+--host=$arch \
+--with-includes=$osgeo4w_path/include \
+--with-libs="$osgeo4w_path/lib $osgeo4w_path/bin" \
+--with-nls \
+--with-freetype-includes=$osgeo4w_path/include/freetype2 \
+--with-bzlib \
+--with-geos=$src/mswindows/osgeo4w/geos-config \
+--with-netcdf=$osgeo4w_path/bin/nc-config \
+--with-gdal=$src/mswindows/osgeo4w/gdal-config \
+--with-liblas=$src/mswindows/osgeo4w/liblas-config \
+--with-opengl=windows
+
+make
+
+# install
+
+bin=bin.$arch
+dist=dist.$arch
+ver=`sed -n '/^INST_DIR[ \t]*=/{s/^.*grass//; p}' include/Make/Platform.make`
+
+rm -f $dist/grass$ver.tmp $dist/etc/fontcap
+
+# create batch files
+
+src_esc=`echo $src | sed 's#^/\([a-z]\)#\1:#; s#/#\\\\\\\\#g'`
+dist_esc="$src_esc\\\\$dist"
+
+(
+sed 's/^\(set GISBASE=\).*/\1'$dist_esc'/' \
+    mswindows/osgeo4w/env.bat.tmpl
+cat<<EOT
+
+set PATH=C:\\msys64\\mingw64\\bin;%OSGEO4W_ROOT%\\apps\\msys\\bin;%PATH%
+
+if not exist %GISBASE%\etc\fontcap (
+	pushd .
+	%~d0
+	cd %GISBASE%\lib
+	set GISRC=dummy
+	%GISBASE%\bin\g.mkfontcap.exe
+	popd
+)
+EOT
+) > $dist/etc/env.bat
+unix2dos $dist/etc/env.bat
+
+(
+sed -e 's/^\(call "\)%~dp0\(.*\)$/\1C:\\OSGeo4W64\\bin\2/' \
+    -e 's/^\(call "\).*\(\\etc\\env\.bat"\)$/\1'$dist_esc'\2/' \
+    -e 's/^\(.* "\)%GISBASE%\\etc\(\\grass.*\)$/\1%GISBASE%\\..\\'$bin'\2/' \
+    -e 's/@POSTFIX@/'$ver'/g' \
+    mswindows/osgeo4w/grass.bat.tmpl
+) > $bin/grass$ver.bat
+unix2dos $bin/grass$ver.bat
+
+test $package -eq 0 && exit
+
+# package
+
+opt_path=$osgeo4w_path/opt
+grass_path=$opt_path/grass
+
+mkdir -p $opt_path
+cp -a $dist $grass_path
+cp -a $bin/grass$ver.py $grass_path/etc
+cp -a `ldd $dist/lib/*.dll | awk '/mingw64/{print $3}' |
+	sort -u | grep -v 'lib\(crypto\|ssl\)'` $grass_path/lib
+
+(
+sed -e 's/^\(set GISBASE=\).*/\1%OSGEO4W_ROOT%\\opt\\grass/' \
+    mswindows/osgeo4w/env.bat.tmpl
+cat<<EOT
+
+set PATH=%OSGEO4W_ROOT%\\apps\\msys\\bin;%PATH%
+
+if not exist %GISBASE%\etc\fontcap (
+	pushd .
+	%~d0
+	cd %GISBASE%\lib
+	set GISRC=dummy
+	%GISBASE%\bin\g.mkfontcap.exe
+	popd
+)
+EOT
+) > $grass_path/etc/env.bat
+unix2dos $grass_path/etc/env.bat
+
+(
+sed -e 's/^\(call "%~dp0\)\(.*\)$/\1\\..\\..\\bin\2/' \
+    -e 's/^\(call "%OSGEO4W_ROOT%\\\).*\(\\etc\\env\.bat"\)$/\1opt\\grass\2/' \
+    -e 's/@POSTFIX@/'$ver'/g' \
+    mswindows/osgeo4w/grass.bat.tmpl
+) > $grass_path/grass$ver.bat
+unix2dos $grass_path/grass$ver.bat
+
+exit
+
+# don't package for GitHub workflow; unnecessary
+
+osgeo4w_basename=`basename $osgeo4w_path`
+date=`date +%Y%m%d`
+zip=$src/grass$ver-$arch-osgeo4w64-$date.zip
+
+cd $osgeo4w_path/..
+zip -r $zip $osgeo4w_basename -x "$osgeo4w_basename/var/*" "*/__pycache__/*"

+ 37 - 0
.github/workflows/osgeo4w.yml

@@ -0,0 +1,37 @@
+name: OSGeo4W
+
+on:
+- push
+- pull_request
+
+jobs:
+  build:
+    name: ${{ matrix.os }} build and tests
+
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os:
+        - windows-2019
+      fail-fast: false
+
+    steps:
+    - name: Set git to use LF
+      run: |
+        git config --global core.autocrlf false
+        git config --global core.eol lf
+    - uses: actions/checkout@v2
+    - name: Install OSGeo4W
+      run: |
+        $exe = 'osgeo4w-setup-x86_64.exe'
+        $url = 'http://download.osgeo.org/osgeo4w/' + $exe
+        (New-Object System.Net.WebClient).DownloadFile($url, $exe)
+        Start-Process ('.\'+$exe) -ArgumentList '-A -g -k -q -s http://download.osgeo.org/x86_64 -P cairo,fftw,freetype-devel,gdal-ecw,gdal-mrsid,liblas-devel,libxdr,msys,pdcurses,python3-numpy,python3-pywin32,python3-wx,regex-devel,wxpython,zstd-devel' -Wait
+    - name: Install MSYS2 packages
+      run: C:\msys64\usr\bin\pacman.exe --noconfirm -S tar libintl make bison diffutils git dos2unix zip mingw-w64-x86_64-toolchain mingw-w64-x86_64-cairo mingw-w64-x86_64-python3-six
+    - name: Compile GRASS GIS
+      run: C:\msys64\usr\bin\bash.exe -l (''+(Get-Location)+'\.github\workflows\build_osgeo4w.sh') -p (Get-Location)
+    - name: Test executing of the grass command
+      run: .github/workflows/test_simple.bat 'C:\OSGeo4W64\opt\grass\grass79.bat'
+    - name: Run tests
+      run: .github/workflows/test_thorough.bat 'C:\OSGeo4W64\opt\grass\grass79.bat'

+ 3 - 0
.github/workflows/test_simple.bat

@@ -0,0 +1,3 @@
+set grass=%1
+
+call %grass% --tmp-location EPSG:4326 --exec g.region res=0.1 -p

+ 6 - 0
.github/workflows/test_thorough.bat

@@ -0,0 +1,6 @@
+set grass=%1
+set python=C:\OSGeo4W64\bin\python3
+
+call %grass% --tmp-location XY --exec g.extension g.download.location
+call %grass% --tmp-location XY --exec g.download.location url=http://fatra.cnr.ncsu.edu/data/nc_spm_full_v2alpha2.tar.gz dbase=%USERPROFILE%
+call %grass% --tmp-location XY --exec %python% -m grass.gunittest.main --grassdata %USERPROFILE% --location nc_spm_full_v2alpha2 --location-type nc --min-success 60

+ 4 - 1
lib/python/gunittest/case.py

@@ -19,7 +19,7 @@ import unittest
 
 from grass.pygrass.modules import Module
 from grass.exceptions import CalledModuleError
-from grass.script import shutil_which, text_to_string, encode
+from grass.script import shutil_which, text_to_string, encode, decode
 
 from .gmodules import call_module, SimpleModule
 from .checkers import (check_text_ellipsis,
@@ -184,6 +184,9 @@ class TestCase(unittest.TestCase):
 
         See :func:`check_text_ellipsis` for details of behavior.
         """
+        # actual is in the system codec while the passed reference is in utf-8;
+        # re-decode reference into the system codec for proper comparison
+        reference = decode(encode(reference, 'utf-8'))
         self.assertTrue(isinstance(actual, (str, unicode)), (
                         'actual argument is not a string'))
         self.assertTrue(isinstance(reference, (str, unicode)), (

+ 8 - 3
lib/python/gunittest/reporters.py

@@ -95,12 +95,17 @@ class FileAnonymizer(object):
         # besides GISBASE and test recursion start directory (which is
         # supposed to be source root directory or similar) we can also try
         # to remove user home directory and GISDBASE
-        # we suppuse that we run in standard grass session
+        # we suppose that we run in standard grass session
         # TODO: provide more effective implementation
+
+        # regex for a trailing separator
+        path_end = r'[\\/]?'
         for path in self._paths_to_remove:
             for filename in filenames:
-                path_end = r'[\\/]?'
-                replace_in_file(filename, path + path_end, '')
+                # literal special characters (e.g., ^\()[]{}.*+-$) in path need
+                # to be escaped in a regex (2nd argument); otherwise, they will
+                # be interpreted as special characters
+                replace_in_file(filename, re.escape(path) + path_end, '')
 
 
 def get_source_url(path, revision, line=None):

+ 2 - 2
scripts/r.blend/testsuite/test_r_blend.py

@@ -24,7 +24,7 @@ class TestRBlend(TestCase):
         """Create maps in a small region."""
         cls.use_temp_region()
         cls.runModule('g.region', raster=cls.map1, flags='p')
-        run_command('d.mon', start='wx0')
+        run_command('d.mon', start='png')
 
     @classmethod
     def tearDownClass(cls):
@@ -32,7 +32,7 @@ class TestRBlend(TestCase):
         cls.runModule('g.remove', flags='f', type='raster',
                       name=(cls.temp1, cls.temp2, cls.temp3))
         cls.del_temp_region()
-        run_command('d.mon', stop='wx0')
+        run_command('d.mon', stop='png')
 
     def test_blend(self):
         """blends color test"""