cabal-rpm 0.7.1 → 0.8.0
raw patch · 7 files changed
+166/−82 lines, 7 files
Files
- NEWS +13/−4
- cabal-rpm.cabal +6/−2
- man/cblrpm.1 +5/−5
- man/cblrpm.1.md +5/−5
- src/Distribution/Package/Rpm.hs +55/−59
- src/Distribution/Package/Rpm/Main.hs +8/−7
- src/Distribution/Package/Rpm/Utils.hs +74/−0
NEWS view
@@ -1,4 +1,13 @@-* 0.7.1+* 0.8.0 (2013-05-31)+- new simplier revision to Fedora Packaging+ - drop %common_summary and %common_description+ - drop %ghc_package, %ghc_description, %ghc_devel_package,+ %ghc_devel_description, %ghc_devel_post_postun, %ghc_files,+ and %ghc_devel_requires+- check external programs available before use+- tweaks for ghc-7.6.3 and Cabal-1.16++* 0.7.1 (2013-03-22) - add final full-stop to description if missing - add ver-rel to initial changelog entry - fix use of cblrpm-diff force lib option@@ -7,7 +16,7 @@ - output when trying a path - map curl C dep to libcurl -* 0.7.0+* 0.7.0 (2013-01-22) - cabal-rpm command renamed to cblrpm, and cabal-rpm-diff to cblrpm-diff - cblrpm now has commands for spec, srpm, and build - cblrpm will try to install packaged uninstalled depends with sudo yum install@@ -17,7 +26,7 @@ - sort extralibs depends - cleanup of unused options and help output -* 0.6.6+* 0.6.6 (2012-11-21) - generate BRs and Req's for C libraries (extra-libraries) - initial map for some C libs: libglut, libiw, libz, libX* - generate BRs and Req's for pkgconfig-depends@@ -27,7 +36,7 @@ - backup suffix changed from .cabal-rpm to .cblrpm - don't mistake non-existent file in cwd for a package -* 0.6.5+* 0.6.5 (2012-11-01) - drop hscolour BuildRequires - simplify generated BuildRequires: drop version ranges for now, exclude pkg self, base libs, and Cabal
cabal-rpm.cabal view
@@ -1,11 +1,13 @@ Name: cabal-rpm-Version: 0.7.1+Version: 0.8.0 Synopsis: RPM package creator for Haskell Cabal-based packages Description: This package generates RPM spec files from Haskell Cabal packages. . Recent changes: .+ * 0.8.0: new simpler revised Fedora packaging; check external commands available+ . * 0.7.1: various bugfixes and minor improvments . * 0.7.0: command arg for spec, srpm, or build; installs existing packaged depends with sudo yum@@ -53,6 +55,8 @@ Other-modules: Distribution.Package.Rpm, Distribution.Package.Rpm.Main,- Distribution.Package.Rpm.Setup+ Distribution.Package.Rpm.Setup,+ Distribution.Package.Rpm.Utils Hs-Source-Dirs: src GHC-options: -fwarn-missing-signatures -Wall+ Extensions: CPP
man/cblrpm.1 view
@@ -59,7 +59,7 @@ .IP .nf \f[C]-cblrpm+cblrpm\ spec \f[] .fi .PP@@ -67,7 +67,7 @@ .IP .nf \f[C]-cblrpm\ [package]+cblrpm\ spec\ [package] \f[] .fi .PP@@ -75,7 +75,7 @@ .IP .nf \f[C]-cblrpm\ [package\-version]+cblrpm\ spec\ [package\-version] \f[] .fi .PP@@ -83,7 +83,7 @@ .IP .nf \f[C]-cblrpm\ path/to/some.cabal+cblrpm\ spec\ path/to/some.cabal \f[] .fi .PP@@ -91,7 +91,7 @@ .IP .nf \f[C]-cblrpm\ path/to/pkg\-ver.tar.gz+cblrpm\ spec\ path/to/pkg\-ver.tar.gz \f[] .fi .SH HISTORY
man/cblrpm.1.md view
@@ -51,23 +51,23 @@ # EXAMPLES Create a .spec file for the Cabal src package in current directory: - cblrpm+ cblrpm spec Create a .spec file for package (directory or package name): - cblrpm [package]+ cblrpm spec [package] Create a .spec file for package-version (directory or package name): - cblrpm [package-version]+ cblrpm spec [package-version] Create a .spec file for a .cabal file: - cblrpm path/to/some.cabal+ cblrpm spec path/to/some.cabal Create a .spec file from a tarball: - cblrpm path/to/pkg-ver.tar.gz+ cblrpm spec path/to/pkg-ver.tar.gz # HISTORY Cabal-rpm was originally written by Bryan O'Sullivan in 2007-2008
src/Distribution/Package/Rpm.hs view
@@ -21,7 +21,7 @@ --import Control.Exception (bracket) import Control.Monad (unless, void, when) import Data.Char (toLower)-import Data.List (intercalate, isPrefixOf, isSuffixOf, nub, sort)+import Data.List (isPrefixOf, isSuffixOf, nub, sort) import Data.Maybe (fromMaybe) import Data.Time.Clock (UTCTime, getCurrentTime) import Data.Time.Format (formatTime)@@ -31,16 +31,16 @@ import Distribution.Package (Dependency (..), PackageIdentifier (..), PackageName (..)) -import Distribution.Simple.Utils (die, warn)+import Distribution.Simple.Utils (warn) import Distribution.PackageDescription (PackageDescription (..), exeName, hasExes, hasLibs, withExe, allBuildInfo, BuildInfo (..)) -import Distribution.Verbosity (normal) --import Distribution.Version (VersionRange, foldVersionRange') import Distribution.Package.Rpm.Setup (RpmFlags (..))+import Distribution.Package.Rpm.Utils (trySystem, optionalSudo, (+-+)) import System.Cmd (system) import System.Directory (doesDirectoryExist, doesFileExist,@@ -55,11 +55,6 @@ import qualified Paths_cabal_rpm (version) -(+-+) :: String -> String -> String-"" +-+ s = s-s +-+ "" = s-s +-+ t = s ++ " " ++ t- -- autoreconf :: Verbosity -> PackageDescription -> IO () -- autoreconf verbose pkgDesc = do -- ac <- doesFileExist "configure.ac"@@ -69,16 +64,16 @@ -- setupMessage verbose "Running autoreconf" pkgDesc -- trySystem "autoreconf" -unlessSystem :: String -> String -> IO ()-unlessSystem tst act = do+unlessSudo :: String -> String -> IO ()+unlessSudo tst act = do ret <- system tst case ret of ExitSuccess -> return ()- ExitFailure _ -> void $ trySystemWarn act+ ExitFailure _ -> void $ optionalSudo act maybeInstall :: String -> IO () maybeInstall pkg = do- unlessSystem ("rpm -q" +-+ pkg) ("sudo yum install" +-+ pkg)+ unlessSudo ("rpm -q" +-+ pkg) ("yum install" +-+ pkg) rpmBuild :: FilePath -> PackageDescription -> RpmFlags -> Bool -> IO () rpmBuild cabalPath pkgDesc flags binary = do@@ -95,7 +90,7 @@ let pkg = package pkgDesc name = packageName pkg when binary $ do- -- trySystem ("sudo yum-builddep" +-+ specFile)+ -- optionalSystem ("sudo yum-builddep" +-+ specFile) mapM_ maybeInstall $ map showDep $ buildDependencies pkgDesc [name] cwd <- getCurrentDirectory home <- getEnv "HOME"@@ -115,20 +110,6 @@ "--define \"_sourcedir" +-+ srcdir ++ "\"" +-+ specFile) -trySystem :: String -> IO ()-trySystem cmd = do- ret <- system cmd- case ret of- ExitSuccess -> return ()- ExitFailure n -> die ("\"" ++ cmd ++ "\"" +-+ "failed with status" +-+ show n)--trySystemWarn :: String -> IO ()-trySystemWarn cmd = do- ret <- system cmd- case ret of- ExitSuccess -> return ()- ExitFailure n -> warn normal ("\"" ++ cmd ++ "\"" +-+ "failed with status" +-+ show n)- defaultRelease :: UTCTime -> IO String defaultRelease now = do darcsRepo <- doesDirectoryExist "_darcs"@@ -183,21 +164,21 @@ specFile = pkgname ++ ".spec" isExec = if (rpmLibrary flags) then False else hasExes pkgDesc isLib = hasLibs pkgDesc+ isBinLib = isExec && isLib specAlreadyExists <- doesFileExist specFile let specFilename = specFile ++ if specAlreadyExists then ".cblrpm" else "" when specAlreadyExists $ putStrLn $ specFile +-+ "exists:" +-+ "creating" +-+ specFilename h <- openFile specFilename WriteMode let putHdr hdr val = hPutStrLn h (hdr ++ ":" ++ padding hdr ++ val)- padding hdr = replicate (15 - length hdr) ' '- putHdr_ hdr val = unless (null val) $ putHdr hdr val- putHdrD hdr val dfl = putHdr hdr (if null val then dfl else val)+ padding hdr = replicate (14 - length hdr) ' ' ++ " " putNewline = hPutStrLn h "" put = hPutStrLn h putDef v s = put $ "%global" +-+ v +-+ s date = formatTime defaultTimeLocale "%a %b %e %Y" now+ ghcPkg = if isBinLib then "-n ghc-%{name}" else ""+ ghcPkgDevel = if isBinLib then "-n ghc-%{name}-devel" else "devel" put "# https://fedoraproject.org/wiki/Packaging:Haskell"- put "# https://fedoraproject.org/wiki/PackagingDrafts/Haskell" putNewline -- Some packages conflate the synopsis and description fields. Ugh.@@ -206,7 +187,7 @@ (x:_) -> return (x, x /= syn) _ -> do warn verbose "This package has no synopsis." return ("Haskell" +-+ name +-+ "package", False)- let common_summary = if synTooLong+ let summary = if synTooLong then syn' +-+ "[...]" else rstrip (== '.') syn' when synTooLong $@@ -222,20 +203,14 @@ when isLib $ do putDef "pkg_name" name putNewline- putDef "common_summary" common_summary- putNewline- putDef "common_description" $ intercalate "\\\n" common_description- putNewline putHdr "Name" (if isExec then (if isLib then "%{pkg_name}" else pkgname) else "ghc-%{pkg_name}") putHdr "Version" version putHdr "Release" $ release ++ "%{?dist}"- if isLib- then putHdr "Summary" "%{common_summary}"- else putHdrD "Summary" common_summary "This package has no summary"+ putHdr "Summary" summary putNewline putHdr "License" $ (showLicense . license) pkgDesc- putHdr_ "URL" $ "http://hackage.haskell.org/package/" ++ pkg_name+ putHdr "URL" $ "http://hackage.haskell.org/package/" ++ pkg_name putHdr "Source0" $ "http://hackage.haskell.org/packages/archive/" ++ pkg_name ++ "/%{version}/" ++ pkg_name ++ "-%{version}.tar.gz" putNewline putHdr "BuildRequires" "ghc-Cabal-devel"@@ -273,10 +248,33 @@ putNewline put "%description"- put $ if isLib then "%{common_description}" else unlines common_description- putNewline+ put $ unlines common_description putNewline + when isLib $ do+ when isExec $ do+ put $ "%package" +-+ ghcPkg+ putHdr "Summary" $ "Haskell" +-+ pkg_name +-+ "library"+ putNewline+ put $ "%description" +-+ ghcPkg+ put $ unlines common_description+ putNewline+ put $ "%package" +-+ ghcPkgDevel+ putHdr "Summary" $ "Haskell" +-+ pkg_name +-+ "library development files"+ putHdr "Requires" "ghc-compiler = %{ghc_version}"+ putHdr "Requires(post)" "ghc-compiler = %{ghc_version}"+ putHdr "Requires(postun)" "ghc-compiler = %{ghc_version}"+ putHdr "Requires" $ (if isExec then "ghc-%{name}" else "%{name}") +-+ "= %{version}-%{release}"+ when (not . null $ clibs ++ pkgcfgs) $ do+ put "# Begin cabal-rpm deps:"+ mapM_ (putHdr "Requires") $ map (++ "-devel%{?_isa}") clibs+ mapM_ (putHdr "Requires") $ map showPkgCfg pkgcfgs+ put "# End cabal-rpm deps"+ putNewline+ put $ "%description" +-+ ghcPkgDevel+ put $ "This package provides the Haskell" +-+ name +-+ "library development files."+ putNewline+ put "%prep" put $ "%setup -q" ++ (if pkgname /= name then " -n %{pkg_name}-%{version}" else "") putNewline@@ -293,25 +291,13 @@ putNewline putNewline - when (isExec && isLib) $ do- put "%ghc_package"- putNewline- put "%ghc_description"- putNewline- putNewline- when isLib $ do- put "%ghc_devel_package"- when (not . null $ clibs ++ pkgcfgs) $ do- put "# Begin cabal-rpm deps:"- mapM_ (putHdr "Requires") $ map (++ "-devel%{?_isa}") clibs- mapM_ (putHdr "Requires") $ map showPkgCfg pkgcfgs- put "# End cabal-rpm deps"- putNewline- put "%ghc_devel_description"+ put $ "%post" +-+ ghcPkgDevel+ put "%ghc_pkg_recache" putNewline putNewline- put "%ghc_devel_post_postun"+ put $ "%postun" +-+ ghcPkgDevel+ put "%ghc_pkg_recache" putNewline putNewline @@ -336,7 +322,13 @@ putNewline when isLib $ do- put $ "%ghc_files" +-+ licenseFile pkgDesc+ let baseFiles = if isBinLib then "-f ghc-%{name}.files" else "-f %{name}.files"+ develFiles = if isBinLib then "-f ghc-%{name}-devel.files" else "-f %{name}-devel.files"+ put $ "%files" +-+ ghcPkg +-+ baseFiles+ put $ "%doc" +-+ licenseFile pkgDesc+ putNewline+ putNewline+ put $ "%files" +-+ ghcPkgDevel +-+ develFiles unless (null docs) $ put $ "%doc" +-+ unwords docs putNewline@@ -373,3 +365,7 @@ showLicense AllRightsReserved = "Proprietary" showLicense OtherLicense = "Unknown" showLicense (UnknownLicense l) = "Unknown" +-+ l+#if MIN_VERSION_Cabal(1,16,0)+showLicense (Apache Nothing) = "ASL ?"+showLicense (Apache (Just ver)) = "ASL" +-+ showVersion ver+#endif
src/Distribution/Package/Rpm/Main.hs view
@@ -17,6 +17,8 @@ import Distribution.Compiler (CompilerFlavor (..)) import Distribution.Package.Rpm (createSpecFile, rpmBuild) import Distribution.Package.Rpm.Setup (RpmFlags (..), parseArgs)+import Distribution.Package.Rpm.Utils (tryReadProcess, trySystem)+ import Distribution.PackageDescription (GenericPackageDescription (..), PackageDescription (..)) import Distribution.PackageDescription.Configuration (finalizePackageDescription)@@ -31,7 +33,6 @@ removeDirectoryRecursive, setCurrentDirectory) import System.Environment (getArgs) import System.FilePath.Posix (takeExtension)-import System.Process (readProcess, system) main :: IO () main = do (opts, args) <- getArgs >>= parseArgs@@ -73,7 +74,7 @@ isdir <- doesDirectoryExist path if isdir then do- putStrLn $ "Trying: " ++ path ++ "/"+ putStrLn $ "Using " ++ path ++ "/" file <- findPackageDesc path return (file, Nothing) else do@@ -88,8 +89,8 @@ else if isSuffixOf ".tar.gz" path then do tmpdir <- mktempdir- _ <- system $ "tar zxf " ++ path ++ " -C " ++ tmpdir ++ " *.cabal"- subdir <- readProcess "ls" [tmpdir] []+ trySystem $ "tar zxf " ++ path ++ " -C " ++ tmpdir ++ " *.cabal"+ subdir <- tryReadProcess "ls" [tmpdir] file <- findPackageDesc $ tmpdir ++ "/" ++ init subdir return (file, Just tmpdir) else error $ path ++ ": file should be a .cabal or .tar.gz file."@@ -98,7 +99,7 @@ tryUnpack pkg = do pkgver <- if elem '.' pkg then return pkg else do- contains_pkg <- readProcess "cabal" ["list", "--simple-output", pkg] []+ contains_pkg <- tryReadProcess "cabal" ["list", "--simple-output", pkg] let pkgs = filter ((== pkg) . fst . break (== ' ')) $ lines contains_pkg return $ map (\c -> if c == ' ' then '-' else c) $ last pkgs isdir <- doesDirectoryExist pkgver@@ -110,12 +111,12 @@ cwd <- getCurrentDirectory tmpdir <- mktempdir setCurrentDirectory tmpdir- _ <- system $ "cabal unpack -v0 " ++ pkgver+ trySystem $ "cabal unpack -v0 " ++ pkgver pth <- findPackageDesc pkgver setCurrentDirectory cwd return (tmpdir ++ "/" ++ pth, Just tmpdir) mktempdir :: IO FilePath mktempdir = do- mktempOut <- readProcess "mktemp" ["-d"] []+ mktempOut <- tryReadProcess "mktemp" ["-d"] return $ init mktempOut
+ src/Distribution/Package/Rpm/Utils.hs view
@@ -0,0 +1,74 @@+-- |+-- Module : Distribution.Package.Rpm.Utils+-- Copyright : Jens Petersen 2013+--+-- Maintainer : Jens Petersen <petersen@fedoraproject.org>+-- Stability : alpha+-- Portability : portable+--+-- Explanation: Command line option processing for building RPM+-- packages.++-- This software may be used and distributed according to the terms of+-- the GNU General Public License, incorporated herein by reference.++module Distribution.Package.Rpm.Utils (+ requireProgram,+ trySystem,+ tryReadProcess,+ optionalSudo,+ (+-+)) where++import Control.Monad (when)+import Data.Maybe (isJust, isNothing)++import Distribution.Simple.Utils (die, warn, findProgramLocation)+import Distribution.Verbosity (normal)++import System.Process (readProcess, system)+import System.Exit (ExitCode(..))++requireProgram :: String -> IO ()+requireProgram cmd = do+ mavail <- findProgramLocation normal cmd+ when (isNothing mavail) $ die (cmd ++ ": command not found")++optionalProgram :: String -> IO Bool+optionalProgram cmd = do+ mavail <- findProgramLocation normal cmd+ when (isNothing mavail) $ warn normal (cmd ++ ": command not found")+ return $ isJust mavail++optionalSudo :: String -> IO ()+optionalSudo cmd = do+ havesudo <- optionalProgram "sudo"+ when havesudo $ do+ let argv = words cmd+ cmd0 = head argv + mavail <- findProgramLocation normal cmd0+ case mavail of+ Nothing -> warn normal $ cmd0 ++ ": command not found"+ Just _ -> do+ ret <- system $ "sudo" +-+ cmd+ case ret of+ ExitSuccess -> return ()+ ExitFailure n -> warn normal ("\"" ++ cmd ++ "\"" +-+ "failed with status" +-+ show n)++trySystem :: String -> IO ()+trySystem cmd = do+ requireProgram $ head $ words cmd+ ret <- system cmd+ case ret of+ ExitSuccess -> return ()+ ExitFailure n -> die ("\"" ++ cmd ++ "\"" +-+ "failed with status" +-+ show n)++tryReadProcess :: FilePath -> [String] -> IO String+tryReadProcess cmd args = do+ requireProgram cmd+ readProcess cmd args []++(+-+) :: String -> String -> String+"" +-+ s = s+s +-+ "" = s+s +-+ t = s ++ " " ++ t+