Skip to content

Instantly share code, notes, and snippets.

@snoyberg
Created April 1, 2020 08:54
Show Gist options
  • Save snoyberg/99849b2c92b1a34f0cd9c509e2161ab7 to your computer and use it in GitHub Desktop.
Save snoyberg/99849b2c92b1a34f0cd9c509e2161ab7 to your computer and use it in GitHub Desktop.
Complete snapshot layer
resolver: lts-15.5
packages:
- pantry-0.4.0.1
- casa-client-0.0.1
- casa-types-0.0.1
- hackage-security-0.6.0.0
- hpack-0.33.0
- lukko-0.1.1.1
#!/usr/bin/env stack
-- stack --resolver foo.yaml script
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
import Pantry
import RIO
import Path
import Path.IO
import Data.Yaml (encodeFile)
complete
:: FilePath -- ^ input
-> FilePath -- ^ output
-> RIO PantryApp ()
complete inputFP outputFP = do
-- This make-a-resolved-path logic can move into Pantry itself
inputRel <- parseRelFile inputFP
inputAbs <- canonicalizePath inputRel
let inputRP = ResolvedPath
{ resolvedRelative = RelFilePath $ fromString inputFP
, resolvedAbsolute = inputAbs
}
ersl <- loadSnapshotLayer $ SLFilePath inputRP
rsl <-
case ersl of
Left _ -> throwString "We don't complete compiler-only layers"
Right rsl -> pure rsl
sl <- completeSnapshotLayer rsl
liftIO $ encodeFile outputFP sl
completeSnapshotLayer
:: RawSnapshotLayer
-> RIO PantryApp SnapshotLayer
completeSnapshotLayer RawSnapshotLayer {..} = do
slParent <- completeSnapshotLocation rslParent
slLocations <- for rslLocations $ \rawLoc -> do
cpl <- completePackageLocation rawLoc
if cplHasCabalFile cpl
then pure $ cplComplete cpl
else throwString $ "We're no longer supporting packages without cabal files: " ++ show rawLoc
let slCompiler = rslCompiler
slDropPackages = rslDropPackages
slFlags = rslFlags
slHidden = rslHidden
slGhcOptions = rslGhcOptions
slPublishTime = rslPublishTime
pure SnapshotLayer {..}
main :: IO ()
main = runPantryApp $ complete "foo.yaml" "bar.yaml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment