Skip to content
Permalink
Browse files

Remove bash parsing from AUR dep handling

  • Loading branch information...
theotherjimmy committed Sep 8, 2017
1 parent bf1ece3 commit 7848e9830cd880215f1d12a1c0294992428ea778
@@ -44,7 +44,6 @@ import Linux.Arch.Aur
import Text.Printf (printf)
import Text.Regex.PCRE ((=~))

import Aura.Bash (namespace, Namespace)
import Aura.Colour.Text
import Aura.Core
import Aura.Install (InstallOptions(..))
@@ -118,11 +117,10 @@ aurPkgInfo (fmap T.pack -> pkgs) = aurInfo pkgs >>= traverse_ displayAurPkgInfo
displayAurPkgInfo :: AurInfo -> Aura ()
displayAurPkgInfo ai = ask >>= \ss -> do
let name = T.unpack $ aurNameOf ai
ns <- fromJust <$> pkgbuild (managerOf ss) name >>= namespace name . T.unpack
liftIO $ putStrLn $ renderAurPkgInfo ss ai ns <> "\n"
liftIO $ putStrLn $ renderAurPkgInfo ss ai <> "\n"

renderAurPkgInfo :: Settings -> AurInfo -> Namespace -> String
renderAurPkgInfo ss ai ns = entrify ss fields entries
renderAurPkgInfo :: Settings -> AurInfo -> String
renderAurPkgInfo ss ai = entrify ss fields entries
where fields = fmap bForeground . infoFields . langOf $ ss
empty x = case x of [] -> "None"; _ -> x
entries = [ magenta "aur"
@@ -133,8 +131,8 @@ renderAurPkgInfo ss ai ns = entrify ss fields entries
, cyan $ maybe "(null)" T.unpack (urlOf ai)
, pkgUrl $ T.unpack $ aurNameOf ai
, T.unpack . T.unwords $ licenseOf ai
, empty . unwords $ depends ns
, empty . unwords $ makedepends ns
, T.unpack . T.unwords $ dependsOf ai
, T.unpack . T.unwords $ makeDepsOf ai
, yellow . show $ aurVotesOf ai
, yellow $ printf "%0.2f" (popularityOf ai)
, maybe "(null)" T.unpack (aurDescriptionOf ai) ]
@@ -78,6 +78,8 @@ data InstallType = Pacman String | Build Buildable
data Buildable = Buildable
{ baseNameOf :: String
, pkgbuildOf :: Pkgbuild
, bldDepsOf :: [Dep]
, bldVersionOf :: String
-- | Did the user select this package, or is it being built as a dep?
, isExplicit :: Bool
-- | Fetch and extract the source code corresponding to the given package.
@@ -43,6 +43,7 @@ module Aura.Packages.ABS
) where

import Control.Monad
import Data.Monoid ((<>))
import Data.List (find)
import Data.Foldable (fold)
import Data.Set (Set)
@@ -84,11 +85,30 @@ absDepsRepo :: Aura Repository
absDepsRepo = asks (getRepo . buildABSDeps)
where getRepo manual = if manual then absRepo else pacmanRepo

-- | Yields the value of the `depends` field.
depends :: Namespace -> [String]
depends = flip value "depends"

makedepends :: Namespace -> [String]
makedepends = flip value "makedepends"

checkdepends :: Namespace -> [String]
checkdepends = flip value "checkdepends"

trueVersion :: Namespace -> String
trueVersion ns = pkgver <> "-" <> pkgrel
where pkgver = head $ value ns "pkgver"
pkgrel = head $ value ns "pkgrel"

makeBuildable :: String -> String -> Aura Buildable
makeBuildable repo name = do
pb <- absPkgbuild repo name
ns <- namespace name pb
pure Buildable { baseNameOf = name
, pkgbuildOf = pb
, bldDepsOf = parseDep <$> foldMap ($ ns)
[depends, makedepends, checkdepends]
, bldVersionOf = trueVersion ns
, isExplicit = False
, buildScripts = \fp -> Just <$> copyTo repo name fp }

@@ -54,15 +54,21 @@ import Utilities (decompress)
---

aurLookup :: String -> Aura (Maybe Buildable)
aurLookup name = asks managerOf >>= \m -> fmap (makeBuildable m name . T.unpack) <$> pkgbuild m name
aurLookup name = asks managerOf >>= \m -> do
junk <- fmap (makeBuildable m name . T.unpack)<$> pkgbuild m name
sequence junk

aurRepo :: Repository
aurRepo = Repository $ aurLookup >=> traverse packageBuildable

makeBuildable :: Manager -> String -> Pkgbuild -> Buildable
makeBuildable m name pb = Buildable
makeBuildable :: Manager -> String -> Pkgbuild -> Aura Buildable
makeBuildable m name pb = do
ai <- head <$> info m [T.pack name]
return Buildable
{ baseNameOf = name
, pkgbuildOf = pb
, bldDepsOf = parseDep . T.unpack <$> dependsOf ai ++ makeDepsOf ai
, bldVersionOf = T.unpack $ aurVersionOf ai
, isExplicit = False
, buildScripts = f }
where f fp = sourceTarball m fp (T.pack name) >>= traverse decompress
@@ -40,21 +40,6 @@ toFilename = (<> ".pb")
pkgbuildPath :: String -> FilePath
pkgbuildPath p = pkgbuildCache <> toFilename p

trueVersion :: Namespace -> String
trueVersion ns = pkgver <> "-" <> pkgrel
where pkgver = head $ value ns "pkgver"
pkgrel = head $ value ns "pkgrel"

-- | Yields the value of the `depends` field.
depends :: Namespace -> [String]
depends = flip value "depends"

makedepends :: Namespace -> [String]
makedepends = flip value "makedepends"

checkdepends :: Namespace -> [String]
checkdepends = flip value "checkdepends"

-- One of my favourite functions in this code base.
pbCustomization :: Buildable -> Aura Buildable
pbCustomization = foldl (>=>) pure [customizepkg, hotEdit]
@@ -63,10 +48,8 @@ pbCustomization = foldl (>=>) pure [customizepkg, hotEdit]
packageBuildable :: Buildable -> Aura Package
packageBuildable b = do
b' <- pbCustomization b
ns <- namespace (baseNameOf b') (pkgbuildOf b')
pure Package
{ pkgNameOf = baseNameOf b'
, pkgVersionOf = trueVersion ns
, pkgDepsOf = parseDep <$> foldMap ($ ns)
[depends, makedepends, checkdepends]
, pkgDepsOf = bldDepsOf b'
, pkgVersionOf = bldVersionOf b'
, pkgInstallTypeOf = Build b' }

0 comments on commit 7848e98

Please sign in to comment.
You can’t perform that action at this time.