[dia: 64/105] #19: Set env in tests and replace `ninja run` with run_with_dia_env.sh.



commit 15c21fa4c238fb0e8efff739dec03012b32b32e8
Author: Eduard Nicodei <eddnicodei gmail com>
Date:   Sun Jan 6 19:40:14 2019 +0000

    #19: Set env in tests and replace `ninja run` with run_with_dia_env.sh.
    
      - This was the more elegant solution as it allows tests to be ran
        under a specific environment and at the same time it allows us to
        run the dia app under any sort of harness we want.
      - Note that this fixes neduard/dia#2.

 app/meson.build              |  4 +++-
 generate_run_with_dia_env.sh | 24 ++++++++++++++++++++++++
 meson.build                  | 16 ++++++++++++----
 tests/exports/meson.build    | 14 ++++++--------
 tests/meson.build            | 19 ++++++++++++-------
 tests/run_dia.sh             | 16 ----------------
 tests/xmllint_test.sh        |  5 ++---
 7 files changed, 59 insertions(+), 39 deletions(-)
---
diff --git a/app/meson.build b/app/meson.build
index 4d4249f9..2b2ccb1d 100644
--- a/app/meson.build
+++ b/app/meson.build
@@ -74,7 +74,7 @@ endif
 
 diaapp_inc = include_directories('.')
 
-rundeps += executable('dia',
+diaapp = executable('dia',
     dia_sources + [dia_app_icons_h, diamarshal_h],
     dependencies : [libgtk_dep, libxml_dep, libm_dep],
     link_with : [libdia],
@@ -85,3 +85,5 @@ rundeps += executable('dia',
     install : true,
     install_rpath : dialibdir
 )
+
+rundeps += diaapp
diff --git a/generate_run_with_dia_env.sh b/generate_run_with_dia_env.sh
new file mode 100755
index 00000000..e7f05508
--- /dev/null
+++ b/generate_run_with_dia_env.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env sh
+if [ !  -d "$2" ] || [ ! -d "$3" ]; then
+    echo Unable to find both directory $2 and $3.
+fi
+
+SOURCE_ROOT=$2
+BUILD_ROOT=$3
+
+# This unfortunately is a duplication of run_env in
+# tests/meson.build.  This is fine as long as this
+# script is only used to generate run_with_dia_env
+# and only that.
+cat > $1 << EOF
+#!/usr/bin/env sh
+export DIA_BASE_PATH=${SOURCE_ROOT}
+export DIA_LIB_PATH=${BUILD_ROOT}/objects:${BUILD_ROOT}/plug-ins
+export DIA_SHAPE_PATH=${SOURCE_ROOT}/shapes
+export DIA_XSLT_PATH=${SOURCE_ROOT}/plug-ins/xslt
+export DIA_PYTHON_PATH=${SOURCE_ROOT}/plug-ins/python
+export DIA_SHEET_PATH=${BUILD_ROOT}/sheets
+\$@
+EOF
+
+chmod u+x $1
diff --git a/meson.build b/meson.build
index 348e2e09..6b107b17 100644
--- a/meson.build
+++ b/meson.build
@@ -74,6 +74,7 @@ configure_file(output : 'config.h',
 # To fix we should remove #ifdef HAVE_CONFIG_H checks from all source files.
 add_project_arguments('-DHAVE_CONFIG_H', language : 'c')
 
+# Keep track of everything that is needed for running dia
 rundeps = []
 
 subdir('po')
@@ -87,10 +88,17 @@ subdir('sheets')
 subdir('shapes')
 subdir('tests')
 
-# Convenience target
-run_target('run',
-    command: [run_dia],
-    depends: rundeps,
+# This is a convenience target to create a way to run dia from
+# command line.
+custom_target('run_with_dia_env',
+    command: [find_program('generate_run_with_dia_env.sh'),
+              '@OUTPUT@',
+              meson.source_root(),
+              meson.build_root()
+          ],
+    output: 'run_with_dia_env',
+    # Ensure we always generate this in the build directory.
+    build_by_default: true
 )
 
 meson.add_install_script('meson-helpers/post-install.py', datadir)
diff --git a/tests/exports/meson.build b/tests/exports/meson.build
index 8dadf0ed..cbaf9d39 100644
--- a/tests/exports/meson.build
+++ b/tests/exports/meson.build
@@ -1,11 +1,9 @@
-exports_test = find_program('exports_test.sh')
-
 test('exports',
-    exports_test,
-    args: [run_dia.path()],
+    find_program('exports_test.sh'),
+    args: [
+        # TODO: this is a bug in meson.  We don't need to
+        # specify full_path() https://github.com/mesonbuild/meson/issues/2681
+        diaapp.full_path()],
     workdir: meson.current_source_dir(),
-    env: [
-        'MESON_BUILD_ROOT=' + meson.build_root(),
-        'MESON_SOURCE_ROOT=' + meson.source_root(),
-    ],
+    env: run_env,
 )
diff --git a/tests/meson.build b/tests/meson.build
index 22ce41e0..dc0553e9 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,5 +1,13 @@
-
-run_dia = find_program('run_dia.sh')
+# Setup local environment to run dia.
+run_env = environment()
+run_env.set('DIA_BASE_PATH', meson.source_root())
+run_env.append('DIA_LIB_PATH',
+    join_paths(meson.build_root(), 'objects'),
+    join_paths(meson.build_root(), 'plug-ins'))
+run_env.set('DIA_SHAPE_PATH',  join_paths(meson.source_root(), 'shapes'))
+run_env.set('DIA_XSLT_PATH',   join_paths(meson.source_root(), 'plug-ins', 'xslt'))
+run_env.set('DIA_PYTHON_PATH', join_paths(meson.source_root(), 'plug-ins', 'python'))
+run_env.set('DIA_SHEET_PATH',  join_paths(meson.build_root(), 'sheets'))
 
 # TODO: minimise code duplication.
 if host_machine.system() != 'windows'
@@ -54,14 +62,11 @@ find_program('xmllint', required: true)
 test('xmllint',
     xmllint_test,
     args: [
-        run_dia.path(),
+        diaapp,
         shape_dtd,
         render_test_dia
     ],
-    env: [
-        'MESON_BUILD_ROOT=' + meson.build_root(),
-        'MESON_SOURCE_ROOT=' + meson.source_root(),
-    ],
+    env: run_env,
 )
 
 test('testsvg', tsvg)
diff --git a/tests/xmllint_test.sh b/tests/xmllint_test.sh
index 474ce533..dcbda279 100755
--- a/tests/xmllint_test.sh
+++ b/tests/xmllint_test.sh
@@ -1,6 +1,5 @@
 #!/usr/bin/env sh
-
-RUN_DIA=$1
+DIA=$1
 SHAPE_DTD=$2
 DIAGRAM=$3
 
@@ -9,7 +8,7 @@ FAILED=0
 set -x
 
 # TODO: can we use mktemp instead of rt.shape?
-${RUN_DIA} ${DIAGRAM} --export=rt.shape || exit 1
+${DIA} ${DIAGRAM} --export=rt.shape || exit 1
 xmllint --dtdvalid ${SHAPE_DTD} rt.shape || exit 2
 rm -f rt.shape
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]