Compare commits

..

2 Commits

Author SHA1 Message Date
Taylor Fausak
11ab798d46
Replace Dhall with TOML using toml-reader (#120)
Co-authored-by: Ollie Charles <ollie@ocharles.org.uk>
2023-06-22 14:28:09 +01:00
Ollie Charles
e0ed4661b4
Update CI (#121) 2023-06-22 13:56:43 +01:00
8 changed files with 29 additions and 46 deletions

View File

@ -4,18 +4,18 @@ jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2.3.4 - uses: actions/checkout@v3.5.3
with: with:
persist-credentials: false persist-credentials: false
submodules: true submodules: true
- uses: cachix/install-nix-action@v14.1 - uses: cachix/install-nix-action@v22
with: with:
nix_path: nixpkgs=channel:nixos-unstable nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: | extra_nix_config: |
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
substituters = https://cache.nixos.org/ https://cache.iog.io substituters = https://cache.nixos.org/ https://cache.iog.io
- uses: cachix/cachix-action@v10 - uses: cachix/cachix-action@v12
with: with:
name: weeder name: weeder
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'

View File

@ -18,9 +18,9 @@ code is reachable and which code is dead.
## Preparing Your Code for Weeder ## Preparing Your Code for Weeder
To use Weeder, you will need to generate `.hie` files from your source code. To use Weeder, you will need to generate `.hie` files from your source code.
### Cabal ### Cabal
If you use Cabal, this is easily done by adding one line to your If you use Cabal, this is easily done by adding one line to your
`cabal.project.local` file: `cabal.project.local` file:
@ -55,13 +55,8 @@ stack build
## Calling Weeder ## Calling Weeder
To call Weeder, you first need to provide a configuration file, `weeder.dhall`. Weeder uses To call Weeder, you first need to provide a configuration file, `weeder.toml`. Weeder uses
[Dhall](https://dhall-lang.org) as its configuration format, and configuration [TOML](https://toml.io/en/) as its configuration format.
files have the type:
``` dhall
{ roots : List Text, type-class-roots : Bool }
```
`roots` is a list of regular expressions of symbols that are considered as `roots` is a list of regular expressions of symbols that are considered as
alive. If you're building an executable, the pattern `^Main.main$` is a alive. If you're building an executable, the pattern `^Main.main$` is a
@ -74,8 +69,9 @@ a type class instance as a root. Weeder is currently unable to add dependency
edges into type class instances, and without this flag may produce false edges into type class instances, and without this flag may produce false
positives. It's recommended to initially set this to `True`: positives. It's recommended to initially set this to `True`:
``` dhall ``` toml
{ roots = [ "^Main.main$" ], type-class-roots = True } roots = [ "^Main.main$" ]
type-class-roots = true
``` ```
Now invoke the `weeder` executable, and - if your project has weeds - you will Now invoke the `weeder` executable, and - if your project has weeds - you will
@ -93,7 +89,7 @@ in the Dhall project).
# Tips # Tips
- You may want to add `^Paths_.*` to the roots in `weeder.dhall` to ignore the - You may want to add `^Paths_.*` to the roots in `weeder.toml` to ignore the
`Paths_packageName` module automatically generated by Cabal. `Paths_packageName` module automatically generated by Cabal.
# Limitations # Limitations

View File

@ -1,10 +1,2 @@
packages: packages:
weeder.cabal weeder.cabal
-- https://github.com/well-typed/cborg/pull/304
source-repository-package
type: git
location: https://github.com/scarf-sh/cborg
tag: 8dae0d21e6f17e30785f35bb3ef5eb611863a904
subdir: cborg
--sha256: sha256-SAHFIlN5QKQKJFhHliXvXOQhrqvsE/TLvY2rkftXkHM=

View File

@ -3,14 +3,13 @@
{-# language OverloadedStrings #-} {-# language OverloadedStrings #-}
{-# language RecordWildCards #-} {-# language RecordWildCards #-}
module Weeder.Config ( Config(..), config ) where module Weeder.Config ( Config(..) ) where
-- containers -- containers
import Data.Set ( Set ) import Data.Set ( Set )
import qualified Data.Set as Set
-- dhall -- toml-reader
import qualified Dhall import qualified TOML
-- | Configuration for Weeder analysis. -- | Configuration for Weeder analysis.
@ -24,14 +23,9 @@ data Config = Config
-- instance is used - enabling this option can prevent false positives. -- instance is used - enabling this option can prevent false positives.
} }
instance TOML.DecodeTOML Config where
-- | A Dhall expression decoder for 'Config'. tomlDecoder = do
-- rootPatterns <- TOML.getField "roots"
-- This parses Dhall expressions of the type @{ roots : List Text, type-class-roots : Bool }@. typeClassRoots <- TOML.getField "type-class-roots"
config :: Dhall.Decoder Config
config =
Dhall.record do
rootPatterns <- Set.fromList <$> Dhall.field "roots" ( Dhall.list Dhall.string )
typeClassRoots <- Dhall.field "type-class-roots" Dhall.bool
return Config{..} return Config{..}

View File

@ -9,6 +9,7 @@
module Weeder.Main ( main, mainWithConfig ) where module Weeder.Main ( main, mainWithConfig ) where
-- base -- base
import Control.Exception ( throwIO )
import Control.Monad ( guard, unless, when ) import Control.Monad ( guard, unless, when )
import Control.Monad.IO.Class ( liftIO ) import Control.Monad.IO.Class ( liftIO )
import Data.Bool import Data.Bool
@ -24,8 +25,8 @@ import qualified Data.Set as Set
-- text -- text
import qualified Data.Text as T import qualified Data.Text as T
-- dhall -- toml-reader
import qualified Dhall import qualified TOML
-- directory -- directory
import System.Directory ( canonicalizePath, doesDirectoryExist, doesFileExist, doesPathExist, listDirectory, withCurrentDirectory ) import System.Directory ( canonicalizePath, doesDirectoryExist, doesFileExist, doesPathExist, listDirectory, withCurrentDirectory )
@ -63,15 +64,16 @@ main = do
execParser $ execParser $
info (optsP <**> helper <**> versionP) mempty info (optsP <**> helper <**> versionP) mempty
Dhall.input config configExpr TOML.decodeFile (T.unpack configExpr)
>>= either throwIO pure
>>= mainWithConfig hieExt hieDirectories requireHsFiles >>= mainWithConfig hieExt hieDirectories requireHsFiles
where where
optsP = (,,,) optsP = (,,,)
<$> strOption <$> strOption
( long "config" ( long "config"
<> help "A Dhall expression for Weeder's configuration. Can either be a file path (a Dhall import) or a literal Dhall expression." <> help "A file path for Weeder's configuration."
<> value "./weeder.dhall" <> value "./weeder.toml"
<> metavar "<weeder.dhall>" <> metavar "<weeder.toml>"
<> showDefaultWith T.unpack <> showDefaultWith T.unpack
) )
<*> strOption <*> strOption

View File

@ -22,7 +22,6 @@ library
, base ^>= 4.17.0.0 , base ^>= 4.17.0.0
, bytestring ^>= 0.10.9.0 || ^>= 0.11.0.0 , bytestring ^>= 0.10.9.0 || ^>= 0.11.0.0
, containers ^>= 0.6.2.1 , containers ^>= 0.6.2.1
, dhall ^>= 1.30.0 || ^>= 1.31.0 || ^>= 1.32.0 || ^>= 1.33.0 || ^>= 1.34.0 || ^>= 1.35.0 || ^>= 1.36.0 || ^>= 1.37.0 || ^>= 1.40.0 || ^>= 1.41
, directory ^>= 1.3.3.2 , directory ^>= 1.3.3.2
, filepath ^>= 1.4.2.1 , filepath ^>= 1.4.2.1
, generic-lens ^>= 2.2.0.0 , generic-lens ^>= 2.2.0.0
@ -32,6 +31,7 @@ library
, optparse-applicative ^>= 0.14.3.0 || ^>= 0.15.1.0 || ^>= 0.16.0.0 || ^>= 0.17 , optparse-applicative ^>= 0.14.3.0 || ^>= 0.15.1.0 || ^>= 0.16.0.0 || ^>= 0.17
, regex-tdfa ^>= 1.2.0.0 || ^>= 1.3.1.0 , regex-tdfa ^>= 1.2.0.0 || ^>= 1.3.1.0
, text ^>= 2.0.1 , text ^>= 2.0.1
, toml-reader ^>= 0.2.0.0
, transformers ^>= 0.5.6.2 || ^>= 0.6 , transformers ^>= 0.5.6.2 || ^>= 0.6
hs-source-dirs: src hs-source-dirs: src
exposed-modules: exposed-modules:

View File

@ -1,3 +0,0 @@
{ roots = [ "Main.main", "^Paths_weeder\\..*" ]
, type-class-roots = True
}

2
weeder.toml Normal file
View File

@ -0,0 +1,2 @@
roots = [ "Main.main", "^Paths_weeder\\..*" ]
type-class-roots = true