Skip to content

Commit

Permalink
Import the PKGBUILD pretty printer from cabal2arch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy Oudompheng committed Oct 14, 2010
1 parent e943c96 commit 79d98b5
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions Distribution/ArchLinux/PkgBuild.hs
Expand Up @@ -402,8 +402,82 @@ readPackage st = do


------------------------------------------------------------------------
-- Pretty printing:

--
-- | Translate an abstract PkgBuild file into a document structure
--

(<=>) :: Doc -> Doc -> Doc
x <=> y = x <> char '=' <> y

--
-- Print a PKGBUILD without comments
--
rawpkg2doc :: PkgBuild -> Doc
rawpkg2doc pkg = vcat
[ text "pkgname"
<=> text (arch_pkgname pkg)
, text "pkgrel"
<=> int (arch_pkgrel pkg)
, text "pkgver"
<=> disp (arch_pkgver pkg)
, text "pkgdesc"
<=> text (show (arch_pkgdesc pkg))
, text "url"
<=> doubleQuotes (text (arch_url pkg))
, text "license"
<=> disp (arch_license pkg)
, text "arch"
<=> disp (arch_arch pkg)
, text "makedepends"
<=> disp (arch_makedepends pkg)
, case arch_depends pkg of
ArchList [] -> empty
_ -> text "depends" <=> disp (arch_depends pkg)
, text "options" <=> disp (arch_options pkg)
, text "source"
<=> dispNoQuotes (arch_source pkg)
, case arch_install pkg of
Nothing -> empty
Just p -> text "install" <=> disp p
, text "md5sums"
<=> disp (arch_md5sum pkg)
, hang
(text "build() {") 4
(vcat $ (map text) (arch_build pkg))
$$ char '}'
, hang
(text "package() {") 4
(vcat $ (map text) (arch_package pkg))
$$ char '}'
]

instance Text PkgBuild where
disp p = rawpkg2doc p
parse = undefined

--
-- Display a PKGBUILD with header
--
instance Text AnnotatedPkgBuild where
disp AnnotatedPkgBuild {
pkgBuiltWith = ver,
pkgHeader = head,
pkgBody = pkg
} = case ver of
Nothing -> empty
Just v -> text "# Package generated by cabal2arch" <+> (disp v)
$$ text head $$ disp pkg
parse = undefined

--
-- Display a full PKGBUILD with contributor name
--
pkg2doc :: String -> AnnotatedPkgBuild -> Doc
pkg2doc email pkg = text "# Contributor:" <+> text email $$ disp pkg

---------------------------------------------------------------------------

{-
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>
Expand Down

0 comments on commit 79d98b5

Please sign in to comment.