-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
105 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Stack.Freeze | ||
( freeze | ||
, FreezeOpts (..) | ||
) where | ||
|
||
import qualified Data.Map as Map | ||
import qualified Data.Set as Set | ||
import qualified Data.Yaml as Yaml | ||
import qualified RIO.ByteString as B | ||
import Stack.Prelude | ||
import Stack.Build.Target | ||
import Stack.Types.Config | ||
import Stack.Types.Package | ||
import Stack.Build.Source | ||
|
||
|
||
data FreezeOpts = FreezeOpts | ||
{ freezeTargets :: [Text] | ||
-- ^ stack TARGETs to trace dependencies for | ||
, freezeFlags :: !(Map (Maybe PackageName) (Map FlagName Bool)) | ||
-- ^ Flags to apply when calculating dependencies | ||
, freezeExtraTargets :: !ExtraTargets | ||
-- ^ Like the "--test" / "--bench" flag for build, affects the meaning of 'dotTargets'. | ||
} | ||
|
||
freeze :: HasEnvConfig env => FreezeOpts -> RIO env () | ||
freeze freezeOpts = do | ||
(locals, sourceMap) <- loadSourceMap NeedTargets defaultBuildOptsCLI | ||
{ boptsCLITargets = freezeTargets freezeOpts | ||
, boptsCLIFlags = freezeFlags freezeOpts | ||
} | ||
let graph = Map.fromList (localDependencies (filter lpWanted locals)) | ||
toPackageLocImmutable (PSRemote _ _ _ pli _) = Just $ mkUnresolvedPackageLocationImmutable pli | ||
toPackageLocImmutable (PSFilePath _ _) = Nothing | ||
sources = Set.unions $ Map.elems graph | ||
locations = mapMaybe (fmap toPackageLocImmutable . flip Map.lookup sourceMap) $ Set.toList sources | ||
liftIO $ B.putStr $ Yaml.encode locations | ||
|
||
|
||
-- | Resolve the direct (depth 0) external dependencies of the given local packages | ||
localDependencies :: [LocalPackage] -> [(PackageName, Set PackageName)] | ||
localDependencies locals = | ||
map (\lp -> let pkg = localPackageToPackage lp | ||
in (packageName pkg, deps pkg)) | ||
locals | ||
where deps pkg = | ||
Set.delete (packageName pkg) (packageAllDeps pkg) | ||
localPackageToPackage lp = | ||
fromMaybe (lpPackage lp) (lpTestBench lp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module Stack.Options.FreezeParser where | ||
|
||
import Options.Applicative | ||
import Stack.Freeze | ||
import Stack.Options.BuildParser | ||
|
||
|
||
-- | Parser for arguments to `stack freeze` | ||
freezeOptsParser :: Parser FreezeOpts | ||
freezeOptsParser = | ||
FreezeOpts <$> targetsParser | ||
<*> flagsParser | ||
<*> extraTargetsParser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters