Skip to content

Commit

Permalink
Merge branch 'custom-preprocessors' of https://github.com/anka-213/stack
Browse files Browse the repository at this point in the history
 into anka-213-custom-preprocessors
  • Loading branch information
snoyberg committed Mar 25, 2021
2 parents d683e21 + 56f33cc commit 6b33abe
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 18 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Other enhancements:

* Consider GHC 9.0 a tested compiler and remove warnings.

* `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
Expand Down
26 changes: 19 additions & 7 deletions doc/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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).
```
Expand Down
11 changes: 11 additions & 0 deletions doc/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Stack/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Stack.Constants
(buildPlanDir
,buildPlanCacheDir
,haskellFileExts
,haskellPreprocessorExts
,haskellDefaultPreprocessorExts
,stackDotYaml
,stackWorkEnvVar
,stackRootEnvVar
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/Stack/Options/ConfigParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +37,7 @@ configOptsParser currentDir hide0 =
, configMonoidJobs = jobs
, configMonoidExtraIncludeDirs = includes
, configMonoidExtraLibDirs = libs
, configMonoidCustomPreprocessorExts = preprocs
, configMonoidOverrideGccPath = overrideGccPath
, configMonoidOverrideHpack = overrideHpack
, configMonoidSkipMsys = skipMsys
Expand Down Expand Up @@ -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"
Expand Down
17 changes: 10 additions & 7 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -1268,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 =
Expand Down
8 changes: 8 additions & 0 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 6b33abe

Please sign in to comment.