Generate .dyn_o files for .hsig files with -dynamic-too
authorMichael Smith <michael@diglumi.com>
Thu, 23 Jul 2015 09:41:16 +0000 (11:41 +0200)
committerBen Gamari <ben@smart-cactus.org>
Thu, 23 Jul 2015 09:41:48 +0000 (11:41 +0200)
With -dynamic-too, .dyn_o files were not being generated for .hsig
files.  Normally, this is handled in the pipeline; however, the branch
for .hsig files called compileEmptyStub directly instead of going
through runPipeline.  When compiling a Cabal package that included .hsig
files, this triggered a linker error later on, as it expected a .dyn_o
file to have been generated for each .hsig.

The fix is to use runPipeline for .hsig files, just as with .hs files.
Alternately, one could duplicate the logic for handling -dynamic-too in
the .hsig branch, but simply calling runPipeline ends up being much
cleaner.

Test Plan: validate

Reviewers: austin, ezyang, bgamari, thomie

Reviewed By: ezyang, thomie

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1084

GHC Trac Issues: #10660

compiler/main/DriverPipeline.hs
testsuite/tests/driver/dynamicToo/dynamicToo005/A005.hsig [new file with mode: 0644]
testsuite/tests/driver/dynamicToo/dynamicToo005/Makefile [new file with mode: 0644]
testsuite/tests/driver/dynamicToo/dynamicToo005/test.T [new file with mode: 0644]
testsuite/tests/driver/dynamicToo/dynamicToo006/A.hsig [new file with mode: 0644]
testsuite/tests/driver/dynamicToo/dynamicToo006/B.hs [new file with mode: 0644]
testsuite/tests/driver/dynamicToo/dynamicToo006/Makefile [new file with mode: 0644]
testsuite/tests/driver/dynamicToo/dynamicToo006/test.T [new file with mode: 0644]

index ff6e81d..97e64c4 100644 (file)
@@ -251,7 +251,18 @@ compileOne' m_tc_result mHscMessage
                        do (iface, changed, details) <-
                                     hscSimpleIface hsc_env tc_result mb_old_hash
                           hscWriteIface dflags iface changed summary
-                          compileEmptyStub dflags hsc_env basename location
+
+                          -- #10660: Use the pipeline instead of calling
+                          -- compileEmptyStub directly, so -dynamic-too gets
+                          -- handled properly
+                          let mod_name = ms_mod_name summary
+                          _ <- runPipeline StopLn hsc_env
+                                            (output_fn,
+                                             Just (HscOut src_flavour mod_name HscUpdateSig))
+                                            (Just basename)
+                                            Persistent
+                                            (Just location)
+                                            Nothing
 
                           -- Same as Hs
                           o_time <- getModificationUTCTime object_filename
diff --git a/testsuite/tests/driver/dynamicToo/dynamicToo005/A005.hsig b/testsuite/tests/driver/dynamicToo/dynamicToo005/A005.hsig
new file mode 100644 (file)
index 0000000..75d621c
--- /dev/null
@@ -0,0 +1,5 @@
+
+module A005 where
+
+data Maybe a = Nothing | Just a
+
diff --git a/testsuite/tests/driver/dynamicToo/dynamicToo005/Makefile b/testsuite/tests/driver/dynamicToo/dynamicToo005/Makefile
new file mode 100644 (file)
index 0000000..617510e
--- /dev/null
@@ -0,0 +1,16 @@
+TOP=../../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+checkExists = [ -f $1 ] || echo $1 missing
+
+.PHONY: dynamicToo005
+# Check that "-c -dynamic-too" works with .hsig
+dynamicToo005:
+       "$(TEST_HC)" $(TEST_HC_OPTS) -dynamic-too -v0 \
+                               -sig-of A005=base:Prelude \
+                               -c A005.hsig
+       $(call checkExists,A005.o)
+       $(call checkExists,A005.hi)
+       $(call checkExists,A005.dyn_o)
+       $(call checkExists,A005.dyn_hi)
diff --git a/testsuite/tests/driver/dynamicToo/dynamicToo005/test.T b/testsuite/tests/driver/dynamicToo/dynamicToo005/test.T
new file mode 100644 (file)
index 0000000..48460f5
--- /dev/null
@@ -0,0 +1,8 @@
+
+test('dynamicToo005',
+     [extra_clean(['A005.o', 'A005.hi', 'A005.dyn_o', 'A005.dyn_hi']),
+      unless(have_vanilla(), skip),
+      unless(have_dynamic(), skip)],
+     run_command,
+     ['$MAKE -s --no-print-directory dynamicToo005'])
+
diff --git a/testsuite/tests/driver/dynamicToo/dynamicToo006/A.hsig b/testsuite/tests/driver/dynamicToo/dynamicToo006/A.hsig
new file mode 100644 (file)
index 0000000..f79d5d3
--- /dev/null
@@ -0,0 +1,5 @@
+
+module A where
+
+data Maybe a = Nothing | Just a
+
diff --git a/testsuite/tests/driver/dynamicToo/dynamicToo006/B.hs b/testsuite/tests/driver/dynamicToo/dynamicToo006/B.hs
new file mode 100644 (file)
index 0000000..65900e7
--- /dev/null
@@ -0,0 +1,8 @@
+{-# LANGUAGE NoImplicitPrelude #-}
+
+module B where
+
+import A
+
+b :: Maybe a
+b = Nothing
diff --git a/testsuite/tests/driver/dynamicToo/dynamicToo006/Makefile b/testsuite/tests/driver/dynamicToo/dynamicToo006/Makefile
new file mode 100644 (file)
index 0000000..497f2c0
--- /dev/null
@@ -0,0 +1,20 @@
+TOP=../../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+checkExists = [ -f $1 ] || echo $1 missing
+
+.PHONY: dynamicToo006
+# Check that "--make -dynamic-too" works with .hsig
+dynamicToo006:
+       "$(TEST_HC)" $(TEST_HC_OPTS) -dynamic-too -v0 \
+                               -sig-of A=base:Prelude \
+                               --make B
+       $(call checkExists,A.o)
+       $(call checkExists,B.o)
+       $(call checkExists,A.hi)
+       $(call checkExists,B.hi)
+       $(call checkExists,A.dyn_o)
+       $(call checkExists,B.dyn_o)
+       $(call checkExists,A.dyn_hi)
+       $(call checkExists,B.dyn_hi)
diff --git a/testsuite/tests/driver/dynamicToo/dynamicToo006/test.T b/testsuite/tests/driver/dynamicToo/dynamicToo006/test.T
new file mode 100644 (file)
index 0000000..72e06ca
--- /dev/null
@@ -0,0 +1,9 @@
+
+test('dynamicToo006',
+     [extra_clean(['A.o', 'A.hi', 'A.dyn_o', 'A.dyn_hi',
+                   'B.o', 'B.hi', 'B.dyn_o', 'B.dyn_hi']),
+      unless(have_vanilla(), skip),
+      unless(have_dynamic(), skip)],
+     run_command,
+     ['$MAKE -s --no-print-directory dynamicToo006'])
+