From f65d32ebcc380c4bc02e968317958021fdff812b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=A4llberg?= Date: Mon, 22 Feb 2021 13:56:04 +0800 Subject: [PATCH 1/3] Add option for custom preprocessors --- src/Stack/Config.hs | 1 + src/Stack/Options/ConfigParser.hs | 9 ++++++++- src/Stack/Types/Config.hs | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Stack/Config.hs b/src/Stack/Config.hs index cf41dbad9a..b18287c8ca 100644 --- a/src/Stack/Config.hs +++ b/src/Stack/Config.hs @@ -230,6 +230,7 @@ configFromConfigMonoid configExtraIncludeDirs = configMonoidExtraIncludeDirs configExtraLibDirs = configMonoidExtraLibDirs + configCustomPreprocessorExts = configMonoidCustomPreprocessorExts configOverrideGccPath = getFirst configMonoidOverrideGccPath -- Only place in the codebase where platform is hard-coded. In theory diff --git a/src/Stack/Options/ConfigParser.hs b/src/Stack/Options/ConfigParser.hs index 4a4f0094c9..3366d472d6 100644 --- a/src/Stack/Options/ConfigParser.hs +++ b/src/Stack/Options/ConfigParser.hs @@ -20,7 +20,7 @@ import qualified System.FilePath as FilePath configOptsParser :: FilePath -> GlobalOptsContext -> Parser ConfigMonoid configOptsParser currentDir hide0 = (\stackRoot workDir buildOpts dockerOpts nixOpts systemGHC installGHC arch - ghcVariant ghcBuild jobs includes libs overrideGccPath overrideHpack + ghcVariant ghcBuild jobs includes libs preprocs overrideGccPath overrideHpack skipGHCCheck skipMsys localBin setupInfoLocations modifyCodePage allowDifferentUser dumpLogs colorWhen snapLoc -> mempty { configMonoidStackRoot = stackRoot @@ -37,6 +37,7 @@ configOptsParser currentDir hide0 = , configMonoidJobs = jobs , configMonoidExtraIncludeDirs = includes , configMonoidExtraLibDirs = libs + , configMonoidCustomPreprocessorExts = preprocs , configMonoidOverrideGccPath = overrideGccPath , configMonoidOverrideHpack = overrideHpack , configMonoidSkipMsys = skipMsys @@ -103,6 +104,12 @@ configOptsParser currentDir hide0 = <> help "Extra directories to check for libraries" <> hide )) + <*> many (strOption + ( long "custom-preprocessor-extensions" + <> metavar "EXT" + <> help "Extensions used for custom preprocessors" + <> hide + )) <*> optionalFirst (absFileOption ( long "with-gcc" <> metavar "PATH-TO-GCC" diff --git a/src/Stack/Types/Config.hs b/src/Stack/Types/Config.hs index 23bb0b0cae..f0d791ba5e 100644 --- a/src/Stack/Types/Config.hs +++ b/src/Stack/Types/Config.hs @@ -320,6 +320,8 @@ data Config = -- ^ --extra-include-dirs arguments ,configExtraLibDirs :: ![FilePath] -- ^ --extra-lib-dirs arguments + ,configCustomPreprocessorExts :: ![Text] + -- ^ List of custom preprocessors to complete the hard coded ones ,configConcurrentTests :: !Bool -- ^ Run test suites concurrently ,configTemplateParams :: !(Map Text Text) @@ -798,6 +800,8 @@ data ConfigMonoid = -- ^ See: 'configExtraIncludeDirs' ,configMonoidExtraLibDirs :: ![FilePath] -- ^ See: 'configExtraLibDirs' + ,configMonoidCustomPreprocessorExts :: ![Text] + -- ^ See: 'configCustomPreprocessorExts' , configMonoidOverrideGccPath :: !(First (Path Abs File)) -- ^ Allow users to override the path to gcc ,configMonoidOverrideHpack :: !(First FilePath) @@ -915,6 +919,7 @@ parseConfigMonoidObject rootDir obj = do obj ..:? configMonoidExtraIncludeDirsName ..!= [] configMonoidExtraLibDirs <- map (toFilePath rootDir FilePath.) <$> obj ..:? configMonoidExtraLibDirsName ..!= [] + configMonoidCustomPreprocessorExts <- obj ..:? configMonoidCustomPreprocessorExtsName ..!= [] configMonoidOverrideGccPath <- First <$> obj ..:? configMonoidOverrideGccPathName configMonoidOverrideHpack <- First <$> obj ..:? configMonoidOverrideHpackName configMonoidConcurrentTests <- First <$> obj ..:? configMonoidConcurrentTestsName @@ -1048,6 +1053,9 @@ configMonoidExtraIncludeDirsName = "extra-include-dirs" configMonoidExtraLibDirsName :: Text configMonoidExtraLibDirsName = "extra-lib-dirs" +configMonoidCustomPreprocessorExtsName :: Text +configMonoidCustomPreprocessorExtsName = "custom-preprocessor-extensions" + configMonoidOverrideGccPathName :: Text configMonoidOverrideGccPathName = "with-gcc" From e70570007c75357cfa07e9f05e9a7351a054a112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=A4llberg?= Date: Mon, 22 Feb 2021 14:27:25 +0800 Subject: [PATCH 2/3] Use the option for custom preprocessors --- src/Stack/Constants.hs | 6 +++--- src/Stack/Package.hs | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Stack/Constants.hs b/src/Stack/Constants.hs index 13fe9d40ce..ba979bc39f 100644 --- a/src/Stack/Constants.hs +++ b/src/Stack/Constants.hs @@ -9,7 +9,7 @@ module Stack.Constants (buildPlanDir ,buildPlanCacheDir ,haskellFileExts - ,haskellPreprocessorExts + ,haskellDefaultPreprocessorExts ,stackDotYaml ,stackWorkEnvVar ,stackRootEnvVar @@ -142,8 +142,8 @@ haskellFileExts :: [Text] haskellFileExts = ["hs", "hsc", "lhs"] -- | Extensions for modules that are preprocessed by common preprocessors. -haskellPreprocessorExts :: [Text] -haskellPreprocessorExts = ["gc", "chs", "hsc", "x", "y", "ly", "cpphs"] +haskellDefaultPreprocessorExts :: [Text] +haskellDefaultPreprocessorExts = ["gc", "chs", "hsc", "x", "y", "ly", "cpphs"] -- | Name of the 'stack' program, uppercased stackProgNameUpper :: String diff --git a/src/Stack/Package.hs b/src/Stack/Package.hs index 9d01f72f4a..e9482b6428 100644 --- a/src/Stack/Package.hs +++ b/src/Stack/Package.hs @@ -1173,7 +1173,9 @@ findCandidate -> RIO Ctx (Maybe DotCabalPath) findCandidate dirs name = do pkg <- asks ctxFile >>= parsePackageNameFromFilePath - candidates <- liftIO makeNameCandidates + customPreprocessorExts <- view $ configL . to configCustomPreprocessorExts + let haskellPreprocessorExts = haskellDefaultPreprocessorExts ++ customPreprocessorExts + candidates <- liftIO $ makeNameCandidates haskellPreprocessorExts case candidates of [candidate] -> return (Just (cons candidate)) [] -> do @@ -1193,11 +1195,12 @@ findCandidate dirs name = do DotCabalFile{} -> DotCabalFilePath DotCabalCFile{} -> DotCabalCFilePath paths_pkg pkg = "Paths_" ++ packageNameString pkg - makeNameCandidates = - liftM (nubOrd . concat) (mapM makeDirCandidates dirs) - makeDirCandidates :: Path Abs Dir + makeNameCandidates haskellPreprocessorExts = + liftM (nubOrd . concat) (mapM (makeDirCandidates haskellPreprocessorExts) dirs) + makeDirCandidates :: [Text] + -> Path Abs Dir -> IO [Path Abs File] - makeDirCandidates dir = + makeDirCandidates haskellPreprocessorExts dir = case name of DotCabalMain fp -> resolveCandidate dir fp DotCabalFile fp -> resolveCandidate dir fp From 56f33cc1ab65351c60889279c55e62dfad4fdcaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=A4llberg?= Date: Tue, 23 Feb 2021 14:49:36 +0800 Subject: [PATCH 3/3] Document the custom preprocessor extensions option --- ChangeLog.md | 4 ++++ doc/faq.md | 26 +++++++++++++++++++------- doc/yaml_configuration.md | 11 +++++++++++ src/Stack/Package.hs | 4 ++-- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index c9f0e5876f..293384e8cb 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -26,6 +26,10 @@ Other enhancements: * `stack list` is a new command to list package versions in a snapshot. See [#5431](https://github.com/commercialhaskell/stack/pull/5431) +* `custom-preprocessor-extensions` is a new configuration option for allowing + stack to be aware of any custom preprocessors you have added to `Setup.hs`. + See [#3491](https://github.com/commercialhaskell/stack/issues/3491) + Bug fixes: * `stack new` now suppports branches other than `master` as default for diff --git a/doc/faq.md b/doc/faq.md index 6af66ce64a..1ac2b73bfd 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -74,9 +74,9 @@ extra-deps: ## I need to use a package (or version of a package) that is not available on hackage, what should I do? -Add it to the -[`extra-deps`](yaml_configuration.md#extra-deps) list in your project's -`stack.yaml`, specifying the package's source code location relative to the +Add it to the +[`extra-deps`](yaml_configuration.md#extra-deps) list in your project's +`stack.yaml`, specifying the package's source code location relative to the directory where your `stack.yaml` file lives, e.g. ```yaml @@ -89,9 +89,9 @@ extra-deps: - patched/diagrams ``` -The above example specifies that the `proprietary-dep` package is found in the -project's `third-party` folder, that the `conduit` package is found in the -project's `github-version-of` folder, and that the `diagrams` package is found +The above example specifies that the `proprietary-dep` package is found in the +project's `third-party` folder, that the `conduit` package is found in the +project's `github-version-of` folder, and that the `diagrams` package is found in the project's `patched` folder. This autodetects changes and reinstalls the package. @@ -171,10 +171,22 @@ test<%= i %> = <%= i %> ``` To ensure that Stack picks up changes to this file for rebuilds, add +the following lines to your stack.yaml file: + +```yaml + custom-preprocessor-extensions: + - erb + + require-stack-version: ">= 2.6.0" +``` + +And for backwards compatability with older versions of stack, also add the following line to your .cabal file: extra-source-files: B.erb +You could also use the [`--custom-preprocessor-extensions` flag](yaml_configuration.md#custom-preprocessor-extensions) + ## I already have GHC installed, can I still use stack? Yes. In its default configuration, stack will simply ignore any system GHC @@ -578,7 +590,7 @@ This probably means a GHC bindist has not yet been added for OS key 'linux64-ncu Supported versions: ghc-7.10.3, ghc-8.0.1, ghc-8.0.2, ghc-8.2.1, ghc-8.2.2 ``` -Most Linux distributions have standardized on providing libtinfo.so.6 (either directly or as a symlink to libncursesw.so.6). As such, there aren't GHC 8.6.* bindists that link to libncursesw.so.6 available. +Most Linux distributions have standardized on providing libtinfo.so.6 (either directly or as a symlink to libncursesw.so.6). As such, there aren't GHC 8.6.* bindists that link to libncursesw.so.6 available. So creating a symlink to libncursesw.so.6 as libtinfo.so.6 can prevent this error (root privileges might be required). ``` diff --git a/doc/yaml_configuration.md b/doc/yaml_configuration.md index 067b6f48a5..d527054c57 100644 --- a/doc/yaml_configuration.md +++ b/doc/yaml_configuration.md @@ -274,6 +274,17 @@ as a reminder for the user to review the configuration and make any changes if needed. The user can delete this message if the generated configuration is acceptable. +### custom-preprocessor-extensions + +In order for stack to be aware of any custom preprocessors you are using, add their extensions here + +```yaml +custom-preprocessor-extensions: +- erb +``` + +TODO: Add a simple example of how to use custom preprocessors. + ## Non-project-specific config Non-project config options may go in the global config (`/etc/stack/config.yaml`) or the user config (`~/.stack/config.yaml`). diff --git a/src/Stack/Package.hs b/src/Stack/Package.hs index e9482b6428..027573aa4a 100644 --- a/src/Stack/Package.hs +++ b/src/Stack/Package.hs @@ -1271,8 +1271,8 @@ logPossibilities dirs mn = do , flow "but did find:" , line <> bulletedList (map pretty possibilities) , flow "If you are using a custom preprocessor for this module" - , flow "with its own file extension, consider adding the file(s)" - , flow "to your .cabal under extra-source-files." + , flow "with its own file extension, consider adding the extension" + , flow "to the 'custom-preprocessor-extensions' field in stack.yaml." ] where makePossibilities name =