cabal-rpm 0.9.11 → 0.10.0
raw patch · 17 files changed
+440/−250 lines, 17 filesnew-component:exe:cabal-rpm
Files
- ChangeLog +19/−0
- cabal-rpm.cabal +7/−3
- man/cabal-rpm.1 +115/−0
- man/cabal-rpm.1.md +81/−0
- man/cblrpm.1 +0/−103
- man/cblrpm.1.md +0/−81
- src/Commands/Depends.hs +1/−1
- src/Commands/Refresh.hs +44/−0
- src/Commands/RpmBuild.hs +9/−1
- src/Commands/Spec.hs +49/−38
- src/Commands/Update.hs +10/−6
- src/Dependencies.hs +12/−6
- src/Distro.hs +42/−0
- src/Main.hs +2/−0
- src/PackageUtils.hs +18/−9
- src/Setup.hs +25/−2
- src/SysCmd.hs +6/−0
ChangeLog view
@@ -1,3 +1,22 @@+* 0.10.0 (2016-07-27)+- rename executable and manpage back to 'cabal-rpm': more predictable+- explicit error for unknown command+- sort docs and include upstream changelogs and news+- add cabal-rpm version header line to spec files+- new highly experimental command to refresh spec files+- only add "ExclusiveArch: %{ghc_arches_with_ghci}" for RHEL/EPEL+- use revised Hackage .cabal files on SUSE (@peti)+- on SUSE add explicit requires for pkgconfig+- new --compiler option (@peti)+- new --distro option (@peti)+- new --strict option which fails when missing cdeps (@peti),+ otherwise a warning is not output+- update now shows the generated patch+- use %cabal_test (@mimi1vx)+- no longer duplicate docs in datadir+- package datadir better+- for SUSE libs executables now go in the base package+ * 0.9.11 (2016-05-06) - build with Cabal-1.24
cabal-rpm.cabal view
@@ -1,5 +1,5 @@ Name: cabal-rpm-Version: 0.9.11+Version: 0.10.0 Synopsis: RPM packaging tool for Haskell Cabal-based packages Description: This package provides a RPM packaging tool for Haskell Cabal-based packages.@@ -20,8 +20,10 @@ 2012-2016 Jens Petersen <petersen@fedoraproject.org> Category: Distribution Build-type: Simple-Extra-source-files: README.md ChangeLog man/cblrpm.1.md man/cblrpm.1+Extra-source-files: README.md ChangeLog man/cabal-rpm.1.md man/cabal-rpm.1 Cabal-version: >=1.6+Tested-with: GHC == 7.0.4, GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4,+ GHC == 7.10.3, GHC == 8.0.1 source-repository head type: git@@ -31,7 +33,7 @@ Description: Use old-locale and time < 1.5 Default: True -Executable cblrpm+Executable cabal-rpm Main-is: Main.hs Build-depends: base < 5, Cabal > 1.10 && < 1.25,@@ -49,9 +51,11 @@ Commands.Diff, Commands.Install, Commands.RpmBuild,+ Commands.Refresh, Commands.Spec, Commands.Update, Dependencies,+ Distro, FileUtils, PackageUtils, Setup,
+ man/cabal-rpm.1 view
@@ -0,0 +1,115 @@+.\" Automatically generated by Pandoc 1.17.2+.\"+.TH "CBLRPM" "1" "2013\-01\-21" "" ""+.hy+.SH NAME+.PP+cblrpm \- a RPM packaging tool for Haskell Cabal packages+.SH SYNOPSIS+.PP+cblrpm [\f[I]options\f[]] spec [\f[I]path\-or\-pkg\f[]] cblrpm+[\f[I]options\f[]] local [\f[I]path\-or\-pkg\f[]] cblrpm+[\f[I]options\f[]] srpm [\f[I]path\-or\-pkg\f[]] cblrpm+[\f[I]options\f[]] prep [\f[I]path\-or\-pkg\f[]] cblrpm+[\f[I]options\f[]] builddep [\f[I]path\-or\-pkg\f[]] cblrpm+[\f[I]options\f[]] install [\f[I]path\-or\-pkg\f[]] cblrpm+[\f[I]options\f[]] depends [\f[I]path\-or\-pkg\f[]] cblrpm+[\f[I]options\f[]] requires [\f[I]path\-or\-pkg\f[]] cblrpm+[\f[I]options\f[]] missingdeps [\f[I]path\-or\-pkg\f[]] cblrpm+[\f[I]options\f[]] diff [\f[I]path\-or\-pkg\f[]] cblrpm+[\f[I]options\f[]] update [\f[I]path\-or\-pkg\f[]]+.SH DESCRIPTION+.PP+cblrpm generates RPM packages and .spec files from Haskell Cabal+package.+.PP+If no \f[I]path\-or\-pkg\f[] is specified, cblrpm looks for a .spec or+.cabal file in the current directory.+Otherwise, it will look for \f[I]path\-or\-pkg\f[].+If the argument is a directory then it will look there for a .spec or+.cabal file.+If the argument is a path to a .cabal file then it will use it.+Otherwise if there is no \[aq]/\[aq] in the argument and it does not+exist then cblrpm will try to unpack the package and use its .cabal+file.+cblrpm uses a temporary directory for unpackaging tarballs or packages.+cblrpm then parses the .cabal file and uses it to generate a .spec file+that can be built.+.PP+If a .spec already exists, cblrpm outputs to .spec.cblrpm instead.+.SH OPTIONS+.TP+.B \-h, \-\-help+Show the help text.+.RS+.RE+.TP+.B \-b, \-\-binary+Force the base package name to be the Hackage package name.+.RS+.RE+.TP+.B \-f \f[I]FLAGS\f[], \-\-flags=\f[I]FLAGS\f[]+Override one or more Cabal build configuration flags.+.RS+.RE+.TP+.B \-\-release=\f[I]RELEASE\f[]+Override the release number in the .spec file.+.RS+.RE+.TP+.B \-v \f[I]N\f[], \-\-verbose=\f[I]N\f[]+Set verbosity to \f[I]N\f[].+.RS+.RE+.TP+.B \-\-version=\f[I]VERSION\f[]+Override the version number in the .spec file.+.RS+.RE+.SH EXAMPLES+.PP+Below CMD can be one of: spec, srpm, prep, local, install, diff,+builddep, depends, requires, missingdeps, update+.PP+Do CMD for the package in current directory:+.IP+.nf+\f[C]+cblrpm\ CMD+\f[]+.fi+.PP+Do CMD for package (directory or package name):+.IP+.nf+\f[C]+cblrpm\ CMD\ [package]+\f[]+.fi+.PP+Do CMD for package\-version (directory or package name):+.IP+.nf+\f[C]+cblrpm\ CMD\ [package\-version]+\f[]+.fi+.PP+Do CMD on a .cabal file:+.IP+.nf+\f[C]+cblrpm\ CMD\ path/to/some.cabal+\f[]+.fi+.SH HISTORY+.PP+Cabal\-rpm was originally written by Bryan O\[aq]Sullivan in 2007\-2008+and resurrected by Jens Petersen in 2012 to replace cabal2spec.+.SH SEE ALSO+.PP+<http://github.com/juhp/cabal-rpm/>+.SH AUTHORS+This manpage was written by Jens Petersen.
+ man/cabal-rpm.1.md view
@@ -0,0 +1,81 @@+% CBLRPM(1)+% This manpage was written by Jens Petersen+% 2013-01-21++# NAME+cblrpm - a RPM packaging tool for Haskell Cabal packages++# SYNOPSIS+cblrpm [*options*] spec [*path-or-pkg*]+cblrpm [*options*] local [*path-or-pkg*]+cblrpm [*options*] srpm [*path-or-pkg*]+cblrpm [*options*] prep [*path-or-pkg*]+cblrpm [*options*] builddep [*path-or-pkg*]+cblrpm [*options*] install [*path-or-pkg*]+cblrpm [*options*] depends [*path-or-pkg*]+cblrpm [*options*] requires [*path-or-pkg*]+cblrpm [*options*] missingdeps [*path-or-pkg*]+cblrpm [*options*] diff [*path-or-pkg*]+cblrpm [*options*] update [*path-or-pkg*]++# DESCRIPTION+cblrpm generates RPM packages and .spec files from Haskell Cabal package.++If no *path-or-pkg* is specified, cblrpm looks for a .spec or .cabal file+in the current directory. Otherwise, it will look for *path-or-pkg*. If+the argument is a directory then it will look there for a .spec or .cabal file.+If the argument is a path to a .cabal file then it will use it.+Otherwise if there is no '/' in the argument and it does not exist+then cblrpm will try to unpack the package and use its .cabal file.+cblrpm uses a temporary directory for unpackaging tarballs or packages.+cblrpm then parses the .cabal file and uses it to generate a .spec file+that can be built.++If a <PKG>.spec already exists, cblrpm outputs to <PKG>.spec.cblrpm instead.++# OPTIONS+-h, --help+: Show the help text.++-b, --binary+: Force the base package name to be the Hackage package name.++-f *FLAGS*, --flags=*FLAGS*+: Override one or more Cabal build configuration flags.++--release=*RELEASE*+: Override the release number in the .spec file.++-v *N*, --verbose=*N*+: Set verbosity to *N*.++--version=*VERSION*+: Override the version number in the .spec file.++# EXAMPLES+Below CMD can be one of:+ spec, srpm, prep, local, install, diff, builddep, depends, requires,+ missingdeps, update++Do CMD for the package in current directory:++ cblrpm CMD++Do CMD for package (directory or package name):+ + cblrpm CMD [package]++Do CMD for package-version (directory or package name):++ cblrpm CMD [package-version]++Do CMD on a .cabal file:++ cblrpm CMD path/to/some.cabal++# HISTORY+Cabal-rpm was originally written by Bryan O'Sullivan in 2007-2008+and resurrected by Jens Petersen in 2012 to replace cabal2spec.++# SEE ALSO+<http://github.com/juhp/cabal-rpm/>
− man/cblrpm.1
@@ -1,103 +0,0 @@-.TH "CBLRPM" "1" "2013\-01\-21" "" ""-.SH NAME-.PP-cblrpm \- a RPM packaging tool for Haskell Cabal packages-.SH SYNOPSIS-.PP-cblrpm [\f[I]options\f[]] spec [\f[I]path\-or\-pkg\f[]] cblrpm-[\f[I]options\f[]] local [\f[I]path\-or\-pkg\f[]] cblrpm-[\f[I]options\f[]] srpm [\f[I]path\-or\-pkg\f[]] cblrpm-[\f[I]options\f[]] prep [\f[I]path\-or\-pkg\f[]] cblrpm-[\f[I]options\f[]] builddep [\f[I]path\-or\-pkg\f[]] cblrpm-[\f[I]options\f[]] install [\f[I]path\-or\-pkg\f[]] cblrpm-[\f[I]options\f[]] depends [\f[I]path\-or\-pkg\f[]] cblrpm-[\f[I]options\f[]] requires [\f[I]path\-or\-pkg\f[]] cblrpm-[\f[I]options\f[]] missingdeps [\f[I]path\-or\-pkg\f[]] cblrpm-[\f[I]options\f[]] diff [\f[I]path\-or\-pkg\f[]] cblrpm-[\f[I]options\f[]] update [\f[I]path\-or\-pkg\f[]]-.SH DESCRIPTION-.PP-cblrpm generates RPM packages and .spec files from Haskell Cabal-package.-.PP-If no \f[I]path\-or\-pkg\f[] is specified, cblrpm looks for a .spec or-.cabal file in the current directory.-Otherwise, it will look for \f[I]path\-or\-pkg\f[].-If the argument is a directory then it will look there for a .spec or-.cabal file.-If the argument is a path to a .cabal file then it will use it.-Otherwise if there is no \[aq]/\[aq] in the argument and it does not-exist then cblrpm will try to unpack the package and use its .cabal-file.-cblrpm uses a temporary directory for unpackaging tarballs or packages.-cblrpm then parses the .cabal file and uses it to generate a .spec file-that can be built.-.PP-If a .spec already exists, cblrpm outputs to .spec.cblrpm instead.-.SH OPTIONS-.TP-.B \-h, \-\-help-Show the help text.-.RS-.RE-.TP-.B \-b, \-\-binary-Force the base package name to be the Hackage package name.-.RS-.RE-.PP-\-f \f[I]FLAGS\f[], \-\-flags=\f[I]FLAGS\f[] : Override one or more-Cabal build configuration flags.-.PP-\-\-release=\f[I]RELEASE\f[] : Override the release number in the .spec-file.-.PP-\-v \f[I]N\f[], \-\-verbose=\f[I]N\f[] : Set verbosity to \f[I]N\f[].-.PP-\-\-version=\f[I]VERSION\f[] : Override the version number in the .spec-file.-.SH EXAMPLES-.PP-Below CMD can be one of: spec, srpm, prep, local, install, diff,-builddep, depends, requires, missingdeps, update-.PP-Do CMD for the package in current directory:-.IP-.nf-\f[C]-cblrpm\ CMD-\f[]-.fi-.PP-Do CMD for package (directory or package name):-.IP-.nf-\f[C]-cblrpm\ CMD\ [package]-\f[]-.fi-.PP-Do CMD for package\-version (directory or package name):-.IP-.nf-\f[C]-cblrpm\ CMD\ [package\-version]-\f[]-.fi-.PP-Do CMD on a .cabal file:-.IP-.nf-\f[C]-cblrpm\ CMD\ path/to/some.cabal-\f[]-.fi-.SH HISTORY-.PP-Cabal\-rpm was originally written by Bryan O\[aq]Sullivan in 2007\-2008-and resurrected by Jens Petersen in 2012 to replace cabal2spec.-.SH SEE ALSO-.PP-<http://github.com/juhp/cabal-rpm/>-.SH AUTHORS-This manpage was written by Jens Petersen.
− man/cblrpm.1.md
@@ -1,81 +0,0 @@-% CBLRPM(1)-% This manpage was written by Jens Petersen-% 2013-01-21--# NAME-cblrpm - a RPM packaging tool for Haskell Cabal packages--# SYNOPSIS-cblrpm [*options*] spec [*path-or-pkg*]-cblrpm [*options*] local [*path-or-pkg*]-cblrpm [*options*] srpm [*path-or-pkg*]-cblrpm [*options*] prep [*path-or-pkg*]-cblrpm [*options*] builddep [*path-or-pkg*]-cblrpm [*options*] install [*path-or-pkg*]-cblrpm [*options*] depends [*path-or-pkg*]-cblrpm [*options*] requires [*path-or-pkg*]-cblrpm [*options*] missingdeps [*path-or-pkg*]-cblrpm [*options*] diff [*path-or-pkg*]-cblrpm [*options*] update [*path-or-pkg*]--# DESCRIPTION-cblrpm generates RPM packages and .spec files from Haskell Cabal package.--If no *path-or-pkg* is specified, cblrpm looks for a .spec or .cabal file-in the current directory. Otherwise, it will look for *path-or-pkg*. If-the argument is a directory then it will look there for a .spec or .cabal file.-If the argument is a path to a .cabal file then it will use it.-Otherwise if there is no '/' in the argument and it does not exist-then cblrpm will try to unpack the package and use its .cabal file.-cblrpm uses a temporary directory for unpackaging tarballs or packages.-cblrpm then parses the .cabal file and uses it to generate a .spec file-that can be built.--If a <PKG>.spec already exists, cblrpm outputs to <PKG>.spec.cblrpm instead.--# OPTIONS--h, --help-: Show the help text.---b, --binary-: Force the base package name to be the Hackage package name.---f *FLAGS*, --flags=*FLAGS*-: Override one or more Cabal build configuration flags.----release=*RELEASE*-: Override the release number in the .spec file.---v *N*, --verbose=*N*-: Set verbosity to *N*.----version=*VERSION*-: Override the version number in the .spec file.--# EXAMPLES-Below CMD can be one of:- spec, srpm, prep, local, install, diff, builddep, depends, requires,- missingdeps, update--Do CMD for the package in current directory:-- cblrpm CMD--Do CMD for package (directory or package name):- - cblrpm CMD [package]--Do CMD for package-version (directory or package name):-- cblrpm CMD [package-version]--Do CMD on a .cabal file:-- cblrpm CMD path/to/some.cabal--# HISTORY-Cabal-rpm was originally written by Bryan O'Sullivan in 2007-2008-and resurrected by Jens Petersen in 2012 to replace cabal2spec.--# SEE ALSO-<http://github.com/juhp/cabal-rpm/>
src/Commands/Depends.hs view
@@ -39,7 +39,7 @@ let pkgcfgs' = map (++ ".pc") pkgcfgs mapM_ putStrLn $ deps ++ tools ++ clibs' ++ pkgcfgs' Requires -> do- (deps, tools, clibs, pkgcfgs, _) <- packageDependencies pkgDesc+ (deps, tools, clibs, pkgcfgs, _) <- packageDependencies False pkgDesc mapM_ putStrLn $ sort $ deps ++ tools ++ clibs ++ pkgcfgs Missing -> do miss <- missingPackages pkgDesc >>= filterM notAvail
+ src/Commands/Refresh.hs view
@@ -0,0 +1,44 @@+-- |+-- Module : Commands.Refresh+-- Copyright : (C) 2016 Jens Petersen+--+-- Maintainer : Jens Petersen <petersen@fedoraproject.org>+--+-- Explanation: refresh spec file to newer cabal-rpm++-- This program is free software: you can redistribute it and/or modify+-- it under the terms of the GNU General Public License as published by+-- the Free Software Foundation, either version 3 of the License, or+-- (at your option) any later version.++module Commands.Refresh (+ refresh+ ) where++import Commands.Spec (createSpecFile)+import PackageUtils (PackageData (..))+import Setup (RpmFlags (..))+import SysCmd (cmd_, shell, (+-+))++import Distribution.Simple.Utils (die)++refresh :: PackageData -> RpmFlags -> IO ()+refresh pkgdata flags =+ case specFilename pkgdata of+ Nothing -> die "No (unique) .spec file in directory."+ Just spec -> do+ -- FIXME: later this should read the cabal-rpm version header line+ oldspec <- createOldSpec "0.9.6" spec+ newspec <- createSpecFile pkgdata flags Nothing+ shell $ "diff -u2 -I \"- spec file generated by cabal-rpm\" -I \"Fedora Haskell SIG <haskell@lists.fedoraproject.org>\"" +-+ oldspec +-+ newspec +-+ "| sed -e 's/.cblrpm//' | patch" +-+ "|| :"+-- setCurrentDirectory cwd+-- when rwGit $+-- cmd_ "git" ["commit", "-a", "-m", "update to" +-+ newver]+ where+ createOldSpec :: String -> String -> IO FilePath+ createOldSpec crVer spec = do+ cmd_ ("cabal-rpm-" ++ crVer) ["spec"]+ let backup = spec ++ ".cblrpm"+ backup' = backup ++ "-" ++ crVer+ cmd_ "mv" [backup, backup']+ return backup'
src/Commands/RpmBuild.hs view
@@ -33,7 +33,7 @@ --import Distribution.Version (VersionRange, foldVersionRange') -import System.Directory (doesFileExist)+import System.Directory (copyFile, doesFileExist) import System.FilePath (takeDirectory, (</>)) -- autoreconf :: Verbosity -> PackageDescription -> IO ()@@ -75,6 +75,14 @@ error "No tarball for source repo" copyTarball name version False srcdir++ let revision = maybe (0::Int) read (lookup "x-revision" (customFieldsPD pkgDesc))+ cabalFile = srcdir </> show revision ++ ".cabal"++ cabalFileExists <- doesFileExist cabalFile+ unless cabalFileExists $+ copyFile cabalPath cabalFile+ rpmbuild stage False Nothing specFile return specFile
src/Commands/Spec.hs view
@@ -17,19 +17,21 @@ -- (at your option) any later version. module Commands.Spec (- createSpecFile, createSpecFile_, detectDistro, Distro(..)+ createSpecFile, createSpecFile_ ) where import Dependencies (notInstalled, packageDependencies, showDep, testsuiteDependencies)+import Distro (Distro(..), detectDistro) import PackageUtils (getPkgName, isScmDir, PackageData (..), packageName, packageVersion) import Setup (RpmFlags (..))-import SysCmd ((+-+), cmd)+import SysCmd ((+-+)) +import Control.Applicative ((<$>)) import Control.Monad (filterM, unless, void, when) import Data.Char (toLower, toUpper)-import Data.List (groupBy, intercalate, isPrefixOf, isSuffixOf,+import Data.List (groupBy, intercalate, intersect, isPrefixOf, isSuffixOf, sort, (\\)) import Data.Maybe (fromMaybe) import Data.Time.Clock (getCurrentTime)@@ -46,7 +48,7 @@ --import Distribution.Version (VersionRange, foldVersionRange') -import System.Directory (doesFileExist, getDirectoryContents)+import System.Directory (copyFile, doesFileExist, getDirectoryContents) import System.IO (IOMode (..), hClose, hPutStrLn, openFile) #if defined(MIN_VERSION_time) && MIN_VERSION_time(1,5,0) import Data.Time.Format (defaultTimeLocale)@@ -91,7 +93,7 @@ hasExecPkg = binlib || (hasExec && not hasLib) -- run commands before opening file to prevent empty file on error -- maybe shell commands should be in a monad or something- (deps, tools, clibs, pkgcfgs, selfdep) <- packageDependencies pkgDesc+ (deps, tools, clibs, pkgcfgs, selfdep) <- packageDependencies (rpmStrict flags) pkgDesc let testsuiteDeps = testsuiteDependencies pkgDesc name missTestDeps <- filterM notInstalled testsuiteDeps @@ -113,7 +115,8 @@ ghcPkg = if binlib then "-n ghc-%{name}" else "" ghcPkgDevel = if binlib then "-n ghc-%{name}-devel" else "devel" - distro <- detectDistro+ put $ "# generated by cabal-rpm-" ++ showVersion Paths_cabal_rpm.version+ distro <- fromMaybe detectDistro (return <$> rpmDistribution flags) if distro /= SUSE then put "# https://fedoraproject.org/wiki/Packaging:Haskell" else do@@ -180,6 +183,7 @@ defRelease <- defaultRelease cabalPath distro let version = packageVersion pkg release = fromMaybe defRelease (rpmRelease flags)+ revision = show $ maybe (0::Int) read (lookup "x-revision" (customFieldsPD pkgDesc)) putHdr "Name" (if binlib then "%{pkg_name}" else basename) putHdr "Version" version putHdr "Release" $ release ++ (if distro == SUSE then [] else "%{?dist}")@@ -194,6 +198,10 @@ putHdr "License" $ (showLicense distro . license) pkgDesc putHdr "Url" $ "https://hackage.haskell.org/package/" ++ pkg_name putHdr "Source0" $ "https://hackage.haskell.org/package/" ++ pkg_name ++ "-%{version}/" ++ pkg_name ++ "-%{version}.tar.gz"+ when (revision /= "0") $+ if distro == SUSE+ then putHdr "Source1" $ "https://hackage.haskell.org/package/" ++ pkg_name ++ "-%{version}/revision/" ++ revision ++ ".cabal"+ else putStrLn "Warning: this is a revised .cabal file" case distro of Fedora -> return () _ -> putHdr "BuildRoot" "%{_tmppath}/%{name}-%{version}-build"@@ -207,7 +215,8 @@ unless (null $ alldeps ++ extraTestDeps) $ do put "# Begin cabal-rpm deps:" mapM_ (putHdr "BuildRequires") alldeps- when (distro /= SUSE &&+ -- for ghc < 7.8+ when (distro `notElem` [Fedora, SUSE] && any (\ d -> d `elem` map showDep ["template-haskell", "hamlet"]) deps) $ putHdr "ExclusiveArch" "%{ghc_arches_with_ghci}" unless (null extraTestDeps) $ do@@ -250,7 +259,7 @@ putHdr "Requires" $ (if binlib then "ghc-%{name}" else "%{name}") ++ isa +-+ "= %{version}-%{release}" unless (null $ clibs ++ pkgcfgs) $ do put "# Begin cabal-rpm deps:"- mapM_ (putHdr "Requires") $ sort $ map (++ isa) clibs ++ pkgcfgs+ mapM_ (putHdr "Requires") $ sort $ map (++ isa) clibs ++ pkgcfgs ++ ["pkgconfig" | distro == SUSE, not $ null pkgcfgs] put "# End cabal-rpm deps" putNewline put $ "%description" +-+ ghcPkgDevel@@ -259,6 +268,12 @@ put "%prep" put $ "%setup -q" ++ (if pkgname /= name then " -n %{pkg_name}-%{version}" else "")+ when (distro == SUSE && revision /= "0") $ do+ let revised = revision ++ ".cabal"+ put $ "cp -p %{SOURCE1}" +-+ pkg_name ++ ".cabal"+ copied <- doesFileExist revised+ unless copied $+ copyFile cabalPath revised putNewline putNewline @@ -289,14 +304,22 @@ 1 -> head licensefiles _ -> "{" ++ intercalate "," licensefiles ++ "}" + -- remove docs from datafiles (#38)+ docs <- sort <$> findDocs cabalPath licensefiles+ let datafiles = dataFiles pkgDesc+ dupdocs = docs `intersect` datafiles+ unless (null dupdocs) $+ put $ "rm %{buildroot}%{_datadir}/" ++ pkg_name ++ "-%{version}/" +++ case length dupdocs of+ 1 -> head dupdocs+ _ -> "{" ++ intercalate "," dupdocs ++ "}"+ putNewline putNewline unless (null testsuiteDeps) $ do put "%check"- put "%if %{with tests}"- put "%cabal test"- put "%endif"+ put "%cabal_test" putNewline putNewline @@ -310,8 +333,6 @@ put $ "%postun" +-+ ghcPkgDevel putInstallScript - docs <- findDocs cabalPath licensefiles- let license_macro = if distro == Fedora then "%license" else "%doc" when hasExecPkg $ do@@ -324,8 +345,8 @@ put $ "%doc" +-+ unwords docs mapM_ (\ p -> put $ "%{_bindir}/" ++ (if p == name then "%{name}" else p)) execs- unless (null (dataFiles pkgDesc)) $- put "%{_datadir}/%{name}-%{version}"+ unless (null datafiles) $+ put $ "%{_datadir}/" ++ pkg_name ++ "-%{version}" putNewline putNewline@@ -336,16 +357,17 @@ put $ "%files" +-+ ghcPkg +-+ baseFiles when (distro /= Fedora) $ put "%defattr(-,root,root,-)" mapM_ (\ l -> put $ license_macro +-+ l) licensefiles- -- be strict for now--- unless (null (dataFiles pkgDesc) || binlib) $--- put "%{_datadir}/%{pkg_name}-%{version}"+ when (not binlib && distro == SUSE) $+ mapM_ (\ p -> put $ "%{_bindir}/" ++ (if p == name then "%{pkg_name}" else p)) execs+ unless (null datafiles || binlib) $+ put $ "%{_datadir}/" ++ pkg_name ++ "-%{version}" putNewline putNewline put $ "%files" +-+ ghcPkgDevel +-+ develFiles when (distro /= Fedora) $ put "%defattr(-,root,root,-)" unless (null docs) $ put $ "%doc" +-+ unwords docs- unless binlib $+ when (not binlib && distro /= SUSE) $ mapM_ (\ p -> put $ "%{_bindir}/" ++ (if p == name then "%{pkg_name}" else p)) execs putNewline putNewline@@ -374,8 +396,8 @@ return $ if null licensefiles then docs else filter unlikely $ filter (`notElem` licensefiles) docs- where names = ["author", "copying", "doc", "example", "licence", "license",- "readme", "todo"]+ where names = ["author", "changelog", "changes", "copying", "doc", "example", "licence",+ "license", "news", "readme", "todo"] likely name = let lowerName = map toLower name in any (`isPrefixOf` lowerName) names unlikely name = not $ any (`isSuffixOf` name) ["~"]@@ -411,6 +433,7 @@ showLicense _ (AGPL (Just ver)) = "AGPLv" ++ showVersion ver #endif #if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(1,20,0)+showLicense SUSE BSD2 = "BSD-2-Clause" showLicense _ BSD2 = "BSD" showLicense _ (MPL ver) = "MPLv" ++ showVersion ver #endif@@ -419,11 +442,6 @@ showLicense _ UnspecifiedLicense = "Unspecified license!" #endif --- from http://stackoverflow.com/questions/930675/functional-paragraphs--- using split would be: map unlines . (Data.List.Split.splitWhen null)-paragraphs :: [String] -> [String]-paragraphs = map (unlines . filter (not . null)) . groupBy (const $ not . null)- -- http://rosettacode.org/wiki/Word_wrap#Haskell wordwrap :: Int -> String -> String wordwrap maxlen = wrap_ 0 False . words@@ -441,15 +459,8 @@ formatParagraphs :: String -> [String] formatParagraphs = map (wordwrap 79) . paragraphs . lines--data Distro = Fedora | RHEL5 | SUSE deriving (Eq)---- for now assume Fedora if no /etc/SuSE-release-detectDistro :: IO Distro-detectDistro = do- suse <- doesFileExist "/etc/SuSE-release"- if suse then return SUSE- else do- dist <- cmd "rpm" ["--eval", "%{?dist}"]- -- RHEL5 does not have macros.dist- return $ if null dist || dist == ".el5" then RHEL5 else Fedora+ where+ -- from http://stackoverflow.com/questions/930675/functional-paragraphs+ -- using split would be: map unlines . (Data.List.Split.splitWhen null)+ paragraphs :: [String] -> [String]+ paragraphs = map (unlines . filter (not . null)) . groupBy (const $ not . null)
src/Commands/Update.hs view
@@ -16,17 +16,18 @@ update ) where -import Commands.Spec (createSpecFile, detectDistro, Distro(..))+import Commands.Spec (createSpecFile)+import Distro (detectDistro, Distro(..)) import FileUtils (withTempDirectory) import PackageUtils (PackageData (..), bringTarball, isGitDir, latestPkg, packageName, packageVersion, prepare, removePrefix) import Setup (RpmFlags (..))-import SysCmd (cmd_, cmdBool, shell, (+-+))-+import SysCmd (cmd_, cmdBool, cmdIgnoreErr, (+-+))+import Control.Applicative ((<$>)) import Control.Monad (when) import Distribution.PackageDescription (PackageDescription (..)) import Distribution.Simple.Utils (die)- +import Data.Maybe (fromMaybe) import System.Directory (createDirectory, getCurrentDirectory, setCurrentDirectory) @@ -51,9 +52,12 @@ withTempDirectory $ \cwd -> do curspec <- createSpecVersion current spec newspec <- createSpecVersion latest spec- shell $ "diff -u1 -I \"- spec file generated by cabal-rpm\" -I \"Fedora Haskell SIG <haskell@lists.fedoraproject.org>\"" +-+ curspec +-+ newspec +-+ "| patch -d" +-+ cwd +-+ "-p1" +-+ "|| :"+ patch <- cmdIgnoreErr "diff" ["-u2", "-I - spec file generated by cabal-rpm", "-I Fedora Haskell SIG <haskell@lists.fedoraproject.org>", curspec, newspec] ""+ putStrLn patch+ out <- cmdIgnoreErr "patch" ["-d", cwd, "-p1" ] patch+ putStrLn out setCurrentDirectory cwd- distro <- detectDistro+ distro <- fromMaybe detectDistro (return <$> rpmDistribution flags) let suffix = if distro == SUSE then "" else "%{?dist}" cmd_ "sed" ["-i", "-e s/^\\(Release: \\).*/\\10" ++ suffix ++ "/", spec] let newver = removePrefix (name ++ "-") latest
src/Dependencies.hs view
@@ -26,10 +26,10 @@ import SysCmd (cmd, cmdBool, repoquery, (+-+)) import Control.Applicative ((<$>))-import Control.Monad (filterM)+import Control.Monad (filterM, when) import Data.List (delete, nub)-import Data.Maybe (catMaybes)+import Data.Maybe (catMaybes, isNothing) import Distribution.Package (Dependency (..), PackageName (..)) import Distribution.PackageDescription (PackageDescription (..),@@ -103,10 +103,11 @@ warning :: String -> IO () warning s = hPutStrLn stderr $ "Warning:" +-+ s -packageDependencies :: PackageDescription -- ^pkg description+packageDependencies :: Bool -- ^strict mode: True means abort on unknown dependencies+ -> PackageDescription -- ^pkg description -> IO ([String], [String], [String], [String], Bool) -- ^depends, tools, c-libs, pkgcfg, selfdep-packageDependencies pkgDesc = do+packageDependencies strict pkgDesc = do (deps, tools', clibs', pkgcfgs, selfdep) <- dependencies pkgDesc let excludedTools n = n `notElem` ["ghc", "hsc2hs", "perl"] mapTools "gtk2hsC2hs" = "gtk2hs-buildtools"@@ -115,7 +116,12 @@ mapTools tool = tool chrpath = ["chrpath" | selfdep] tools = filter excludedTools $ nub $ map mapTools tools' ++ chrpath- clibs <- catMaybes <$> mapM resolveLib clibs'+ clibsWithErrors <- mapM resolveLib clibs'+ when (any isNothing clibsWithErrors) $+ if strict+ then fail "cannot resolve all clib dependencies"+ else putStrLn "Warning: could not resolve all clib dependencies"+ let clibs = catMaybes clibsWithErrors let showPkgCfg p = "pkgconfig(" ++ p ++ ")" return (map showDep deps, tools, nub clibs, map showPkgCfg pkgcfgs, selfdep) @@ -127,7 +133,7 @@ missingPackages :: PackageDescription -> IO [String] missingPackages pkgDesc = do- (deps, tools, clibs, pkgcfgs, _) <- packageDependencies pkgDesc+ (deps, tools, clibs, pkgcfgs, _) <- packageDependencies False pkgDesc pcpkgs <- mapM derefPkg pkgcfgs filterM notInstalled $ deps ++ ["ghc-Cabal-devel", "ghc-rpm-macros"] ++ tools ++ clibs ++ pcpkgs
+ src/Distro.hs view
@@ -0,0 +1,42 @@+-- |+-- Module : Distro+-- Copyright : (C) 2016 Jens Petersen+--+-- Maintainer : Jens Petersen <petersen@fedoraproject.org>+--+-- Types and utility functions to represent different RPM-based distributions.++-- This program is free software: you can redistribute it and/or modify+-- it under the terms of the GNU General Public License as published by+-- the Free Software Foundation, either version 3 of the License, or+-- (at your option) any later version.++module Distro (+ detectDistro, parseDistroName, readDistroName, Distro(..)+ ) where++import SysCmd (cmd)+import Data.Maybe (fromMaybe)+import Data.Char (toLower)++data Distro = Fedora | RHEL5 | SUSE deriving (Show, Eq)++detectDistro :: IO Distro+detectDistro = do+ suseVersion <- cmd "rpm" ["--eval", "%{?suse_version}"]+ if null suseVersion then do+ dist <- cmd "rpm" ["--eval", "%{?dist}"]+ -- RHEL5 does not have macros.dist+ return $ if null dist || dist == ".el5" then RHEL5 else Fedora+ else return SUSE++parseDistroName :: String -> Maybe Distro+parseDistroName x = lookup (map toLower x) known+ where+ known = [ ("suse", SUSE)+ , ("fedora", Fedora)+ , ("rhel5", RHEL5)+ ]++readDistroName :: String -> Distro+readDistroName s = fromMaybe (error $ "unrecognized distribution name " ++ show s) (parseDistroName s)
src/Main.hs view
@@ -19,6 +19,7 @@ import Commands.Depends (depends, Depends (..)) import Commands.Diff (diff) import Commands.Install (install)+import Commands.Refresh (refresh) import Commands.RpmBuild (rpmBuild_) import Commands.Spec (createSpecFile_) import Commands.Update (update)@@ -46,6 +47,7 @@ "diff" -> diff pkgdata opts "install" -> install pkgdata opts "depends" -> depends pkgdata Depends+ "refresh" -> refresh pkgdata opts "requires" -> depends pkgdata Requires "missingdeps" -> depends pkgdata Missing "update" -> update pkgdata opts
src/PackageUtils.hs view
@@ -45,7 +45,7 @@ import Data.Maybe (fromMaybe, isJust) import Data.Version (showVersion) -import Distribution.Compiler (CompilerFlavor (..))+import Distribution.Compiler import Distribution.Package (PackageIdentifier (..), PackageName (..)) import Distribution.PackageDescription (PackageDescription (..),@@ -96,19 +96,28 @@ simplePackageDescription path opts = do let verbose = rpmVerbosity opts genPkgDesc <- readPackageDescription verbose path+ compiler <- case rpmCompilerId opts of+ Just cid -> return+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(1,22,0)+ (unknownCompilerInfo cid NoAbiTag)+#else+ cid+#endif+ Nothing -> do #if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(1,18,0)- (compiler, _, _) <- configCompilerEx+ (compiler, _, _) <- configCompilerEx #else- (compiler, _) <- configCompiler+ (compiler, _) <- configCompiler #endif- (Just GHC) Nothing Nothing defaultProgramConfiguration verbose- case finalizePackageDescription (rpmConfigurationsFlags opts)- (const True) (Platform buildArch buildOS)+ (Just GHC) Nothing Nothing defaultProgramConfiguration verbose #if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(1,22,0)- (compilerInfo compiler)+ return (compilerInfo compiler) #else- (compilerId compiler)+ return (compilerId compiler) #endif+ case finalizePackageDescription (rpmConfigurationsFlags opts)+ (const True) (Platform buildArch buildOS)+ compiler [] genPkgDesc of Left e -> die $ "finalize failed: " ++ show e Right (pd, _) -> return pd@@ -215,7 +224,7 @@ cmd_ "cabal" ["unpack", "-v0", pkgver] pth <- findPackageDesc' pkgver setCurrentDirectory cwd- return (tmpdir ++ "/" ++ pth, Just tmpdir)+ return (tmpdir </> pth, Just tmpdir) latestPkg :: String -> IO String latestPkg pkg = do
src/Setup.hs view
@@ -23,9 +23,11 @@ import Control.Monad (unless, when) import Data.Char (toLower)-import Data.Maybe (listToMaybe)+import Data.Maybe (listToMaybe, fromMaybe) import Data.Version (showVersion) +import Distribution.Compiler (CompilerId)+import Distribution.Text (simpleParse) import Distribution.PackageDescription (FlagName (..)) import Distribution.ReadE (readEOrFail) import Distribution.Verbosity (Verbosity, flagToVerbosity, normal,@@ -37,6 +39,7 @@ import System.Exit (ExitCode (..), exitSuccess, exitWith) import System.IO (Handle, hPutStrLn, stderr, stdout) +import Distro (Distro(..), readDistroName) import Paths_cabal_rpm (version) import SysCmd ((+-+)) @@ -45,7 +48,10 @@ , rpmForce :: Bool , rpmHelp :: Bool , rpmBinary :: Bool+ , rpmStrict :: Bool , rpmRelease :: Maybe String+ , rpmCompilerId :: Maybe CompilerId+ , rpmDistribution :: Maybe Distro , rpmVerbosity :: Verbosity , rpmVersion :: Bool }@@ -57,7 +63,10 @@ , rpmForce = False , rpmHelp = False , rpmBinary = False+ , rpmStrict = False , rpmRelease = Nothing+ , rpmCompilerId = Nothing+ , rpmDistribution = Nothing , rpmVerbosity = normal , rpmVersion = False }@@ -76,8 +85,14 @@ "Set given flags in Cabal conditionals", Option "" ["force"] (NoArg (\x -> x { rpmForce = True })) "Overwrite existing spec file.",+ Option "" ["strict"] (NoArg (\x -> x { rpmStrict = True }))+ "Fail rather than produce an incomplete spec file.", Option "" ["release"] (ReqArg (\rel x -> x { rpmRelease = Just rel }) "RELEASE") "Override the default package release",+ Option "" ["compiler"] (ReqArg (\cid x -> x { rpmCompilerId = Just (parseCompilerId cid) }) "COMPILER-ID")+ "Finalize Cabal files targetting the given compiler version",+ Option "" ["distro"] (ReqArg (\did x -> x { rpmDistribution = Just (readDistroName did) }) "DISTRO")+ "Choose the distribution generated spec files will target", Option "v" ["verbose"] (ReqArg (\verb x -> x { rpmVerbosity = readEOrFail flagToVerbosity verb }) "n") "Change build verbosity", Option "V" ["version"] (NoArg (\x -> x { rpmVersion = True }))@@ -114,6 +129,10 @@ ++ "Options:" hPutStrLn h (usageInfo info options) +parseCompilerId :: String -> CompilerId+parseCompilerId x = fromMaybe err (simpleParse x)+ where err = error (show x ++ " is not a valid compiler id")+ parseArgs :: [String] -> IO (RpmFlags, String, Maybe String) parseArgs args = do let (os, args', unknown, errs) = getOpt' Permute options args@@ -128,7 +147,11 @@ error $ unlines errs unless (null unknown) $ error $ "Unrecognised options:" +-+ unwords unknown- when (null args' || notElem (head args') ["builddep", "depends", "diff", "install", "missingdeps", "prep", "requires", "spec", "srpm", "build", "local", "rpm", "update"]) $ do+ when (null args') $ do+ printHelp stderr+ exitWith (ExitFailure 1)+ when (head args' `notElem` ["builddep", "depends", "diff", "install", "missingdeps", "prep", "requires", "spec", "srpm", "build", "local", "rpm", "update", "refresh"]) $ do+ hPutStrLn stderr $ "Unknown command:" +-+ head args' printHelp stderr exitWith (ExitFailure 1) when (length args' > 2) $
src/SysCmd.hs view
@@ -18,6 +18,7 @@ cmd, cmd_, cmdBool,+ cmdIgnoreErr, cmdQuiet, cmdSilent, pkgInstall,@@ -122,6 +123,11 @@ cmd c args = do requireProgram c removeTrailingNewline <$> readProcess c args ""++cmdIgnoreErr :: FilePath -> [String] -> String -> IO String+cmdIgnoreErr c args input = do+ (_exit, out, _err) <- readProcessWithExitCode c args input+ return out removeTrailingNewline :: String -> String removeTrailingNewline "" = ""