packages feed

kit 0.4.1 → 0.4.2

raw patch · 8 files changed

+57/−89 lines, 8 filesdep +Glob

Dependencies added: Glob

Files

Kit/Main.hs view
@@ -3,6 +3,7 @@   import qualified Data.ByteString as BS    import Control.Monad.Trans+  import Control.Monad.Error   import Data.List   import Data.Maybe   import Data.Monoid@@ -29,14 +30,13 @@       return $ home </> ".kit" </> "repository"   defaultLocalRepository = fmap fileRepo defaultLocalRepoPath -  handleFails (Left e) = do-    print e-    return ()-  handleFails (Right _) = return ()+  handleFails :: Either KitError a -> IO ()+  handleFails = either (putStrLn . ("kit error: " ++)) (\x -> return ()) +  run f = runErrorT f >>= handleFails+   doUpdate :: IO ()-  doUpdate = unKitIO g >>= handleFails-      where g = do+  doUpdate = run $ do               repo <- liftIO defaultLocalRepository               deps <- getMyDeps repo               puts $ "Dependencies: " ++ (stringJoin ", " $ map kitFileName deps)@@ -49,13 +49,13 @@    doPackageKit :: IO ()   doPackageKit = do-      mySpec <- unKitIO myKitSpec+      mySpec <- runErrorT myKitSpec       T.for mySpec package       return ()    doDeployLocal :: IO ()   doDeployLocal = do-    mySpec <- unKitIO myKitSpec+    mySpec <- runErrorT myKitSpec     T.for mySpec package     T.for mySpec x     handleFails mySpec@@ -63,8 +63,7 @@         x :: KitSpec -> IO ()         x spec = let               k = specKit spec-              kf = kitFileName . specKit $ spec-              pkg = (kf ++ ".tar.gz")+              pkg = (kitFileName k ++ ".tar.gz")             in do               repo <- defaultLocalRepoPath               let thisKitDir = repo </> "kits" </> kitName k </> kitVersion k@@ -73,9 +72,7 @@               copyFile "KitSpec" $ thisKitDir </> "KitSpec"    doVerify :: String -> IO ()-  doVerify sdk = (unKitIO f >>= handleFails)-    where-      f = do+  doVerify sdk = run $ do         mySpec <- myKitSpec         puts "Checking that the kit can be depended upon..."         puts " #> Deploying locally"@@ -86,18 +83,19 @@           let kitVerifyDir = "kit-verify"           cleanOrCreate kitVerifyDir           inDirectory kitVerifyDir $ do-            writeFile "KitSpec" $ encode (KitSpec (Kit "verify-kit" "1.0") $ defaultConfiguration{kitConfigDependencies=[specKit mySpec]})+            let verifySpec = (defaultSpecForKit $ Kit "verify-kit" "1.0"){ specDependencies = [specKit mySpec] }+            writeFile "KitSpec" $ encode verifySpec             doUpdate             inDirectory "Kits" $ do               system $ "xcodebuild -sdk " ++ sdk           putStrLn "OK."         puts "End checks."-      puts = liftIO . putStrLn+       where puts = liftIO . putStrLn    doCreateSpec :: String -> String -> IO ()   doCreateSpec name version = do     let kit =(Kit name version)-    let spec = KitSpec kit defaultConfiguration+    let spec = defaultSpecForKit kit     writeFile "KitSpec" $ encode spec     putStrLn $ "Created KitSpec for " ++ kitFileName kit     return ()
Kit/Model.hs view
@@ -6,20 +6,10 @@    data KitSpec = KitSpec {     specKit :: Kit,-    specConfiguration :: KitConfiguration-  } deriving (Show, Read)--  data KitConfiguration = KitConfiguration {-    kitConfigDependencies :: [Kit],-    sourceDir :: FilePath+    specDependencies :: [Kit],+    specSourceDir :: FilePath   } deriving (Show, Read) -  specDependencies :: KitSpec -> [Kit]-  specDependencies = kitConfigDependencies . specConfiguration--  defaultConfiguration :: KitConfiguration-  defaultConfiguration = KitConfiguration [] "src"-   type Version = String    data Kit = Kit {@@ -33,6 +23,9 @@   kitConfigFile :: Kit -> String   kitConfigFile kit = kitFileName kit </> (kitName kit ++ ".xcconfig") +  defaultSpecForKit :: Kit -> KitSpec+  defaultSpecForKit kit = KitSpec kit [] "src"+   instance JSON Kit where       showJSON kit = makeObj           [ ("name", showJSON $ kitName kit)@@ -53,8 +46,8 @@        readJSON (JSObject obj) =           let myKit = Kit <$> f "name" <*> f "version"-              myConfig = (KitConfiguration <$> f "dependencies" <*> (f "sourceDir" <|> pure "src"))-           in KitSpec <$> myKit <*> myConfig+              -- myConfig = (KitConfiguration <$> )+           in KitSpec <$> myKit <*> f "dependencies" <*> (f "sourceDir" <|> pure "src")         where f x = mLookup x jsonObjAssoc >>= readJSON               jsonObjAssoc = fromJSObject obj 
Kit/Package.hs view
@@ -18,9 +18,9 @@      *.codeproj   -} -  fileBelongsInPackage :: KitConfiguration -> FilePath -> Bool+  fileBelongsInPackage :: KitSpec -> FilePath -> Bool   fileBelongsInPackage config fp = let-    a = elem fp [sourceDir config, "test", "KitSpec"]+    a = elem fp [specSourceDir config, "test", "KitSpec"]     b = "xcodeproj" `isSuffixOf` fp     c = "xcconfig" `isSuffixOf` fp     d = ".pch" `isSuffixOf` fp@@ -30,11 +30,13 @@   package spec = do       tempDir <- getTemporaryDirectory       current <- getCurrentDirectory+      distDir <- fmap (</> "dist") getCurrentDirectory       let kd = tempDir </> kitPath       cleanOrCreate kd       contents <- getDirectoryContents "."-      mapM_ (cp_r_to kd) (filter (fileBelongsInPackage . specConfiguration $ spec) contents)-      inDirectory tempDir $ sh $ "tar czf " ++ (current </> (kitPath ++ ".tar.gz")) ++ " " ++ kitPath+      mapM_ (cp_r_to kd) (filter (fileBelongsInPackage spec) contents)+      mkdir_p distDir+      inDirectory tempDir $ sh $ "tar czf " ++ (distDir </> (kitPath ++ ".tar.gz")) ++ " " ++ kitPath       return ()     where       kitPath = kitFileName . specKit $ spec
Kit/Project.hs view
@@ -7,6 +7,7 @@    import Control.Monad.Trans   import Control.Monad+  import Control.Monad.Error   import Control.Applicative   import qualified Data.Foldable as F   import Data.Maybe@@ -117,7 +118,7 @@     where sh = system    readSpec :: FilePath -> KitIO KitSpec-  readSpec kitSpecPath = readSpecContents kitSpecPath >>= KitIO . return . parses+  readSpec kitSpecPath = readSpecContents kitSpecPath >>= ErrorT . return . parses    myKitSpec :: KitIO KitSpec   myKitSpec = readSpec "KitSpec"@@ -131,8 +132,8 @@   readSpecContents :: FilePath -> KitIO String   readSpecContents kitSpecPath = checkExists kitSpecPath >>= liftIO . readFile -  parses :: String -> Either [KitError] KitSpec+  parses :: String -> Either KitError KitSpec   parses contents = case (decode contents) of                       Ok a -> Right a-                      Error a -> Left [a]+                      Error a -> Left a 
Kit/Repository.hs view
@@ -25,6 +25,7 @@   import qualified Data.Traversable as T   import Control.Monad   import Control.Monad.Trans+  import Control.Monad.Error   import Text.JSON   import qualified Data.ByteString as BS @@ -39,7 +40,7 @@   getKitSpec :: KitRepository -> Kit -> KitIO KitSpec   getKitSpec kr k = do     mbKitStuff <- liftIO $ repoRead kr (kitSpecPath k)-    maybe (kitError $ "Missing " ++ kitFileName k) f mbKitStuff+    maybe (throwError $ "Missing " ++ kitFileName k) f mbKitStuff     where f contents = maybeToKitIO ("Invalid KitSpec file for " ++ kitFileName k) $ case (decode contents) of                           Ok a -> Just a                           Error _ -> Nothing
Kit/Util.hs view
@@ -14,62 +14,35 @@   import qualified Data.Traversable as T   import Data.Foldable   import Control.Applicative-  import Control.Monad+   import Data.Monoid-  import Control.Monad.Trans+  import Control.Monad.Error ---  ma |> f = fmap f ma+  import System.FilePath.Glob    maybeRead :: Read a => String -> Maybe a   maybeRead = fmap fst . listToMaybe . reads    justTrue :: Bool -> a -> Maybe a-  justTrue True a = Just a-  justTrue False _ = Nothing+  justTrue p a = if p then Just a else Nothing    maybeToRight :: b -> Maybe a -> Either b a-  maybeToRight _ (Just a) = Right a-  maybeToRight b Nothing = Left b+  maybeToRight v = maybe (Left v) Right    maybeToLeft :: b -> Maybe a -> Either a b-  maybeToLeft _ (Just a) = Left a-  maybeToLeft b Nothing = Right b+  maybeToLeft v = maybe (Right v) Left    instance Foldable (Either c) where-    foldr f z (Left c) = z-    foldr f z (Right a) = f a z+    foldr f z = either (const z) (\v -> f v z)    instance T.Traversable (Either c) where     sequenceA = either (pure . Left) (Right <$>)    type KitError = String -  data KitIO a = KitIO { unKitIO :: (IO (Either [KitError] a)) }--  kitError :: KitError -> KitIO a-  kitError e = KitIO . return $ Left [e]--  maybeToKitIO msg = maybe (kitError msg) return--  instance Monad KitIO where-    (KitIO ioE) >>= f = KitIO $ ioE >>= g-      where g l@(Left v) = return (Left v)-            g (Right v) = unKitIO $ f v--    return = KitIO . return . Right--  instance Functor KitIO where-    fmap f kio = kio >>= (return . f)--  instance MonadIO KitIO where-    liftIO v = KitIO (fmap Right v)+  type KitIO a = ErrorT KitError IO a -  instance Applicative KitIO where-    pure = return-    mf <*> ma = do-      f <- mf-      a <- ma-      return $ f a+  maybeToKitIO msg = maybe (throwError msg) return    mkdir_p :: FilePath -> IO ()   mkdir_p = createDirectoryIfMissing True@@ -89,7 +62,7 @@     return v    glob :: String -> IO [String]-  glob pattern = fmap lines (readProcess "ruby" ["-e", "puts Dir.glob(\"" ++ pattern ++ "\")"] [])+  glob pattern = globDir1 (compile pattern) ""    stringJoin :: Monoid a => a -> [a] -> a   stringJoin x = mconcat . intersperse x
Kit/XCode/Builder.hs view
@@ -6,15 +6,15 @@   import Kit.XCode.Common   import Kit.XCode.ProjectFile   import Kit.Util-  +   createBuildFile :: Integer -> FilePath -> PBXBuildFile   createBuildFile i path = PBXBuildFile uuid1 $ PBXFileReference uuid2 path     where uuid1 = uuid i           uuid2 = uuid $ i + 10000000-  +   buildXCodeProject :: [FilePath] -> [FilePath] -> String-  buildXCodeProject headers sources = -      projectPbxProj bfs frs classes hs srcs +  buildXCodeProject headers sources =+      projectPbxProj bfs frs classes hs srcs     where       sourceStart = toInteger (length headers + 1)       headerBuildFiles = zipWith createBuildFile [1..] headers@@ -25,7 +25,7 @@       classes = classesSection $ map buildFileReference (sourceBuildFiles ++ headerBuildFiles)       hs = headersSection headerBuildFiles       srcs = sourcesSection sourceBuildFiles-  +   xxx :: FilePath -> UUID -> UUID -> PBXBuildFile   xxx fp buildId fileId = PBXBuildFile buildId (PBXFileReference fileId fp) @@ -65,9 +65,9 @@           "path" ~> show path,           "sourceTree" ~> show "<group>"         ]-      +   layoutSection :: String -> [String] -> String-  layoutSection name body = let +  layoutSection name body = let       front  = "/* Begin " ++ name ++ " section */"       middle = map ("    " ++) body       back   = "/* End " ++ name ++ " section */"@@ -78,8 +78,8 @@       "4728C530117C02B10027D7D1 /* Kit.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 4728C52F117C02B10027D7D1 /* Kit.xcconfig */; };",       "AA747D9F0F9514B9006C5449 /* KitDeps_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* KitDeps_Prefix.pch */; };",       "AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };"-    ])  -    +    ])+   fileReferenceSection :: [PBXFileReference] -> String   fileReferenceSection refs = layoutSection "PBXFileReference" (map fileReferenceItem refs ++ [   		"4728C52F117C02B10027D7D1 /* Kit.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Kit.xcconfig; sourceTree = \"<group>\"; };",@@ -107,7 +107,7 @@   			);   			runOnlyForDeploymentPostprocessing = 0;   		};-  /* End PBXHeadersBuildPhase section */-}                +  /* End PBXHeadersBuildPhase section */-}   headersSection :: [PBXBuildFile] -> String   headersSection bfs = layoutSection "PBXHeadersBuildPhase" [lineItem "D2AAC07A0554694100DB518D" "Headers" [     "isa" ~> "PBXHeadersBuildPhase",@@ -116,7 +116,7 @@     "runOnlyForDeploymentPostprocessing" ~> "0" 	  ]] 	  where prefixPchUUID = "AA747D9F0F9514B9006C5449"-	  +	 	{-     /* Begin PBXSourcesBuildPhase section */     		D2AAC07B0554694100DB518D /* Sources */ = {@@ -136,7 +136,7 @@     "files" ~> ("(" ++ (stringJoin "," $ map buildFileId bfs) ++ ",)"),     "runOnlyForDeploymentPostprocessing" ~> "0"     ]]-  +   testBuilder = let     header = PBXFileReference "1" "fk/fk.h"     source = PBXFileReference "2" "fk/fk.m"
kit.cabal view
@@ -1,5 +1,5 @@ name: kit-version: 0.4.1+version: 0.4.2 cabal-version: >=1.2 build-type: Simple license: BSD3@@ -9,7 +9,7 @@ build-depends: process -any, network -any, mtl -any, json -any,                filepath -any, directory -any, containers -any, cmdargs >=0.3,                bytestring -any, base >=3 && <5, QuickCheck -any, MissingH -any,-               HTTP >=4000.0.9+               HTTP >=4000.0.9, Glob >= 0.5 stability: homepage: package-url: