Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
haskell
shake-plus-extended
Commits
dfd26c31
Commit
dfd26c31
authored
4 years ago
by
Daniel Firth
Browse files
Options
Download
Email Patches
Plain Diff
Fix styling
parent
ee68c10f
Pipeline
#529
failed with stages
in 8 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
150 additions
and
138 deletions
+150
-138
src/Development/Shake/Plus/Extended.hs
src/Development/Shake/Plus/Extended.hs
+17
-18
src/Development/Shake/Plus/Extended/Conduit.hs
src/Development/Shake/Plus/Extended/Conduit.hs
+20
-20
src/Development/Shake/Plus/Extended/FileRules.hs
src/Development/Shake/Plus/Extended/FileRules.hs
+28
-27
src/Development/Shake/Plus/Extended/Loaders.hs
src/Development/Shake/Plus/Extended/Loaders.hs
+63
-51
src/Development/Shake/Plus/Extended/Simple.hs
src/Development/Shake/Plus/Extended/Simple.hs
+22
-22
No files found.
src/Development/Shake/Plus/Extended.hs
View file @
dfd26c31
{- |
Module : Development.Shake.Plus.Extended
Copyright : Copyright (C) 2020 Daniel Firth
Maintainer : Daniel Firth <dan.firth@homotopic.tech>
License : MIT
Stability : experimental
Module exports for Development.Shake.Plus.Extended.
-}
module
Development.Shake.Plus.Extended
(
module
Development
.
Shake
.
Plus
.
Extended
.
FileRules
,
module
Development
.
Shake
.
Plus
.
Extended
.
Loaders
,
module
Development
.
Shake
.
Plus
.
Extended
.
Simple
)
where
-- |
-- Module : Development.Shake.Plus.Extended
-- Copyright : Copyright (C) 2020 Daniel Firth
-- Maintainer : Daniel Firth <dan.firth@homotopic.tech>
-- License : MIT
-- Stability : experimental
--
-- Module exports for Development.Shake.Plus.Extended.
module
Development.Shake.Plus.Extended
(
module
Development
.
Shake
.
Plus
.
Extended
.
FileRules
,
module
Development
.
Shake
.
Plus
.
Extended
.
Loaders
,
module
Development
.
Shake
.
Plus
.
Extended
.
Simple
,
)
where
import
Data.IxSet.Typed.Binary
()
import
Data.IxSet.Typed.Hashable
()
import
Development.Shake.Plus.Extended.FileRules
import
Development.Shake.Plus.Extended.Loaders
import
Development.Shake.Plus.Extended.Simple
import
Path.Binary
()
import
Data.IxSet.Typed.Binary
()
import
Data.IxSet.Typed.Hashable
()
import
Path.Binary
()
This diff is collapsed.
Click to expand it.
src/Development/Shake/Plus/Extended/Conduit.hs
View file @
dfd26c31
{- |
Module : Shakebook.Conduit
License : MIT
Stability : experimental
Utilities for using conduit to store remote caches.
-}
module
Development.Shake.Plus.Extended.Conduit
(
RemoteJSONLookup
(
..
)
,
addRemoteJSONOracleCache
)
where
import
Data.Aeson
import
Data.Binary.Instances.Aeson
()
import
Development.Shake.Plus
import
Network.HTTP.Simple
import
RIO
import
qualified
RIO.Text
as
T
-- |
-- Module : Shakebook.Conduit
-- License : MIT
-- Stability : experimental
--
-- Utilities for using conduit to store remote caches.
module
Development.Shake.Plus.Extended.Conduit
(
RemoteJSONLookup
(
..
),
addRemoteJSONOracleCache
,
)
where
import
Data.Aeson
import
Data.Binary.Instances.Aeson
()
import
Development.Shake.Plus
import
Network.HTTP.Simple
import
RIO
import
qualified
RIO.Text
as
T
-- | Remote json lookup for an oracle, this should contain a URL as Text.
newtype
RemoteJSONLookup
=
RemoteJSONLookup
Text
...
...
@@ -25,7 +24,9 @@ newtype RemoteJSONLookup = RemoteJSONLookup Text
type
instance
RuleResult
RemoteJSONLookup
=
Value
deriving
instance
Hashable
RemoteJSONLookup
deriving
instance
Binary
RemoteJSONLookup
deriving
instance
NFData
RemoteJSONLookup
-- | Adds an oracle cache for looking up json from a remote server.
...
...
@@ -34,4 +35,3 @@ addRemoteJSONOracleCache = addOracleCache $ \(RemoteJSONLookup x) -> do
initReq
<-
parseRequest
$
T
.
unpack
x
(
y
::
Response
Value
)
<-
httpJSON
initReq
return
$
getResponseBody
y
This diff is collapsed.
Click to expand it.
src/Development/Shake/Plus/Extended/FileRules.hs
View file @
dfd26c31
{- |
Module : Development.Shake.Plus.Extended.FileRules
Copyright : Copyright (C) 2020 Daniel Firth
Maintainer : Daniel Firth <dan.firth@homotopic.tech>
License : MIT
Stability : experimental
-- |
-- Module : Development.Shake.Plus.Extended.FileRules
-- Copyright : Copyright (C) 2020 Daniel Firth
-- Maintainer : Daniel Firth <dan.firth@homotopic.tech>
-- License : MIT
-- Stability : experimental
module
Development.Shake.Plus.Extended.FileRules
(
HasLocalOut
(
..
),
(
/%>
),
(
/|%>
),
(
%^>
),
(
|%^>
),
)
where
-}
module
Development.Shake.Plus.Extended.FileRules
(
HasLocalOut
(
..
)
,
(
/%>
)
,
(
/|%>
)
,
(
%^>
)
,
(
|%^>
)
)
where
import
Control.Comonad.Env
as
E
import
Control.Exception.Extra
import
Development.Shake.FilePath
import
Development.Shake.Plus
import
RIO
as
R
import
Within
import
Control.Comonad.Env
as
E
import
Control.Exception.Extra
import
Development.Shake.FilePath
import
Development.Shake.Plus
import
RIO
as
R
import
Within
class
HasLocalOut
r
where
localOutL
::
Lens'
r
(
Path
Rel
Dir
)
-- | Variant of `(%>)` that passes the local directory from the environment into the callback.
(
/%>
)
::
(
MonadReader
r
m
,
HasLocalOut
r
,
MonadRules
m
)
=>
FilePattern
->
((
Path
Rel
Dir
,
Path
Rel
File
)
->
RAction
r
()
)
->
m
()
(
/%>
)
xs
ract
=
R
.
ask
>>=
\
r
->
do
let
d
=
view
localOutL
r
(
toFilePath
d
<>
xs
)
%>
(
stripProperPrefix
d
>=>
\
x
->
ract
(
d
,
x
))
(
/%>
)
xs
ract
=
R
.
ask
>>=
\
r
->
do
let
d
=
view
localOutL
r
(
toFilePath
d
<>
xs
)
%>
(
stripProperPrefix
d
>=>
\
x
->
ract
(
d
,
x
))
-- | Variant of `(|%>)` that passes the local directory from the environment into the callback.
(
/|%>
)
::
(
MonadReader
r
m
,
HasLocalOut
r
,
MonadRules
m
)
=>
[
FilePattern
]
->
((
Path
Rel
Dir
,
Path
Rel
File
)
->
RAction
r
()
)
->
m
()
(
/|%>
)
xs
ract
=
R
.
ask
>>=
\
r
->
do
let
d
=
view
localOutL
r
((
toFilePath
d
<>
)
<$>
xs
)
|%>
(
stripProperPrefix
d
>=>
\
x
->
ract
(
d
,
x
))
(
/|%>
)
xs
ract
=
R
.
ask
>>=
\
r
->
do
let
d
=
view
localOutL
r
((
toFilePath
d
<>
)
<$>
xs
)
|%>
(
stripProperPrefix
d
>=>
\
x
->
ract
(
d
,
x
))
-- | `Within` variant of `(%>)`, used to keep track of local directories.
(
%^>
)
::
(
Partial
,
MonadReader
r
m
,
MonadRules
m
)
=>
Within
Rel
FilePattern
->
(
Within
Rel
(
Path
Rel
File
)
->
RAction
r
()
)
->
m
()
...
...
This diff is collapsed.
Click to expand it.
src/Development/Shake/Plus/Extended/Loaders.hs
View file @
dfd26c31
{- |
Module : Development.Shake.Plus.Extended.Loaders
Copyright : Copyright (C) 2020 Daniel Firth
Maintainer : Daniel Firth <dan.firth@homotopic.tech
License : MIT
Stability : experimental
-- |
-- Module : Development.Shake.Plus.Extended.Loaders
-- Copyright : Copyright (C) 2020 Daniel Firth
-- Maintainer : Daniel Firth <dan.firth@homotopic.tech
-- License : MIT
-- Stability : experimental
--
-- Experimental loaders for shake-plus. Load a collection of `FilePattern`s as a `HashMap`.
module
Development.Shake.Plus.Extended.Loaders
(
batchLoad
,
batchLoadWithin
,
batchLoadWithin'
,
batchLoadIndex
,
batchLoadIndex'
,
)
where
Experimental loaders for shake-plus. Load a collection of `FilePattern`s as a `HashMap`.
-}
module
Development.Shake.Plus.Extended.Loaders
(
batchLoad
,
batchLoadWithin
,
batchLoadWithin'
,
batchLoadIndex
,
batchLoadIndex'
)
where
import
Control.Comonad.Env
as
E
import
Development.Shake.Plus.Core
import
Development.Shake.Plus.Directory
import
qualified
Data.IxSet.Typed
as
Ix
import
Path
import
RIO
import
qualified
RIO.HashMap
as
HM
import
Within
import
Control.Comonad.Env
as
E
import
qualified
Data.IxSet.Typed
as
Ix
import
Development.Shake.Plus.Core
import
Development.Shake.Plus.Directory
import
Path
import
RIO
import
qualified
RIO.HashMap
as
HM
import
Within
traverseToSnd
::
Functor
f
=>
(
a
->
f
b
)
->
a
->
f
(
a
,
b
)
traverseToSnd
f
a
=
(
a
,)
<$>
f
a
-- | Load a directory of `FilePattern`s via some loading function. This should
-- be a `Development.Shake.newCache` operation that takes full filepaths.
batchLoad
::
MonadAction
m
=>
Path
b
Dir
-- ^ The directory to search in
->
[
FilePattern
]
-- ^ A filepattern to match against.
->
(
Path
b
File
->
m
a
)
-- ^ A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
->
m
(
HashMap
(
Path
Rel
File
)
a
)
batchLoad
::
MonadAction
m
=>
-- | The directory to search in
Path
b
Dir
->
-- | A filepattern to match against.
[
FilePattern
]
->
-- | A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
(
Path
b
File
->
m
a
)
->
m
(
HashMap
(
Path
Rel
File
)
a
)
batchLoad
dir
pat
f
=
do
xs
<-
getDirectoryFiles
dir
pat
xs
<-
getDirectoryFiles
dir
pat
xs'
<-
mapM
(
traverseToSnd
$
f
.
(
dir
</>
))
xs
return
.
HM
.
fromList
$
xs'
-- | Like `batchLoad`, but returns an `Within` of a `Dir` containing the `HashMap`
batchLoadWithin
::
MonadAction
m
=>
Within
b
[
FilePattern
]
-- ^ The directory and filepattern to search.
->
(
Within
b
(
Path
Rel
File
)
->
m
a
)
-- ^ A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
->
m
(
Within
b
(
HashMap
(
Path
Rel
File
)
a
))
batchLoadWithin
::
MonadAction
m
=>
-- | The directory and filepattern to search.
Within
b
[
FilePattern
]
->
-- | A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
(
Within
b
(
Path
Rel
File
)
->
m
a
)
->
m
(
Within
b
(
HashMap
(
Path
Rel
File
)
a
))
batchLoadWithin
w
f
=
do
xs
<-
getDirectoryFiles
(
E
.
ask
w
)
(
extract
w
)
xs
<-
getDirectoryFiles
(
E
.
ask
w
)
(
extract
w
)
xs'
<-
mapM
(
traverseToSnd
$
f
.
(`
within
`
E
.
ask
w
))
xs
return
$
(`
within
`
E
.
ask
w
)
$
HM
.
fromList
xs'
-- | Like `batchLoadWithin'`, but returns a `HashMap` containing `Within` values instead of an `Within` of a `Hashmap`.
batchLoadWithin'
::
MonadAction
m
=>
Within
b
[
FilePattern
]
-- ^ The directory and filepattern to search.
->
(
Within
b
(
Path
Rel
File
)
->
m
a
)
-- ^ A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
->
m
(
HashMap
(
Within
b
(
Path
Rel
File
))
a
)
batchLoadWithin'
::
MonadAction
m
=>
-- | The directory and filepattern to search.
Within
b
[
FilePattern
]
->
-- | A `Development.Shake.Plus.newCache` operation that loads the file and turns it into some `a`.
(
Within
b
(
Path
Rel
File
)
->
m
a
)
->
m
(
HashMap
(
Within
b
(
Path
Rel
File
))
a
)
batchLoadWithin'
w
f
=
do
xs
<-
getDirectoryFiles
(
E
.
ask
w
)
(
extract
w
)
xs
<-
getDirectoryFiles
(
E
.
ask
w
)
(
extract
w
)
xs'
<-
mapM
(
traverseToSnd
$
f
.
(`
within
`
E
.
ask
w
))
xs
return
$
HM
.
fromList
(
first
(`
within
`
E
.
ask
w
)
<$>
xs'
)
-- | Take a loading function and a filepattern and return an IxSet
batchLoadIndex
::
(
MonadAction
m
,
Ix
.
Indexable
ixs
x
)
=>
(
Path
Rel
File
->
m
x
)
->
Path
Rel
Dir
->
[
FilePattern
]
->
m
(
Ix
.
IxSet
ixs
x
)
batchLoadIndex
::
(
MonadAction
m
,
Ix
.
Indexable
ixs
x
)
=>
(
Path
Rel
File
->
m
x
)
->
Path
Rel
Dir
->
[
FilePattern
]
->
m
(
Ix
.
IxSet
ixs
x
)
batchLoadIndex
rd
dir
fp
=
Ix
.
fromList
.
HM
.
elems
<$>
batchLoad
dir
fp
rd
-- | Take a loading function and a filepattern and return an IxSet
batchLoadIndex'
::
(
MonadAction
m
,
Ix
.
Indexable
ixs
x
)
=>
Proxy
ixs
->
(
Path
Rel
File
->
m
x
)
->
Path
Rel
Dir
->
[
FilePattern
]
->
m
(
Ix
.
IxSet
ixs
x
)
batchLoadIndex'
::
(
MonadAction
m
,
Ix
.
Indexable
ixs
x
)
=>
Proxy
ixs
->
(
Path
Rel
File
->
m
x
)
->
Path
Rel
Dir
->
[
FilePattern
]
->
m
(
Ix
.
IxSet
ixs
x
)
batchLoadIndex'
_
rd
dir
fp
=
Ix
.
fromList
.
HM
.
elems
<$>
batchLoad
dir
fp
rd
This diff is collapsed.
Click to expand it.
src/Development/Shake/Plus/Extended/Simple.hs
View file @
dfd26c31
{
- |
Module : Development.Shake.Plus.Extended.Simple
Copyright : Copyright (C) 2020 Daniel Firth
Maintainer : Daniel Firth <dan.firth@homotopic.tech>
License : MIT
Stability : experimental
Shortcuts to run shake-plus with a simple environment.
-}
module
Development.Shake.Plus.Extended.Simple
(
SimpleSPlusEnv
(
..
)
,
run
Logged
ShakePlus
,
run
SimpleShakePlus
,
runLoggedShakeForward
)
where
-
- |
--
Module : Development.Shake.Plus.Extended.Simple
--
Copyright : Copyright (C) 2020 Daniel Firth
--
Maintainer : Daniel Firth <dan.firth@homotopic.tech>
--
License : MIT
--
Stability : experimental
--
--
Shortcuts to run shake-plus with a simple environment.
module
Development.Shake.Plus.Extended.Simple
(
SimpleSPlusEnv
(
..
),
runLoggedShakePlus
,
run
Simple
ShakePlus
,
run
LoggedShakeForward
,
)
where
import
Development.Shake.Plus
import
Development.Shake.Plus.Forward
import
Development.Shake.Plus.Extended.FileRules
import
Development.Shake.Plus.Forward
import
RIO
data
SimpleSPlusEnv
=
SimpleSPlusEnv
{
logFunc
::
LogFunc
,
localOut
::
Path
Rel
Dir
}
data
SimpleSPlusEnv
=
SimpleSPlusEnv
{
logFunc
::
LogFunc
,
localOut
::
Path
Rel
Dir
}
instance
HasLogFunc
SimpleSPlusEnv
where
logFuncL
=
lens
logFunc
(
\
x
y
->
x
{
logFunc
=
y
}
)
logFuncL
=
lens
logFunc
(
\
x
y
->
x
{
logFunc
=
y
})
instance
HasLocalOut
SimpleSPlusEnv
where
localOutL
=
lens
localOut
(
\
x
y
->
x
{
localOut
=
y
})
localOutL
=
lens
localOut
(
\
x
y
->
x
{
localOut
=
y
})
-- | Run a `ShakePlus` with just a `LogFunc` in the environment that logs to stderr.
runLoggedShakePlus
::
MonadIO
m
=>
ShakeOptions
->
ShakePlus
LogFunc
a
->
m
()
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help