From 01c3d00a4ef49c3f7310402d8d635f69cbf9ee64 Mon Sep 17 00:00:00 2001
From: Tamar Christina <tamar@zhox.com>
Date: Mon, 15 Oct 2018 13:23:51 -0400
Subject: [PATCH] Fix plugin tests requirements

Unfortunately the implementation has confused the ability to make
dynamic libraries with dynamic way.
This constraint is only true for systems that require `-fPIC` for
shared libraries.

Since the implementation has this implicit assumption, mark the tests
as requiring dynway.

Test Plan: ./validate

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: simonpj, rwbarton, carter

Differential Revision: https://phabricator.haskell.org/D5174
---
 testsuite/config/ghc                          | 23 +++++++++++--
 testsuite/tests/plugins/all.T                 | 34 ++++++++++++++++---
 .../tests/simplCore/should_compile/all.T      |  1 +
 3 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/testsuite/config/ghc b/testsuite/config/ghc
index e974b62a96a2..b2edfd07bdba 100644
--- a/testsuite/config/ghc
+++ b/testsuite/config/ghc
@@ -185,6 +185,7 @@ def get_compiler_info():
         config.package_conf_cache_file = ''
 
     # See Note [WayFlags]
+    # See Note [PluginWay]
     if config.ghc_dynamic:
         config.ghc_th_way_flags = "-dynamic"
         config.ghci_way_flags   = "-dynamic"
@@ -200,12 +201,28 @@ def get_compiler_info():
     else:
         config.ghc_th_way_flags = "-static"
         config.ghci_way_flags   = "-static"
-        config.plugin_way_flags = "-static"
+        config.plugin_way_flags = "-dynamic"
         config.ghc_th_way       = "normal"
-        config.ghc_plugin_way   = "normal"
+        config.ghc_plugin_way   = "dyn"
+
+# Note [PluginWay]
+#
+# Unfortunately the implementation has confused the ability to make dynamic
+# libraries with dynamic way.
+#
+# This constraint is only true for systems that require -fPIC for
+# shared libraries.
+#
+# It may not be worth fixing this assumption since the only platform that doesn't
+# require -fPIC is Windows.  These plugins require libghc to be linked so in
+# doing so you would exceed the amount of allowed symbols in a single shared
+# library.  The only way these would ever work is thus with DynWay.
+#
+# Since the implementation has this implicit assumption, mark the tests as
+# always requiring DynWay.
 
 # Note [Replacing backward slashes in config.libdir]
-# 
+#
 # We *do* need to replace backslashes in config.libdir, for the following
 # reason:
 #
diff --git a/testsuite/tests/plugins/all.T b/testsuite/tests/plugins/all.T
index 339b9bab767a..cc412fa9cee9 100644
--- a/testsuite/tests/plugins/all.T
+++ b/testsuite/tests/plugins/all.T
@@ -6,23 +6,27 @@ setTestOpts(req_interp)
 # solved.  See also #15313.
 
 test('plugins01',
-     [extra_files(['simple-plugin/']), when(opsys('mingw32'), multi_cpu_race),
+     [extra_files(['simple-plugin/']), only_ways([config.ghc_plugin_way]),
+     when(opsys('mingw32'), multi_cpu_race),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins01 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory plugins01'])
 
 test('plugins02',
-     [extra_files(['simple-plugin/']), when(opsys('mingw32'), multi_cpu_race),
+     [extra_files(['simple-plugin/']), only_ways([config.ghc_plugin_way]),
+     when(opsys('mingw32'), multi_cpu_race),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins02 TOP={top}')],
      compile_fail,
      ['-package-db simple-plugin/pkg.plugins02/local.package.conf -fplugin Simple.BadlyTypedPlugin -package simple-plugin ' + config.plugin_way_flags])
 
 test('plugins03',
-     [extra_files(['simple-plugin/']), when(opsys('mingw32'), multi_cpu_race),
+     [extra_files(['simple-plugin/']), only_ways([config.ghc_plugin_way]),
+     when(opsys('mingw32'), multi_cpu_race),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins03 TOP={top}')],
      compile_fail,
      ['-package-db simple-plugin/pkg.plugins03/local.package.conf -fplugin Simple.NonExistentPlugin -package simple-plugin'])
 
 test('plugins04', [extra_files(['HomePackagePlugin.hs']),
+                   only_ways([config.ghc_plugin_way]),
                    when(opsys('mingw32'), multi_cpu_race)],
      multimod_compile_fail,
      ['plugins04', '-package ghc -fplugin HomePackagePlugin'])
@@ -35,24 +39,28 @@ test('plugins05', [extra_files(['HomePackagePlugin.hs']),
 test('plugins06',
      [extra_files(['LinkerTicklingPlugin.hs']),
       when(opsys('mingw32'), multi_cpu_race),
-      unless(have_dynamic(), skip), only_ways([config.ghc_plugin_way])],
+      unless(have_dynamic(), skip),
+      only_ways([config.ghc_plugin_way])],
      multimod_compile_and_run, ['plugins06', '-package ghc'])
 
 test('plugins07',
      [extra_files(['rule-defining-plugin/']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C rule-defining-plugin package.plugins07 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory plugins07'])
 
 test('plugins08',
      [extra_files(['simple-plugin/']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins08 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory plugins08'])
 
 test('plugins09',
      [extra_files(['simple-plugin/']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins09 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory plugins09'])
 
@@ -60,76 +68,89 @@ test('plugins10',
      [expect_broken(15216),
       extra_files(['simple-plugin/', 'QuasiQuotation.hs']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins10 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory plugins10'])
 
 test('plugins11',
      [extra_files(['simple-plugin/']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins11 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory plugins11'])
 
 test('plugins12',
      [extra_files(['simple-plugin/']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins12 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory plugins12'])
 
 test('plugins13',
      [extra_files(['simple-plugin/', 'PluginFilteredExport.hs']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins13 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory plugins13'])
 
 test('plugins14',
      [extra_files(['simple-plugin/']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins14 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory plugins14'])
 
 test('plugins15',
      [extra_files(['simple-plugin/', 'MetaRemoveHelper.hs']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins15 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory plugins15'])
 
 test('T10420',
      [extra_files(['rule-defining-plugin/']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C rule-defining-plugin package.T10420 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory T10420'])
 
 test('T10294',
      [extra_files(['annotation-plugin/']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C annotation-plugin package.T10294 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory T10294'])
 
 test('T10294a',
      [extra_files(['annotation-plugin/']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C annotation-plugin package.T10294a TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory T10294a'])
 
 test('frontend01', [extra_files(['FrontendPlugin.hs']),
+                    only_ways([config.ghc_plugin_way]),
                     when(opsys('mingw32'), multi_cpu_race),
                     unless(have_dynamic(), expect_broken(10301))], run_command,
      ['$MAKE -s --no-print-directory frontend01'])
 
 test('T11244',
      [extra_files(['rule-defining-plugin/']),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C rule-defining-plugin package.T11244 TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory T11244'])
 
 test('T12567a',
      [extra_files(['T12567b.hs', 'simple-plugin/']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.T12567a TOP={top}')],
      run_command, ['$MAKE -s --no-print-directory T12567a'])
 
 test('T14335',
      [extra_files(['simple-plugin/', 'plugins01.hs']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins01 TOP={top}')],
      compile_fail,
      ['-package-db simple-plugin/pkg.plugins01/local.package.conf -fplugin Simple.Plugin \
@@ -138,6 +159,7 @@ test('T14335',
 test('plugin-recomp-pure',
      [extra_files(['plugin-recomp/', 'plugin-recomp-test.hs']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C plugin-recomp package.plugins01 TOP={top}')
       ],
      run_command, ['$MAKE -s --no-print-directory plugin-recomp-pure'])
@@ -145,6 +167,7 @@ test('plugin-recomp-pure',
 test('plugin-recomp-impure',
      [extra_files(['plugin-recomp/', 'plugin-recomp-test.hs']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C plugin-recomp package.plugins01 TOP={top}')
       ],
      run_command, ['$MAKE -s --no-print-directory plugin-recomp-impure'])
@@ -152,18 +175,21 @@ test('plugin-recomp-impure',
 test('plugin-recomp-flags',
      [extra_files(['plugin-recomp/', 'plugin-recomp-test.hs']),
       when(opsys('mingw32'), multi_cpu_race),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C plugin-recomp package.plugins01 TOP={top}')
       ],
      run_command, ['$MAKE -s --no-print-directory plugin-recomp-flags'])
 
 test('plugin-recomp-change',
      [extra_files(['plugin-recomp/', 'plugin-recomp-test.hs']),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C plugin-recomp package.plugins01 TOP={top}')
       ],
      run_command, ['$MAKE -s --no-print-directory plugin-recomp-change'])
 
 test('plugin-recomp-change-prof',
      [extra_files(['plugin-recomp/', 'plugin-recomp-test.hs']),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C plugin-recomp package.plugins01 TOP={top}'),
       when(not config.have_profiling,skip)
       ],
diff --git a/testsuite/tests/simplCore/should_compile/all.T b/testsuite/tests/simplCore/should_compile/all.T
index 391994e3df6b..d6b9aa0cf9df 100644
--- a/testsuite/tests/simplCore/should_compile/all.T
+++ b/testsuite/tests/simplCore/should_compile/all.T
@@ -147,6 +147,7 @@ test('T7865', normal, run_command, ['$MAKE -s --no-print-directory T7865'])
 test('T7785', only_ways(['optasm']), compile, ['-ddump-rules'])
 test('T7702',
      [extra_files(['T7702plugin']),
+      only_ways([config.ghc_plugin_way]),
       pre_cmd('$MAKE -s --no-print-directory -C T7702plugin package.T7702 TOP={top}'),
       # we say 18mb peak allocated +/- 70% because other compiler flags have
       # a large effect on allocation which is hard to separate from the
-- 
GitLab