From: Jeremy Bicha <jeremy.bicha@canonical.com>
Date: Thu, 12 Jan 2023 08:47:54 -0500
Subject: Revert "build: Drop the install-tests option"

Debian and Ubuntu uses these installed tests as part of their
autopkgtest system

This reverts commit 3121f88265ac61733e257f5335473d6f139f158c.
---
 meson.build                      |  1 +
 meson.options                    |  5 +++
 testsuite/a11y/meson.build       |  5 +++
 testsuite/css/change/meson.build | 25 +++++++++++++++
 testsuite/css/meson.build        | 32 ++++++++++++++++++-
 testsuite/css/nodes/meson.build  | 69 ++++++++++++++++++++++++++++++++++++++++
 testsuite/css/parser/meson.build | 17 ++++++++++
 testsuite/css/style/meson.build  | 50 +++++++++++++++++++++++++++++
 testsuite/gdk/meson.build        | 37 +++++++++++++++++++--
 testsuite/gsk/meson.build        | 21 +++++++++---
 testsuite/gtk/meson.build        | 45 ++++++++++++++++++++++++++
 11 files changed, 298 insertions(+), 9 deletions(-)

diff --git a/meson.build b/meson.build
index 09c1851..07a7036 100644
--- a/meson.build
+++ b/meson.build
@@ -1084,6 +1084,7 @@ summary('Documentation', get_option('documentation'), section: 'Build')
 summary('Man pages', get_option('man-pages'), section: 'Build')
 summary('Testsuite', get_option('build-testsuite'), section: 'Build')
 summary('Tests', get_option('build-tests'), section: 'Build')
+summary('Install tests', get_option('install-tests'), section: 'Build')
 summary('Demos', get_option('build-demos'), section: 'Build')
 summary('Examples', get_option('build-examples'), section: 'Build')
 
diff --git a/meson.options b/meson.options
index 0c0412d..5534f3d 100644
--- a/meson.options
+++ b/meson.options
@@ -149,3 +149,8 @@ option('build-tests',
        type: 'boolean',
        value: true,
        description : 'Build tests')
+
+option('install-tests',
+       type: 'boolean',
+       value: false,
+       description : 'Install tests')
diff --git a/testsuite/a11y/meson.build b/testsuite/a11y/meson.build
index 4fe5030..b45a57e 100644
--- a/testsuite/a11y/meson.build
+++ b/testsuite/a11y/meson.build
@@ -1,3 +1,6 @@
+testexecdir = join_paths(installed_test_bindir, 'gtk')
+testdatadir = join_paths(installed_test_datadir, 'gtk')
+
 # Available keys for each test:
 #
 #  - 'name': the test name; used for the test and to determine the base
@@ -74,6 +77,8 @@ foreach t : tests
     c_args: test_cargs + test_extra_cargs,
     link_args: test_extra_ldflags,
     dependencies: libgtk_dep,
+    install: get_option('install-tests'),
+    install_dir: testexecdir,
   )
 
   if test_extra_suites.contains('slow')
diff --git a/testsuite/css/change/meson.build b/testsuite/css/change/meson.build
index f78d27e..6994e9e 100644
--- a/testsuite/css/change/meson.build
+++ b/testsuite/css/change/meson.build
@@ -6,10 +6,15 @@ changetest_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
 changetest_env.set('GSETTINGS_BACKEND', 'memory')
 changetest_env.set('G_ENABLE_DIAGNOSTIC', '0')
 
+testexecdir = join_paths(installed_test_bindir, 'css', 'change')
+testdatadir = join_paths(installed_test_datadir, 'css')
+
 test_change = executable('test-css-change',
   sources: ['test-css-change.c', '../../testutils.c'],
   c_args: common_cflags,
   dependencies: libgtk_dep,
+  install: get_option('install-tests'),
+  install_dir: testexecdir,
 )
 
 test('change', test_change,
@@ -18,3 +23,23 @@ test('change', test_change,
   env: changetest_env,
   suite: 'css',
 )
+
+test_data = [
+  'test1.css', 'test1.ui', 'test1.nodes',
+  'test2.css', 'test2.ui', 'test2.nodes',
+  'test3.css', 'test3.ui', 'test3.nodes',
+  'test4.css', 'test4.ui', 'test4.nodes',
+  'test5.css', 'test5.ui', 'test5.nodes',
+]
+
+if get_option('install-tests')
+  conf = configuration_data()
+  conf.set('libexecdir', gtk_libexecdir)
+  configure_file(input: 'change.test.in',
+                 output: 'change.test',
+                 configuration: conf,
+                 install_dir: testdatadir)
+
+  install_data(test_data, install_dir: testexecdir)
+
+endif
diff --git a/testsuite/css/meson.build b/testsuite/css/meson.build
index 74494ff..138c47f 100644
--- a/testsuite/css/meson.build
+++ b/testsuite/css/meson.build
@@ -9,10 +9,15 @@ subdir('nodes')
 subdir('style')
 subdir('change')
 
+testexecdir = join_paths(installed_test_bindir, 'css')
+testdatadir = join_paths(installed_test_datadir, 'css')
+
 test_api = executable('api',
   sources: ['api.c'],
   c_args: common_cflags,
   dependencies: libgtk_dep,
+  install: get_option('install-tests'),
+  install_dir: testexecdir,
 )
 
 test('api', test_api,
@@ -27,6 +32,8 @@ test_data = executable('data',
   c_args: common_cflags + ['-DGTK_COMPILATION'],
   include_directories: [confinc, ],
   dependencies: libgtk_static_dep,
+  install: get_option('install-tests'),
+  install_dir: testexecdir,
 )
 
 test('data', test_data,
@@ -40,6 +47,8 @@ transition = executable('transition',
   sources: ['transition.c'],
   c_args: common_cflags + ['-DGTK_COMPILATION'],
   dependencies: libgtk_static_dep,
+  install: get_option('install-tests'),
+  install_dir: testexecdir,
 )
 
 test('transition', transition,
@@ -53,6 +62,8 @@ color = executable('color',
   sources: ['color.c'],
   c_args: common_cflags + ['-DGTK_COMPILATION'],
   dependencies: libgtk_static_dep,
+  install: get_option('install-tests'),
+  install_dir: testexecdir,
 )
 
 test('color', color,
@@ -65,7 +76,9 @@ test('color', color,
 compute = executable('compute',
   sources: ['compute.c'],
   c_args: common_cflags + ['-DGTK_COMPILATION'],
-  dependencies: libgtk_static_dep
+  dependencies: libgtk_static_dep,
+  install: get_option('install-tests'),
+  install_dir: testexecdir,
 )
 
 test('compute', compute,
@@ -74,3 +87,20 @@ test('compute', compute,
   env: csstest_env,
   suite: 'css'
 )
+if get_option('install-tests')
+  conf = configuration_data()
+  conf.set('libexecdir', gtk_libexecdir)
+  configure_file(input: 'api.test.in',
+    output: 'api.test',
+    configuration: conf,
+    install_dir: testdatadir,
+  )
+
+  conf = configuration_data()
+  conf.set('libexecdir', gtk_libexecdir)
+  configure_file(input: 'data.test.in',
+    output: 'data.test',
+    configuration: conf,
+    install_dir: testdatadir,
+  )
+endif
diff --git a/testsuite/css/nodes/meson.build b/testsuite/css/nodes/meson.build
index f682cdb..b737386 100644
--- a/testsuite/css/nodes/meson.build
+++ b/testsuite/css/nodes/meson.build
@@ -6,10 +6,15 @@ nodetest_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
 nodetest_env.set('GSETTINGS_BACKEND', 'memory')
 nodetest_env.set('G_ENABLE_DIAGNOSTIC', '0')
 
+testexecdir = join_paths(installed_test_bindir, 'css', 'nodes')
+testdatadir = join_paths(installed_test_datadir, 'css')
+
 test_nodes = executable('test-css-nodes',
   sources: ['test-css-nodes.c', '../../testutils.c'],
   c_args: common_cflags,
   dependencies: libgtk_dep,
+  install: get_option('install-tests'),
+  install_dir: testexecdir,
 )
 
 test('nodes', test_nodes,
@@ -18,3 +23,67 @@ test('nodes', test_nodes,
   env: nodetest_env,
   suite: 'css',
 )
+
+test_data = [
+  'box.ltr.nodes',
+  'box.ltr.ui',
+  'box.rtl.nodes',
+  'box.rtl.ui',
+  'buttons.nodes',
+  'buttons.ui',
+  'checkbutton.ltr.nodes',
+  'checkbutton.ltr.ui',
+  'checkbutton.rtl.nodes',
+  'checkbutton.rtl.ui',
+  'combobox.nodes',
+  'combobox.ui',
+  'entries.nodes',
+  'entries.ui',
+  'expander.ltr.nodes',
+  'expander.ltr.ui',
+  'expander.rtl.nodes',
+  'expander.rtl.ui',
+  'levelbar.ltr.nodes',
+  'levelbar.ltr.ui',
+  'levelbar.rtl.nodes',
+  'levelbar.rtl.ui',
+  'notebook-arrows2.nodes',
+  'notebook-arrows2.ui',
+  'notebook-arrows.nodes',
+  'notebook-arrows.ui',
+  'notebook.bottom.ltr.nodes',
+  'notebook.bottom.ltr.ui',
+  'notebook.bottom.rtl.nodes',
+  'notebook.bottom.rtl.ui',
+  'notebook.left.ltr.nodes',
+  'notebook.left.ltr.ui',
+  'notebook.left.rtl.nodes',
+  'notebook.left.rtl.ui',
+  'notebook.right.ltr.nodes',
+  'notebook.right.ltr.ui',
+  'notebook.right.rtl.nodes',
+  'notebook.right.rtl.ui',
+  'notebook.top.ltr.nodes',
+  'notebook.top.ltr.ui',
+  'notebook.top.rtl.nodes',
+  'notebook.top.rtl.ui',
+  'paned.ltr.nodes',
+  'paned.ltr.ui',
+  'paned.rtl.nodes',
+  'paned.rtl.ui',
+  'progressbar.nodes',
+  'progressbar.ui',
+  'scale.nodes',
+  'scale.ui',
+]
+
+if get_option('install-tests')
+  conf = configuration_data()
+  conf.set('libexecdir', gtk_libexecdir)
+  configure_file(input: 'nodes.test.in',
+                 output: 'nodes.test',
+                 configuration: conf,
+                 install_dir: testdatadir)
+
+  install_data(test_data, install_dir: testexecdir)
+endif
diff --git a/testsuite/css/parser/meson.build b/testsuite/css/parser/meson.build
index b41200c..5fc6d7f 100644
--- a/testsuite/css/parser/meson.build
+++ b/testsuite/css/parser/meson.build
@@ -1,7 +1,12 @@
+testexecdir = join_paths(installed_test_bindir, 'css', 'parser')
+testdatadir = join_paths(installed_test_datadir, 'css')
+
 test_parser = executable('test-css-parser',
   sources: ['test-css-parser.c', '../../testutils.c'],
   c_args: common_cflags,
   dependencies: libgtk_dep,
+  install: get_option('install-tests'),
+  install_dir: testexecdir,
 )
 
 test_data = [
@@ -672,3 +677,15 @@ foreach testname : test_data
          suite: 'css')
   endif
 endforeach
+
+if get_option('install-tests')
+  conf = configuration_data()
+  conf.set('libexecdir', gtk_libexecdir)
+  configure_file(input: 'parser.test.in',
+                 output: 'parser.test',
+                 configuration: conf,
+                 install_dir: testdatadir)
+
+  install_data(test_data, install_dir: testexecdir)
+
+endif
diff --git a/testsuite/css/style/meson.build b/testsuite/css/style/meson.build
index 04f8822..4d48ba4 100644
--- a/testsuite/css/style/meson.build
+++ b/testsuite/css/style/meson.build
@@ -7,6 +7,9 @@ styletest_env.set('GSETTINGS_BACKEND', 'memory')
 styletest_env.set('G_ENABLE_DIAGNOSTIC', '0')
 styletest_env.set('GTK_DEBUG', '')
 
+testexecdir = join_paths(installed_test_bindir, 'css', 'style')
+testdatadir = join_paths(installed_test_datadir, 'css')
+
 cssresources = gnome.compile_resources(
   'cssresources',
   'test-css-style.gresource.xml',
@@ -17,6 +20,8 @@ test_style = executable('test-css-style',
   sources: ['test-css-style.c', '../../testutils.c', cssresources],
   c_args: common_cflags,
   dependencies: libgtk_dep,
+  install: get_option('install-tests'),
+  install_dir: testexecdir,
 )
 
 test('style', test_style,
@@ -25,3 +30,48 @@ test('style', test_style,
   env: styletest_env,
   suite: 'css',
 )
+
+test_data = [
+  'adjacent-states.css',
+  'adjacent-states.nodes',
+  'adjacent-states.ui',
+  'bloomfilter-not.css',
+  'bloomfilter-not.nodes',
+  'bloomfilter-not.ui',
+  'colornames.css',
+  'colornames.nodes',
+  'colornames.ui',
+  'currentcolor.css',
+  'currentcolor.nodes',
+  'currentcolor.ui',
+  'font.css',
+  'font.nodes',
+  'font.ui',
+  'gradient.css',
+  'gradient.nodes',
+  'gradient.ui',
+  'gtk.css',
+  'inherit.css',
+  'inherit.nodes',
+  'inherit.ui',
+  'label.css',
+  'label.nodes',
+  'label.ui',
+  'misc.css',
+  'misc.nodes',
+  'misc.ui',
+  'nth-child.css',
+  'nth-child.nodes',
+  'nth-child.ui',
+]
+
+if get_option('install-tests')
+  conf = configuration_data()
+  conf.set('libexecdir', gtk_libexecdir)
+  configure_file(input: 'style.test.in',
+                 output: 'style.test',
+                 configuration: conf,
+                 install_dir: testdatadir)
+
+  install_data(test_data, install_dir: testexecdir)
+endif
diff --git a/testsuite/gdk/meson.build b/testsuite/gdk/meson.build
index 64a2ecd..1a2a1fd 100644
--- a/testsuite/gdk/meson.build
+++ b/testsuite/gdk/meson.build
@@ -1,9 +1,13 @@
+testexecdir = join_paths(installed_test_bindir, 'gdk')
+testdatadir = join_paths(installed_test_datadir, 'gdk')
+
 clipboard_client = executable('clipboard-client',
   sources: ['clipboard-client.c'],
   include_directories: [confinc],
   c_args: common_cflags,
   dependencies: [ libgtk_dep ],
-  install: false,
+  install: get_option('install-tests'),
+  install_dir: testexecdir
 )
 
 tests = [
@@ -55,7 +59,8 @@ foreach t : tests
     sources: [ '@0@.c'.format(test_name) ] + t.get('sources', []),
     c_args: common_cflags,
     dependencies: libgtk_dep,
-    install: false,
+    install: get_option('install-tests'),
+    install_dir: testexecdir,
   )
 
   suites = ['gdk'] + t.get('suites', [])
@@ -97,7 +102,8 @@ foreach t : internal_tests
     sources: [ '@0@.c'.format(test_name) ] + t.get('sources', []),
     c_args: common_cflags + ['-DGTK_COMPILATION'],
     dependencies: libgtk_static_dep,
-    install: false,
+    install: get_option('install-tests'),
+    install_dir: testexecdir,
   )
 
   suites = ['gdk'] + t.get('suites', [])
@@ -113,3 +119,28 @@ foreach t : internal_tests
     suite: suites,
   )
 endforeach
+
+
+if get_option('install-tests')
+  foreach t : tests
+    test_name = t.get('name')
+    suites = t.get('suites', [])
+
+    if suites.contains('flaky') or suites.contains('failing')
+      continue
+    endif
+
+    test_cdata = configuration_data()
+    test_cdata.set('testexecdir', testexecdir)
+    test_cdata.set('test', test_name)
+    configure_file(input: 'gdk.test.in',
+      output: '@0@.test'.format(test_name),
+      configuration: test_cdata,
+      install: true,
+      install_dir: testdatadir,
+    )
+  endforeach
+
+  install_subdir('clipboard-data', install_dir: testexecdir)
+  install_subdir('image-data', install_dir: testexecdir)
+endif
diff --git a/testsuite/gsk/meson.build b/testsuite/gsk/meson.build
index 0eb0db8..c049a94 100644
--- a/testsuite/gsk/meson.build
+++ b/testsuite/gsk/meson.build
@@ -1,13 +1,20 @@
+testexecdir = join_paths(installed_test_bindir, 'gsk')
+testdatadir = join_paths(installed_test_datadir, 'gsk')
+
 compare_render = executable('compare-render',
   ['compare-render.c', '../reftests/reftest-compare.c', 'replay-node.c', '../gdk/udmabuf.c'],
   dependencies: libgtk_static_dep,
   c_args: common_cflags + ['-DGTK_COMPILATION'],
+  install: get_option('install-tests'),
+  install_dir: testexecdir
 )
 
 node_parser = executable('node-parser', 
   [ 'node-parser.c', '../testutils.c' ],
   dependencies: libgtk_dep,
   c_args: common_cflags,
+  install: get_option('install-tests'),
+  install_dir: testexecdir
 )
 
 compare_render_tests = [
@@ -632,9 +639,12 @@ foreach t : tests
   test_srcs = ['@0@.c'.format(test_name)] + t.get(1, [])
   test_extra_suites = t.get(2, [])
 
-  test_exe = executable(test_name, test_srcs,
-    dependencies : libgtk_dep,
+  test_exe = executable(test_name,
+    sources: test_srcs,
+    dependencies : libgtk_static_dep,
     c_args : test_cargs + common_cflags,
+    install: get_option('install-tests'),
+    install_dir: testexecdir,
   )
 
   test(test_name, test_exe,
@@ -669,10 +679,11 @@ foreach t : internal_tests
   test_srcs = ['@0@.c'.format(test_name)] + t.get(1, [])
   test_extra_suites = t.get(2, [])
 
-  test_exe = executable(test_name,
-    sources: test_srcs,
-    dependencies : libgtk_static_dep,
+  test_exe = executable(test_name, test_srcs,
     c_args : test_cargs + common_cflags + ['-DGTK_COMPILATION'],
+    dependencies : libgtk_static_dep,
+    install: get_option('install-tests'),
+    install_dir: testexecdir,
   )
 
   test(test_name, test_exe,
diff --git a/testsuite/gtk/meson.build b/testsuite/gtk/meson.build
index 9f9ebc7..5dd1ddf 100644
--- a/testsuite/gtk/meson.build
+++ b/testsuite/gtk/meson.build
@@ -1,3 +1,6 @@
+testexecdir = join_paths(installed_test_bindir, 'gtk')
+testdatadir = join_paths(installed_test_datadir, 'gtk')
+
 gtk_tests_export_dynamic_ldflag = []
 
 if cc.get_id() != 'msvc'
@@ -186,6 +189,8 @@ foreach t : tests
     c_args: test_cargs + test_extra_cargs,
     link_args: test_extra_ldflags,
     dependencies: libgtk_dep,
+    install: get_option('install-tests'),
+    install_dir: testexecdir,
   )
 
   if test_extra_suites.contains('slow')
@@ -214,6 +219,8 @@ foreach t : internal_tests
     c_args: test_cargs + test_extra_cargs + ['-DGTK_COMPILATION'],
     link_args: test_extra_ldflags,
     dependencies: libgtk_static_dep,
+    install: get_option('install-tests'),
+    install_dir: testexecdir,
   )
 
   if test_extra_suites.contains('slow')
@@ -234,6 +241,8 @@ if add_languages('cpp', required: false, native: false)
   test_exe = executable('autotestkeywords',
     sources: ['autotestkeywords.cc'],
     dependencies: libgtk_dep,
+    install: get_option('install-tests'),
+    install_dir: testexecdir,
   )
   test('c++ keywords', test_exe,
     args: [ '--tap', '-k' ],
@@ -241,6 +250,16 @@ if add_languages('cpp', required: false, native: false)
     env: test_env,
     suite: 'gtk',
   )
+  if get_option('install-tests')
+    conf = configuration_data()
+    conf.set('testexecdir', testexecdir)
+    conf.set('test', 'autotestkeywords')
+    configure_file(input: 'gtk.test.in',
+      output: 'autotestkeywords.test',
+      configuration: conf,
+      install_dir: testdatadir,
+    )
+  endif
 endif
 
 
@@ -270,6 +289,8 @@ focus_chain = executable('test-focus-chain',
   sources: ['test-focus-chain.c', '../testutils.c'],
   dependencies: libgtk_dep,
   c_args: common_cflags,
+  install: get_option('install-tests'),
+  install_dir: testexecdir
 )
 
 foreach test : focus_chain_tests
@@ -300,3 +321,27 @@ if host_machine.system() in ['linux']
        workdir: meson.project_source_root(),
        suite: ['gtk', 'gtk'])
 endif
+
+if get_option('install-tests')
+  foreach t : tests
+    test_name = t.get('name')
+    suites = t.get('suites', [])
+
+    if suites.contains('flaky') or suites.contains('failing')
+      continue
+    endif
+
+    conf = configuration_data()
+    conf.set('testexecdir', testexecdir)
+    conf.set('test', test_name)
+    configure_file(input: 'gtk.test.in',
+      output: '@0@.test'.format(test_name),
+      configuration: conf,
+      install_dir: testdatadir,
+    )
+  endforeach
+
+  install_subdir('icons', install_dir: testexecdir)
+  install_subdir('icons2', install_dir: testexecdir)
+  install_subdir('ui', install_dir: testexecdir)
+endif
