Skip to content

Commit

Permalink
Merge pull request #654 from commercialhaskell/sdist-command
Browse files Browse the repository at this point in the history
Add 'stack sdist' command
  • Loading branch information
mgsloan committed Jul 22, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 500a553 + 4071b30 commit ba5bc52
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/Main.hs
Original file line number Diff line number Diff line change
@@ -15,8 +15,10 @@ import Control.Monad.IO.Class
import Control.Monad.Logger
import Control.Monad.Reader (ask, asks)
import Data.Attoparsec.Args (withInterpreterArgs)
import qualified Data.ByteString.Lazy as L
import Data.List
import qualified Data.List as List
import qualified Data.Map as Map
import Data.Maybe
import Data.Monoid
import qualified Data.Set as Set
@@ -165,6 +167,10 @@ main = withInterpreterArgs stackProgName $ \args isInterpreter ->
"Upload a package to Hackage"
uploadCmd
(many $ strArgument $ metavar "TARBALL/DIR")
addCommand "sdist"
"Create source distribution tarballs"
sdistCmd
(many $ strArgument $ metavar "DIR")
addCommand "dot"
"Visualize your project's dependency graph using Graphviz dot"
dotCmd
@@ -574,6 +580,20 @@ uploadCmd args go = do
(tarName, tarBytes) <- getSDistTarball pkgDir
liftIO $ Upload.uploadBytes uploader tarName tarBytes

sdistCmd :: [String] -> GlobalOpts -> IO ()
sdistCmd dirs go =
withBuildConfig go ExecStrategy $ do
-- If no directories are specified, build all sdist tarballs.
dirs' <- if null dirs
then asks (Map.keys . bcPackages . getBuildConfig)
else mapM (parseAbsDir <=< liftIO . canonicalizePath) dirs
forM_ dirs' $ \dir -> do
(tarName, tarBytes) <- getSDistTarball dir
distDir <- distDirFromDir dir
tarPath <- fmap (distDir </>) $ parseRelFile tarName
liftIO $ L.writeFile (toFilePath tarPath) tarBytes
$logInfo $ "Wrote sdist tarball to " <> T.pack (toFilePath tarPath)

-- | Execute a command.
execCmd :: ExecOpts -> GlobalOpts -> IO ()
execCmd ExecOpts {..} go@GlobalOpts{..} =

0 comments on commit ba5bc52

Please sign in to comment.