Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/d sy ms #15

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,35 +143,40 @@ Available options:
-v Show verbose output

Available commands:
upload Uploads frameworks contained in the local
upload Uploads frameworks and dSYMs contained in the local
Carthage/Build/iOS to S3, according to the local
Cartfile.resolved
download Downloads and unpacks in Carthage/Build/iOS
frameworks found in S3, according to the local
Carftfile.resolved
frameworks and dSYMs found in S3, according to the
local Carftfile.resolved
list Lists frameworks in the cache and reports cache
misses/hits, according to the local
Carftfile.resolved
Carftfile.resolved. Ignores dSYMs.
```

#### Uploading

Uploading one or more frameworks (an empty list of frameworks will upload all frameworks found in `Cartfile.resolved`):
Uploading one or more frameworks and corresponding dSYMs
(an empty list of frameworks will upload all frameworks found in `Cartfile.resolved`):

```
$ rome upload Alamofire FGAuth
Uploaded: Alamofire/Alamofire.framework-3.4.1.zip
Uploaded: Alamofire/Alamofire.framework.dSYM-3.4.1.zip
Uploaded: FGAuth/FGAuth.framework-v3.3.3.zip
```

#### Downloading

Downloading one or more frameworks (an empty list of frameworks will download all frameworks found in `Cartfile.resolved`):
Downloading one or more frameworks and corresponding dSYMs
(an empty list of frameworks will download all frameworks found in `Cartfile.resolved`):

```
$ rome download Alamofire FGAuth
Downloaded: Alamofire.framework-3.4.1.zip
Unzipped: Alamofire.framework-3.4.1.zip
Downloaded: Alamofire.framework.dSYM-3.4.1.zip
Unzipped: Alamofire.framework.dSYM-3.4.1.zip
Downloaded: FGAuth.framework-v3.3.3.zip
Unzipped: FGAuth.framework-v3.3.3.zip
```
Expand Down Expand Up @@ -209,5 +214,8 @@ $ rome list --present
ResearchKit
```

Note: `list` completely ignores dSYMs. If a dSYM is missing the corresponding
framework is still reported as present.

## Get Rome
The Rome binary is attached as a zip to the [releases page](https://github.com/blender/Rome/releases) here on GitHub.
4 changes: 3 additions & 1 deletion Rome.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Rome
version: 0.4.0.4
version: 0.5.0.6
synopsis: An S3 cache for Carthage
description: Please see README.md
homepage: https://github.com/blender/Rome
Expand All @@ -18,6 +18,7 @@ library
exposed-modules: Lib
, Data.Cartfile
, Data.Romefile
, Data.Ini.Utils
, Text.Parsec.Utils

build-depends: base >= 4.7 && < 5
Expand All @@ -29,6 +30,7 @@ library
, MissingH >= 1.3
, directory >= 1.2.2
, containers >= 0.5
, unordered-containers >= 0.2.7
, conduit-extra >= 1.1
, ini >= 0.3.5
, text >= 1.2
Expand Down
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Options.Applicative as Opts


romeVersion :: String
romeVersion = "0.4.0.4"
romeVersion = "0.5.0.6"



Expand Down
80 changes: 80 additions & 0 deletions src/Data/Ini/Utils.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}

module Data.Ini.Utils
(optionalKey
, requireKey
, inRequiredSection
, inOptionalSection
, fromIni'
, fromIni''
)
where

import Data.Char
import Data.Text as T
import qualified Data.HashMap.Strict as M
import Data.Monoid
import Control.Exception
import Control.Monad.Except
import Control.Monad.Reader
import Data.Ini



requireKey :: (MonadReader (Ini, Text) m, MonadError Text m) => Text -> m Text
requireKey key = do
(ini, section) <- ask
case lookupValue section key ini of
Left e -> invalidError Nothing (pack e)
Right value
| blank value -> invalidError (Just key) "cannot be a blank string."
| otherwise -> return value
where
blank x = T.null x || T.all isSpace x

optionalKey :: Monad m => Text -> ReaderT (Ini, Text) m (Maybe Text)
optionalKey key = do
(ini, section) <- ask
case lookupValue section key ini of
Left _ -> return Nothing
Right value -> return $ Just value

requireSection :: (MonadReader Ini m, MonadError Text m) => Text -> m Text
requireSection section = do
(Ini ini) <- ask
case M.lookup section ini of
Nothing -> invalidError Nothing ("Could not find section " <> section)
Just _ -> return section

inRequiredSection :: (MonadReader Ini m, MonadError Text m) => ReaderT (Ini, Text) m b -> Text -> m b
inRequiredSection reader section = do
ini <- ask
s <- requireSection section
runReaderT reader (ini, s)

inOptionalSection :: (MonadReader Ini m) => Text -> a -> ReaderT (Ini, Text) (ExceptT Text m) a -> m a
inOptionalSection section defaultValue exceptingReader = do
t <- runExceptT $ exceptingReader `inRequiredSection` section
case t of
Left _ -> return defaultValue
Right a -> return a

invalidError Nothing e = throwError e
invalidError (Just k) e = throwError $ "Key " <> k <> " " <> e

fromIni' :: ReaderT Ini (ExceptT Text m) a -> Ini -> m (Either Text a)
fromIni' r ini = runExceptT $ runReaderT r ini

fromIni'' :: ReaderT Ini m a -> Ini -> m a
fromIni'' = runReaderT


example :: Ini -> IO ()
example ini = do
r <- requireKey "k" `inRequiredSection` "text" `fromIni'` ini
t <- inOptionalSection "section" "default" (requireKey "k") `fromIni'` ini
s <- inOptionalSection "section" (Just "default") (optionalKey "k") `fromIni''` ini
case r of
Right _ -> print r
Left _ -> undefined
73 changes: 37 additions & 36 deletions src/Data/Romefile.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}


module Data.Romefile
Expand All @@ -11,10 +13,15 @@ module Data.Romefile
)
where

import Data.Cartfile
import qualified Text.Parsec as Parsec
import qualified Text.Parsec.Utils as Parsec
import qualified Text.Parsec.String as Parsec
import Data.Ini as INI
import Data.Ini.Utils as INI
import Data.Monoid
import Data.Text
import Control.Monad.Except
import Control.Monad.Trans
-- import qualified Text.Parsec as Parsec
-- import qualified Text.Parsec.Utils as Parsec
-- import qualified Text.Parsec.String as Parsec

type FrameworkName = String
type GitRepoName = String
Expand All @@ -24,38 +31,32 @@ data RomefileEntry = RomefileEntry { gitRepositoryName :: GitRepoName
deriving (Show, Eq)



-- |The name of the Romefile
romefile :: String
romefile = "Romefile"

-- Romefile parsing

parseS3BucketNameSection :: Parsec.Parsec String () String
parseS3BucketNameSection = do
Parsec.string "[S3Bucket]" >> Parsec.endOfLine
s3BucketName <- Parsec.parseWhiteSpaces >> Parsec.parseUnquotedString
Parsec.endOfLine
return s3BucketName

parseRepositoryMapSection :: Parsec.Parsec String () [RomefileEntry]
parseRepositoryMapSection = do
Parsec.string "[RepositoryMap]" >> Parsec.endOfLine
Parsec.many parseRepositoryMapLine

parseRepositoryMapLine :: Parsec.Parsec String () RomefileEntry
parseRepositoryMapLine = do
gitRepositoryName <- Parsec.parseWhiteSpaces >> Parsec.parseUnquotedString
frameworkCommonName <- Parsec.parseWhiteSpaces >> Parsec.parseUnquotedString
Parsec.endOfLine
return RomefileEntry {..}

parseRomeConfig :: Parsec.Parsec String () (String, [RomefileEntry])
parseRomeConfig = do
s3BucketName <- parseS3BucketNameSection
Parsec.many Parsec.newline
romeFileEntries <- Parsec.option [] parseRepositoryMapSection
Parsec.manyTill Parsec.parseWhiteSpaces Parsec.eof
return (s3BucketName, romeFileEntries)

parseRomefile :: String -> IO (Either Parsec.ParseError (String, [RomefileEntry]))
parseRomefile = Parsec.parseFromFile parseRomeConfig
-- |The delimiter of the CACHE section a Romefile
cacheSectionDelimiter :: Text
cacheSectionDelimiter = "CACHE"

-- |The S3-Bucket Key
s3BucketKey :: Text
s3BucketKey = "S3-Bucket"

-- |The delimier of the REPOSITORYMAP section
repositoryMapSectionDelimiter :: String
repositoryMapSectionDelimiter = "REPOSITORYMAP"


parseRomefile :: (MonadIO m, MonadError String m) => FilePath -> m (Text, [RomefileEntry])
parseRomefile f = do
eitherIni <- liftIO $ INI.readIniFile f
case eitherIni of
Left iniError -> throwError iniError
Right ini -> do
eitherBucker <- getBucket ini
case eitherBucker of
Left e -> throwError $ "Error while parsing " <> f <> ": " <> unpack e
Right bucket -> return (bucket, [])

getBucket ini = requireKey s3BucketKey `inRequiredSection` cacheSectionDelimiter `fromIni'` ini
Loading