Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for .zip format source distributions #5755

Merged
merged 9 commits into from
Dec 1, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions Cabal/doc/nix-local-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Quickstart

Suppose that you are in a directory containing a single Cabal package
which you wish to build (if you haven't set up a package yet check
out `developing packages <developing-packages.html>`__ for
out `developing packages <developing-packages.html>`__ for
instructions). You can configure and build it using Nix-style
local builds with this command (configuring is not necessary):

Expand Down Expand Up @@ -141,8 +141,8 @@ identify the result of a build; if we compute this identifier and we
find that we already have this ID built, we can just use the already
built version.

The global package store is ``~/.cabal/store`` (configurable via
global `store-dir` option); if you need to clear your store for
The global package store is ``~/.cabal/store`` (configurable via
global `store-dir` option); if you need to clear your store for
whatever reason (e.g., to reclaim disk space or because the global
store is corrupted), deleting this directory is safe (``new-build``
will just rebuild everything it needs on its next invocation).
Expand Down Expand Up @@ -411,7 +411,7 @@ them manually or to install them globally.
This command opens a REPL with the current default target loaded, and a version
of the ``vector`` package matching that specification exposed.

::
::

$ cabal new-repl --build-depends "vector >= 0.12 && < 0.13"

Expand Down Expand Up @@ -540,7 +540,7 @@ invocations and bringing the project's executables into scope.
cabal new-install
-----------------

``cabal new-install [FLAGS] PACKAGES`` builds the specified packages and
``cabal new-install [FLAGS] PACKAGES`` builds the specified packages and
symlinks their executables in ``symlink-bindir`` (usually ``~/.cabal/bin``).

For example this command will build the latest ``cabal-install`` and symlink
Expand All @@ -559,7 +559,7 @@ repository, this command will build cabal-install HEAD and symlink the

$ cabal new-install exe:cabal

It is also possible to "install" libraries using the ``--lib`` flag. For
It is also possible to "install" libraries using the ``--lib`` flag. For
example, this command will build the latest Cabal library and install it:

::
Expand Down Expand Up @@ -630,10 +630,6 @@ and two archives of the same format built from the same source will hash to the
Output is to ``stdout`` by default. The file paths are relative to the project's root
directory.

- ``--targz``: Output an archive in ``.tar.gz`` format.

- ``--zip``: Output an archive in ``.zip`` format.

- ``-o``, ``--output-dir``: Sets the output dir, if a non-default one is desired. The default is
``dist-newstyle/sdist/``. ``--output-dir -`` will send output to ``stdout``
unless multiple archives are being created.
Expand Down Expand Up @@ -895,7 +891,7 @@ package, and thus apply globally:
.. option:: --store-dir=DIR

Specifies the name of the directory of the global package store.

Solver configuration options
----------------------------

Expand All @@ -908,7 +904,7 @@ The following settings control the behavior of the dependency solver:
Add extra constraints to the version bounds, flag settings,
and other properties a solver can pick for a
package. For example:

::

constraints: bar == 2.1
Expand Down
16 changes: 8 additions & 8 deletions cabal-install/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags
, unlines (("- " ++) . unPackageName . fst <$> xs)
]
_ -> return ()

when (not . null $ errs') $ reportTargetProblems verbosity errs'

let
Expand Down Expand Up @@ -351,7 +351,7 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags

sdistize (SpecificSourcePackage spkg@SourcePackage{..}) = SpecificSourcePackage spkg'
where
sdistPath = distSdistFile localDistDirLayout packageInfoId TargzFormat
sdistPath = distSdistFile localDistDirLayout packageInfoId
spkg' = spkg { packageSource = LocalTarballPackage sdistPath }
sdistize named = named

Expand All @@ -375,8 +375,8 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags
unless (Map.null targets) $
mapM_
(\(SpecificSourcePackage pkg) -> packageToSdist verbosity
(distProjectRootDirectory localDistDirLayout) (Archive TargzFormat)
(distSdistFile localDistDirLayout (packageId pkg) TargzFormat) pkg
(distProjectRootDirectory localDistDirLayout) TarGzArchive
(distSdistFile localDistDirLayout (packageId pkg)) pkg
) (localPackages localBaseCtx)

if null targets
Expand All @@ -391,9 +391,9 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags
| Just (pkg :: PackageId) <- simpleParse pkgName = return pkg
| otherwise = die' verbosity ("Invalid package ID: " ++ pkgName)
packageIds <- mapM parsePkg targetStrings

cabalDir <- getCabalDir
let
let
projectConfig = globalConfig <> cliConfig

ProjectConfigBuildOnly {
Expand All @@ -413,7 +413,7 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags
projectConfig

SourcePackageDb { packageIndex } <- projectConfigWithBuilderRepoContext
verbosity buildSettings
verbosity buildSettings
(getSourcePackages verbosity)

for_ targetStrings $ \case
Expand Down Expand Up @@ -724,7 +724,7 @@ entriesForLibraryComponents = Map.foldrWithKey' (\k v -> mappend (go k v)) []
hasLib :: (ComponentTarget, [TargetSelector]) -> Bool
hasLib (ComponentTarget (CLibName _) _, _) = True
hasLib _ = False

go :: UnitId -> [(ComponentTarget, [TargetSelector])] -> [GhcEnvironmentFileEntry]
go unitId targets
| any hasLib targets = [GhcEnvFilePackageId unitId]
Expand Down
58 changes: 12 additions & 46 deletions cabal-install/Distribution/Client/CmdSdist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module Distribution.Client.CmdSdist
( sdistCommand, sdistAction, packageToSdist
, SdistFlags(..), defaultSdistFlags
, OutputFormat(..), ArchiveFormat(..) ) where
, OutputFormat(..)) where

import Distribution.Client.CmdErrorMessages
( Plural(..), renderComponentKind )
Expand All @@ -19,7 +19,7 @@ import Distribution.Client.TargetSelector
import Distribution.Client.RebuildMonad
( runRebuild )
import Distribution.Client.Setup
( ArchiveFormat(..), GlobalFlags(..) )
( GlobalFlags(..) )
import Distribution.Solver.Types.SourcePackage
( SourcePackage(..) )
import Distribution.Client.Types
Expand All @@ -41,7 +41,7 @@ import Distribution.Pretty
import Distribution.ReadE
( succeedReadE )
import Distribution.Simple.Command
( CommandUI(..), option, choiceOpt, reqArg )
( CommandUI(..), option, reqArg )
import Distribution.Simple.PreProcess
( knownSuffixHandlers )
import Distribution.Simple.Setup
Expand All @@ -61,20 +61,17 @@ import Distribution.Verbosity

import qualified Codec.Archive.Tar as Tar
import qualified Codec.Archive.Tar.Entry as Tar
import qualified Codec.Archive.Zip as Zip
import qualified Codec.Compression.GZip as GZip
import Control.Exception
( throwIO )
import Control.Monad
( when, forM, forM_ )
( when, forM_ )
import Control.Monad.Trans
( liftIO )
import Control.Monad.State.Lazy
( StateT, modify, gets, evalStateT )
import Control.Monad.Writer.Lazy
( WriterT, tell, execWriterT )
import Data.Bits
( shiftL )
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.Either
Expand Down Expand Up @@ -116,16 +113,6 @@ sdistCommand = CommandUI
"Separate the source files with NUL bytes rather than newlines."
sdistNulSeparated (\v flags -> flags { sdistNulSeparated = v })
trueArg
, option [] ["archive-format"]
"Choose what type of archive to create. No effect if given with '--list-only'"
sdistArchiveFormat (\v flags -> flags { sdistArchiveFormat = v })
(choiceOpt
[ (Flag TargzFormat, ([], ["targz"]),
"Produce a '.tar.gz' format archive (default and required for uploading to hackage)")
, (Flag ZipFormat, ([], ["zip"]),
"Produce a '.zip' format archive")
]
)
, option ['o'] ["output-dir", "outputdir"]
"Choose the output directory of this command. '-' sends all output to stdout"
sdistOutputPath (\o flags -> flags { sdistOutputPath = o })
Expand All @@ -139,7 +126,6 @@ data SdistFlags = SdistFlags
, sdistProjectFile :: Flag FilePath
, sdistListSources :: Flag Bool
, sdistNulSeparated :: Flag Bool
, sdistArchiveFormat :: Flag ArchiveFormat
, sdistOutputPath :: Flag FilePath
}

Expand All @@ -150,7 +136,6 @@ defaultSdistFlags = SdistFlags
, sdistProjectFile = mempty
, sdistListSources = toFlag False
, sdistNulSeparated = toFlag False
, sdistArchiveFormat = toFlag TargzFormat
, sdistOutputPath = mempty
}

Expand All @@ -164,7 +149,6 @@ sdistAction SdistFlags{..} targetStrings globalFlags = do
globalConfig = globalConfigFile globalFlags
listSources = fromFlagOrDefault False sdistListSources
nulSeparated = fromFlagOrDefault False sdistNulSeparated
archiveFormat = fromFlagOrDefault TargzFormat sdistArchiveFormat
mOutputPath = flagToMaybe sdistOutputPath

projectRoot <- either throwIO return =<< findProjectRoot Nothing mProjectFile
Expand All @@ -186,20 +170,15 @@ sdistAction SdistFlags{..} targetStrings globalFlags = do
format =
if | listSources, nulSeparated -> SourceList '\0'
| listSources -> SourceList '\n'
| otherwise -> Archive archiveFormat

ext = case format of
SourceList _ -> "list"
Archive TargzFormat -> "tar.gz"
Archive ZipFormat -> "zip"
| otherwise -> TarGzArchive

outputPath pkg = case mOutputPath' of
Just path
| path == "-" -> "-"
| otherwise -> path </> prettyShow (packageId pkg) <.> ext
| otherwise -> path </> prettyShow (packageId pkg) <.> "tar.gz"
Nothing
| listSources -> "-"
| otherwise -> distSdistFile distLayout (packageId pkg) archiveFormat
| otherwise -> distSdistFile distLayout (packageId pkg)

createDirectoryIfMissing True (distSdistDirectory distLayout)

Expand All @@ -215,7 +194,7 @@ data IsExec = Exec | NoExec
deriving (Show, Eq)

data OutputFormat = SourceList Char
| Archive ArchiveFormat
| TarGzArchive
deriving (Show, Eq)

packageToSdist :: Verbosity -> FilePath -> OutputFormat -> FilePath -> UnresolvedSourcePackage -> IO ()
Expand All @@ -237,10 +216,10 @@ packageToSdist verbosity projectRootDir format outputFile pkg = do
case dir0 of
Left tgz -> do
case format of
Archive TargzFormat -> do
TarGzArchive -> do
write =<< BSL.readFile tgz
when (outputFile /= "-") $
notice verbosity $ "Wrote tarball sdist to " ++ outputFile ++ "\n"
notice verbosity $ "Wrote tarball sdist to " ++ outputFile ++ "\n"
_ -> die' verbosity ("cannot convert tarball package to " ++ show format)

Right dir -> do
Expand All @@ -259,7 +238,7 @@ packageToSdist verbosity projectRootDir format outputFile pkg = do
write (BSL.pack . (++ [nulSep]) . intercalate [nulSep] . fmap ((prefix </>) . snd) $ files)
when (outputFile /= "-") $
notice verbosity $ "Wrote source list to " ++ outputFile ++ "\n"
Archive TargzFormat -> do
TarGzArchive -> do
let entriesM :: StateT (Set.Set FilePath) (WriterT [Tar.Entry] IO) ()
entriesM = do
let prefix = prettyShow (packageId pkg)
Expand Down Expand Up @@ -301,20 +280,7 @@ packageToSdist verbosity projectRootDir format outputFile pkg = do
write . normalize . GZip.compress . Tar.write $ fmap setModTime entries
when (outputFile /= "-") $
notice verbosity $ "Wrote tarball sdist to " ++ outputFile ++ "\n"
Archive ZipFormat -> do
let prefix = prettyShow (packageId pkg)
entries <- forM files $ \(perm, file) -> do
let perm' = case perm of
-- -rwxr-xr-x
Exec -> 0o010755 `shiftL` 16
-- -rw-r--r--
NoExec -> 0o010644 `shiftL` 16
contents <- BSL.readFile file
return $ (Zip.toEntry (prefix </> file) 0 contents) { Zip.eExternalFileAttributes = perm' }
let archive = foldr Zip.addEntryToArchive Zip.emptyArchive entries
write (Zip.fromArchive archive)
when (outputFile /= "-") $
notice verbosity $ "Wrote zip sdist to " ++ outputFile ++ "\n"

setCurrentDirectory oldPwd

--
Expand Down
12 changes: 3 additions & 9 deletions cabal-install/Distribution/Client/DistDirLayout.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import System.FilePath

import Distribution.Package
( PackageId, ComponentId, UnitId )
import Distribution.Client.Setup
( ArchiveFormat(..) )
import Distribution.Compiler
import Distribution.Simple.Compiler
( PackageDB(..), PackageDBStack, OptimisationLevel(..) )
Expand Down Expand Up @@ -115,7 +113,7 @@ data DistDirLayout = DistDirLayout {
distPackageCacheDirectory :: DistDirParams -> FilePath,

-- | The location that sdists are placed by default.
distSdistFile :: PackageId -> ArchiveFormat -> FilePath,
distSdistFile :: PackageId -> FilePath,
distSdistDirectory :: FilePath,

distTempDirectory :: FilePath,
Expand Down Expand Up @@ -227,12 +225,8 @@ defaultDistDirLayout projectRoot mdistDirectory =
distPackageCacheDirectory params = distBuildDirectory params </> "cache"
distPackageCacheFile params name = distPackageCacheDirectory params </> name

distSdistFile pid format = distSdistDirectory </> prettyShow pid <.> ext
where
ext = case format of
TargzFormat -> "tar.gz"
ZipFormat -> "zip"

distSdistFile pid = distSdistDirectory </> prettyShow pid <.> "tar.gz"

distSdistDirectory = distDirectory </> "sdist"

distTempDirectory = distDirectory </> "tmp"
Expand Down
42 changes: 3 additions & 39 deletions cabal-install/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module Distribution.Client.Setup
, reportCommand, ReportFlags(..)
, runCommand
, initCommand, IT.InitFlags(..)
, sdistCommand, SDistFlags(..), SDistExFlags(..), ArchiveFormat(..)
, sdistCommand, SDistFlags(..)
, win32SelfUpgradeCommand, Win32SelfUpgradeFlags(..)
, actAsSetupCommand, ActAsSetupFlags(..)
, sandboxCommand, defaultSandboxLocation, SandboxFlags(..)
Expand Down Expand Up @@ -2384,49 +2384,13 @@ initCommand = CommandUI {

-- | Extra flags to @sdist@ beyond runghc Setup sdist
--
data SDistExFlags = SDistExFlags {
sDistFormat :: Flag ArchiveFormat
}
deriving (Show, Generic)

data ArchiveFormat = TargzFormat | ZipFormat -- ...
deriving (Show, Eq)

defaultSDistExFlags :: SDistExFlags
defaultSDistExFlags = SDistExFlags {
sDistFormat = Flag TargzFormat
}

sdistCommand :: CommandUI (SDistFlags, SDistExFlags)
sdistCommand :: CommandUI SDistFlags
sdistCommand = Cabal.sdistCommand {
commandUsage = \pname ->
"Usage: " ++ pname ++ " v1-sdist [FLAGS]\n",
commandDefaultFlags = (commandDefaultFlags Cabal.sdistCommand, defaultSDistExFlags),
commandOptions = \showOrParseArgs ->
liftOptions fst setFst (commandOptions Cabal.sdistCommand showOrParseArgs)
++ liftOptions snd setSnd sdistExOptions
commandDefaultFlags = (commandDefaultFlags Cabal.sdistCommand)
}
where
setFst a (_,b) = (a,b)
setSnd b (a,_) = (a,b)

sdistExOptions =
[option [] ["archive-format"] "archive-format"
sDistFormat (\v flags -> flags { sDistFormat = v })
(choiceOpt
[ (Flag TargzFormat, ([], ["targz"]),
"Produce a '.tar.gz' format archive (default and required for uploading to hackage)")
, (Flag ZipFormat, ([], ["zip"]),
"Produce a '.zip' format archive")
])
]

instance Monoid SDistExFlags where
mempty = gmempty
mappend = (<>)

instance Semigroup SDistExFlags where
(<>) = gmappend

--

Expand Down
Loading