From 5c0ff95778f543526180bad251ee4089c734aa16 Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Thu, 9 Nov 2017 14:53:01 +0800 Subject: [PATCH] Do not apply global options within conditionals (fixes #214) --- src/Hpack/Config.hs | 9 ++++----- test/EndToEndSpec.hs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Hpack/Config.hs b/src/Hpack/Config.hs index 5ccf0ea..0edb9c0 100644 --- a/src/Hpack/Config.hs +++ b/src/Hpack/Config.hs @@ -796,10 +796,12 @@ toExecutables :: FilePath -> String -> Section global -> [(String, Section Execu toExecutables dir packageName_ globalOptions = traverseNamedSections (toExecutable dir packageName_ globalOptions) toExecutable :: FilePath -> String -> Section global -> Section ExecutableSection -> IO ([String], Section Executable) -toExecutable dir packageName_ globalOptions = toExecutable_ >=> expandForeignSources dir . nubOtherModules +toExecutable dir packageName_ globalOptions = + toExecutable_ . mergeSections emptyExecutableSection globalOptions + >=> expandForeignSources dir . nubOtherModules where toExecutable_ :: Section ExecutableSection -> IO (Section Executable) - toExecutable_ sect_ = do + toExecutable_ sect@Section{..} = do (executable, ghcOptions) <- fromExecutableSection sectionData conditionals <- mapM (traverse toExecutable_) sectionConditionals return sect { @@ -808,9 +810,6 @@ toExecutable dir packageName_ globalOptions = toExecutable_ >=> expandForeignSou , sectionConditionals = conditionals } where - sect :: Section ExecutableSection - sect@Section{..} = mergeSections emptyExecutableSection globalOptions sect_ - fromExecutableSection :: ExecutableSection -> IO (Executable, [GhcOption]) fromExecutableSection ExecutableSection{..} = do modules <- maybe inferModules (return . fromList) executableSectionOtherModules diff --git a/test/EndToEndSpec.hs b/test/EndToEndSpec.hs index b7f5016..81173aa 100644 --- a/test/EndToEndSpec.hs +++ b/test/EndToEndSpec.hs @@ -132,6 +132,21 @@ spec = around_ (inTempDirectoryNamed "foo") $ do |] context "within conditional" $ do + it "does not apply global options" $ do + -- related bug: https://github.com/sol/hpack/issues/214 + [i| + ghc-options: -Wall + executables: + foo: + when: + condition: os(windows) + main: Foo.hs + |] `shouldRenderTo` executable "foo" [i| + ghc-options: -Wall + if os(windows) + main-is: Foo.hs + |] + it "accepts executable-specific fields" $ do [i| executables: