packages feed

cabal-rpm 0.6.2 → 0.6.3

raw patch · 6 files changed

+223/−20 lines, 6 files

Files

NEWS view
@@ -1,3 +1,8 @@+* 0.6.3 (2012-09-24)+- support tarball path argument+- use a temporary working dir for opening tarball or cabal unpack+- add a manpage+ * 0.6.2 (2012-09-10) - fix output of L/GPL version 
README.md view
@@ -26,6 +26,10 @@      $ cabal-rpm path/to/mypkg.cabal +or tarball:++    $ cabal-rpm path/to/mypkg-version.tar.gz+ or on a package source dir:      $ cabal-rpm mypkg-0.1
cabal-rpm.cabal view
@@ -1,11 +1,13 @@ Name:                cabal-rpm-Version:             0.6.2+Version:             0.6.3 Synopsis:            RPM package creator for Haskell Cabal-based packages Description:     This package generates RPM spec files from Haskell Cabal packages.     .     Recent changes:     .+    * 0.6.3: accept tarball arg, use temporary working directory, and add manpage+    .     * 0.6.2: fix L/GPL version output     .     * 0.6.1: fix bugs for 'cabal-rpm pkg' unpacking and extra docs@@ -21,7 +23,7 @@                      2012 Jens Petersen <petersen@fedoraproject.org> Category:            Distribution Build-type:          Simple-Extra-source-files:  README.md NEWS+Extra-source-files:  README.md NEWS man/cabal-rpm.1.md man/cabal-rpm.1 Cabal-version:       >=1.6  source-repository head
+ man/cabal-rpm.1 view
@@ -0,0 +1,95 @@+.SH NAME+.PP+cabal-rpm - generates RPM .spec files from Cabal packages+.SH SYNOPSIS+.PP+cabal-rpm [\f[I]options\f[]] [\f[I]path-or-pkg\f[]]+.SH DESCRIPTION+.PP+Cabal-rpm generates RPM .spec files from Haskell Cabal package.+.PP+If no \f[I]path-or-pkg\f[] is specified, cabal-rpm looks for a .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 .cabal+file.+If the argument is a path to a .cabal or .tar.gz file then it will use+it.+Otherwise if there is no \[aq]/\[aq] in the argument and it does not+exist then cabal-rpm will try to unpack the package and use its .cabal+file.+Cabal-rpm uses a temporary directory for unpackaging tarballs or+packages.+.PP+Cabal-rpm then parses the above specified .cabal file and uses it to+generate a .spec file that can be built.+.SH OPTIONS+.TP+.B -h+Show the help text.+.RS+.RE+.TP+.B --name \f[I]NAME\f[]+Override the RPM package name to be \f[I]NAME\f[]+.RS+.RE+.PP+-f \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[] : Set verbosity to \f[I]N\f[].+.PP+--version=\f[I]VERSION\f[] : Override the version number in the .spec+file.+.SH EXAMPLES+.PP+Create a .spec file for the Cabal src package in current directory:+.IP+.nf+\f[C]+cabal-rpm+\f[]+.fi+.PP+Create a .spec file for package (directory or package name):+.IP+.nf+\f[C]+cabal-rpm\ [package]+\f[]+.fi+.PP+Create a .spec file for package-version (directory or package name):+.IP+.nf+\f[C]+cabal-rpm\ [package-version]+\f[]+.fi+.PP+Create a .spec file for a .cabal file:+.IP+.nf+\f[C]+cabal-rpm\ path/to/some.cabal+\f[]+.fi+.PP+Create a .spec file from a tarball:+.IP+.nf+\f[C]+cabal-rpm\ path/to/pkg-ver.tar.gz+\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/>
+ man/cabal-rpm.1.md view
@@ -0,0 +1,71 @@+% CABAL-RPM(1)+% Jens Petersen+% 2012-09-24++# NAME+cabal-rpm - generates RPM .spec files from Cabal packages++# SYNOPSIS+cabal-rpm [*options*] [*path-or-pkg*]++# DESCRIPTION+Cabal-rpm generates RPM .spec files from Haskell Cabal package.++If no *path-or-pkg* is specified, cabal-rpm looks for a .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 .cabal file.+If the argument is a path to a .cabal or .tar.gz file then it will use it.+Otherwise if there is no '/' in the argument and it does not exist+then cabal-rpm will try to unpack the package and use its .cabal file.+Cabal-rpm uses a temporary directory for unpackaging tarballs or packages.++Cabal-rpm then parses the above specified .cabal file and+uses it to generate a .spec file that can be built.+++# OPTIONS+-h+:   Show the help text.++--name *NAME*+:   Override the RPM package name to be *NAME*++-f *FLAGS*+: Override one or more Cabal build configuration flags.++--release=*RELEASE*+: Override the release number in the .spec file.++-v *N*+: Set verbosity to *N*.++--version=*VERSION*+: Override the version number in the .spec file.++# EXAMPLES+Create a .spec file for the Cabal src package in current directory:++    cabal-rpm++Create a .spec file for package (directory or package name):+ +    cabal-rpm [package]++Create a .spec file for package-version (directory or package name):++    cabal-rpm [package-version]++Create a .spec file for a .cabal file:++    cabal-rpm path/to/some.cabal++Create a .spec file from a tarball:++    cabal-rpm path/to/pkg-ver.tar.gz++# 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/Distribution/Package/Rpm/Main.hs view
@@ -16,9 +16,11 @@ import Distribution.Package.Rpm (createSpecFile) import Distribution.Package.Rpm.Setup (RpmFlags (..), parseArgs) import Distribution.Simple.Utils (defaultPackageDesc, findPackageDesc)-import Control.Monad (unless, void)+import Control.Monad (void) import Data.Char (isDigit)-import System.Directory (doesDirectoryExist, doesFileExist)+import Data.List (isSuffixOf)+import System.Directory (doesDirectoryExist, doesFileExist, getCurrentDirectory,+                         removeDirectoryRecursive, setCurrentDirectory) import System.Environment (getArgs) import System.FilePath.Posix (takeExtension) import System.Process (readProcess, system)@@ -26,38 +28,62 @@ main :: IO () main = do (opts, args) <- getArgs >>= parseArgs           let verbosity = rpmVerbosity opts-          cabalPath <- if null args then defaultPackageDesc verbosity else findCabalFile  $ head args+          (cabalPath, mtmp) <- if null args+                               then do+                                 pth <- defaultPackageDesc verbosity+                                 return (pth, Nothing)+                               else findCabalFile $ head args           void $ createSpecFile cabalPath opts+          maybe (return ()) removeDirectoryRecursive mtmp -findCabalFile :: FilePath -> IO FilePath+-- returns path to .cabal file and possibly tmpdir to be removed+findCabalFile :: FilePath -> IO (FilePath, Maybe FilePath) findCabalFile path = do   isdir <- doesDirectoryExist path   if isdir-    then findPackageDesc path+    then do+      file <- findPackageDesc path+      return (file, Nothing)     else do       isfile <- doesFileExist path       if not isfile         then if '/' `notElem` path-             then tryUnpack path+             then do+               tryUnpack path              else error $ path ++ ": No such file or directory"-        else if takeExtension path /= ".cabal"-             then error $ path ++ ": file should have .cabal extension file."-             else return path+        else if takeExtension path == ".cabal"+             then return (path, Nothing)+             else if isSuffixOf ".tar.gz" path+                  then do+                    tmpdir <- mktempdir+                    _ <- system $ "tar zxf " ++ path ++ " -C " ++ tmpdir ++ " *.cabal"+                    subdir <- readProcess "ls" [tmpdir] []+                    file <- findPackageDesc $ tmpdir ++ "/" ++ init subdir+                    return (file, Just tmpdir)+                  else error $ path ++ ": file should be a .cabal or .tar.gz file." -tryUnpack :: String -> IO FilePath+tryUnpack :: String -> IO (FilePath, Maybe FilePath) tryUnpack pkg = do   pkgver <- if isDigit $ last pkg then return pkg             else do               contains_pkg <- readProcess "cabal" ["list", "--simple-output", pkg] []-              let pkgs = filter (startsWith pkg) $ lines contains_pkg+              let pkgs = filter ((== pkg) . fst . break (== ' ')) $ lines contains_pkg               return $ map (\c -> if c == ' ' then '-' else c) $ last pkgs   isdir <- doesDirectoryExist pkgver-  unless isdir $ do+  if isdir+    then do+    pth <-findPackageDesc pkgver+    return (pth, Nothing)+    else do+    cwd <- getCurrentDirectory+    tmpdir <- mktempdir+    setCurrentDirectory tmpdir     _ <- system $ "cabal unpack " ++ pkgver-    return ()-  findPackageDesc pkgver+    pth <- findPackageDesc pkgver+    setCurrentDirectory cwd+    return (tmpdir ++ "/" ++ pth, Just tmpdir) -startsWith :: String -> String -> Bool-startsWith pkg mth = take (length pkg') mth == pkg'-  where-    pkg' = pkg ++ " "+mktempdir :: IO FilePath+mktempdir = do+  mktempOut <- readProcess "mktemp" ["-d"] []+  return $ init mktempOut