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

Handle Cartfile entries with no new lines at EOL #166

Merged
merged 7 commits into from
Feb 16, 2019
Merged
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
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
- brew install bats-core
script:
- bundle exec danger
- stack $ARGS setup
- stack $ARGS setup -j 2
- stack $ARGS test --no-terminal --haddock --no-haddock-deps
- stack $ARGS build
- stack $ARGS build -j 2
- stack $ARGS sdist
- stack $ARGS install
- travis_wait 60 bats integration-tests/dynamic-frameworks-ini.bats
Expand Down Expand Up @@ -77,9 +77,9 @@ jobs:
- brew install bats-core
script:
- bundle exec danger
- stack $ARGS setup
- stack $ARGS setup -j 2
- stack $ARGS test --no-terminal --haddock --no-haddock-deps
- stack $ARGS build
- stack $ARGS build -j 2
- stack $ARGS sdist
- stack $ARGS install
- travis_wait 60 bats integration-tests/current-framework-yaml.bats
Expand Down Expand Up @@ -114,9 +114,9 @@ jobs:
- brew install bats-core
script:
- bundle exec danger
- stack $ARGS setup
- stack $ARGS setup -j 2
- stack $ARGS test --no-terminal --haddock --no-haddock-deps
- stack $ARGS build
- stack $ARGS build -j 2
- stack $ARGS sdist
- stack $ARGS install
- travis_wait 60 bats integration-tests/static-frameworks-ini.bats
Expand All @@ -126,4 +126,5 @@ cache:
directories:
- $HOME/.local/bin
- $HOME/.stack
- $TRAVIS_BUILD_DIR/.stack-work
- vendor/bundle
2 changes: 1 addition & 1 deletion Rome.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Rome
version: 0.18.1.53
version: 0.18.2.54
synopsis: A cache for Carthage
description: Please see README.md
homepage: https://github.com/blender/Rome
Expand Down
2 changes: 1 addition & 1 deletion Rome.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Rome'
s.version = '0.18.1.53'
s.version = '0.18.2.54'
s.summary = 'A cache tool for Carthage'
s.homepage = 'https://github.com/blender/Rome'
s.source = { :http => "#{s.homepage}/releases/download/v#{s.version}/rome.zip" }
Expand Down
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import System.Exit


romeVersion :: RomeVersion
romeVersion = (0, 18, 1, 53)
romeVersion = (0, 18, 2, 54)



Expand Down
1 change: 1 addition & 0 deletions src/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import qualified Data.Text.IO as T
import System.Directory
import System.FilePath
import Types
import Debug.Trace


getCartfileEntires :: RomeMonad [CartfileEntry]
Expand Down
42 changes: 34 additions & 8 deletions src/Data/Carthage/Cartfile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import qualified Text.Parsec as Parsec
import qualified Text.Parsec.String as Parsec
import qualified Text.Parsec.Utils as Parsec
import Data.Carthage.Common
import Debug.Trace

newtype Location = Location { unLocation :: String }
deriving (Eq, Show, Ord)
Expand Down Expand Up @@ -55,20 +56,45 @@ quotedContent :: Parsec.Parsec String () String
quotedContent =
Parsec.char '"' *> Parsec.parseUnquotedString <* Parsec.char '"'

parseCartfileResolvedLine :: Parsec.Parsec String () CartfileEntry
parseCartfileResolvedLine = do
parseCartfileEntry :: Parsec.Parsec String () CartfileEntry
parseCartfileEntry = do
hosting <- repoHosting
location <- Location <$> quotedContent
_ <- Parsec.many1 Parsec.space
version <- Version <$> quotedContent
return CartfileEntry {..}

parseMaybeCartfileEntry :: Parsec.Parsec String () (Maybe CartfileEntry)
parseMaybeCartfileEntry =
Parsec.optional Parsec.spaces
*> (parseCartfileResolvedLine `Parsec.onceAndConsumeTill` Parsec.endOfLine)

parseCartfileResolved
:: MonadIO m => String -> m (Either Parsec.ParseError [CartfileEntry])
parseCartfileResolved = liftIO . Parsec.parseFromFile
(catMaybes <$> Parsec.many (Parsec.try parseMaybeCartfileEntry))
( catMaybes
<$> ( (Parsec.many $ do
line <-
Parsec.optional Parsec.endOfLine
*> ( Parsec.try parseEmtpyLine
<|> Parsec.try parseDependency
<|> Parsec.try parseComment
)
<* Parsec.optional Parsec.endOfLine
case line of
Dependency entry ->
return $ Just entry
_ -> return Nothing
)
<* Parsec.eof
)
)

data CartfileLine = EmptyLine | Comment | Dependency { entry :: CartfileEntry } deriving (Eq, Show)

parseDependency :: Parsec.Parsec String () CartfileLine
parseDependency = Dependency <$> parseCartfileEntry

parseComment :: Parsec.Parsec String () CartfileLine
parseComment =
Parsec.char '#'
>> Parsec.manyTill Parsec.anyChar (Parsec.lookAhead Parsec.endOfLine)
>> return Comment

parseEmtpyLine :: Parsec.Parsec String () CartfileLine
parseEmtpyLine = Parsec.many1 Parsec.space >> return EmptyLine
13 changes: 0 additions & 13 deletions src/Text/Parsec/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Text.Parsec.Utils
( parseWhiteSpaces
, parseUnquotedString
, onceAndConsumeTill
) where


Expand All @@ -21,15 +20,3 @@ parseWhiteSpaces =
parseUnquotedString :: Parsec.Parsec String () String
parseUnquotedString =
Parsec.many1 (Parsec.noneOf ['"', ' ', '\t', '\n', '\'', '\\', '\r'])


-- | @onceOrConsumeTill p@ end@ tries to apply the parser @p@ /once/ and consumes
-- | the input until @end@. Returns a `Maybe` of the value of @p@.
-- | Thanks to Tobias Mayer, Berlin Haskell Group.
onceAndConsumeTill
:: (Parsec.Stream s Identity Char)
=> Parsec.Parsec s u a
-> Parsec.Parsec s u b
-> Parsec.Parsec s u (Maybe a)
onceAndConsumeTill p end = Parsec.optionMaybe (Parsec.try p) <* consume
where consume = Parsec.try end <|> Parsec.anyChar *> consume