diff --git a/src/Caches/Local/Downloading.hs b/src/Caches/Local/Downloading.hs index 54c2503..010374b 100644 --- a/src/Caches/Local/Downloading.hs +++ b/src/Caches/Local/Downloading.hs @@ -66,30 +66,34 @@ getVersionFileFromLocalCache :: MonadIO m => FilePath -- ^ The cache definition -> CachePrefix -- ^ A prefix for folders at top level in the cache. - -> ProjectNameAndVersion -- ^ The `ProjectNameAndVersion` used to identify the .version file + -> InvertedRepositoryMap -- ^ The map used to resolve from a `FrameworkVersion` to the path of the Framework in the cache + -> FrameworkVector -- ^ The `FrameworkVector` used to identify the .version file -> ExceptT String m LBS.ByteString -getVersionFileFromLocalCache lCacheDir (CachePrefix prefix) projectNameAndVersion +getVersionFileFromLocalCache lCacheDir (CachePrefix prefix) reverseRomeMap fVector = do - versionFileExistsInLocalCache <- - liftIO . doesFileExist $ versionFileLocalCachePath - - if versionFileExistsInLocalCache - then - liftIO - . runResourceT - . C.runConduit - $ C.sourceFile versionFileLocalCachePath - C..| C.sinkLbs - else - throwError - $ "Error: could not find " - <> versionFileName - <> " in local cache at : " - <> versionFileLocalCachePath - where - versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion - versionFileRemotePath = remoteVersionFilePath projectNameAndVersion - versionFileLocalCachePath = lCacheDir prefix versionFileRemotePath + case temp_versionFileRemotePath reverseRomeMap fVector of + Just versionFileRemotePath -> do + versionFileExistsInLocalCache <- + liftIO . doesFileExist $ versionFileLocalCachePath + + if versionFileExistsInLocalCache + then + liftIO + . runResourceT + . C.runConduit + $ C.sourceFile versionFileLocalCachePath + C..| C.sinkLbs + else + throwError + $ "Error: could not find " + <> verboseDebugFileName + <> " in local cache at : " + <> versionFileLocalCachePath + where + verboseDebugFileName = takeFileName $ versionFileRemotePath + versionFileLocalCachePath = + lCacheDir prefix versionFileRemotePath + _ -> pure mempty @@ -404,10 +408,11 @@ getAndUnzipDSYMFromLocalCache buildTypeConfig lCacheDir reverseRomeMap fVector p getAndSaveVersionFilesFromLocalCache :: MonadIO m => FilePath -- ^ The cache definition. - -> [ProjectNameAndVersion] -- ^ A list of `ProjectNameAndVersion` identifying the .version files + -> InvertedRepositoryMap + -> [FrameworkVector] -- ^ A list of `FrameworkVector` identifying the .version files -> [ExceptT String (ReaderT (CachePrefix, Bool) m) ()] -getAndSaveVersionFilesFromLocalCache lCacheDir = - map (getAndSaveVersionFileFromLocalCache lCacheDir) +getAndSaveVersionFilesFromLocalCache lCacheDir reverseRomeMap = + map (getAndSaveVersionFileFromLocalCache lCacheDir reverseRomeMap) @@ -416,28 +421,39 @@ getAndSaveVersionFilesFromLocalCache lCacheDir = getAndSaveVersionFileFromLocalCache :: MonadIO m => FilePath -- ^ The cache definition. - -> ProjectNameAndVersion -- ^ The `ProjectNameAndVersion` identifying the .version file + -> InvertedRepositoryMap + -> FrameworkVector -- ^ The `FrameworkVector` used to indentify the .version file -> ExceptT String (ReaderT (CachePrefix, Bool) m) () -getAndSaveVersionFileFromLocalCache lCacheDir projectNameAndVersion = do - (cachePrefix@(CachePrefix prefix), verbose) <- ask - let finalVersionFileLocalCachePath = versionFileLocalCachePath prefix - let sayFunc = if verbose then sayLnWithTime else sayLn - versionFileBinary <- getVersionFileFromLocalCache lCacheDir - cachePrefix - projectNameAndVersion - sayFunc - $ "Found " - <> versionFileName - <> " in local cache at: " - <> finalVersionFileLocalCachePath - liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath - sayFunc $ "Copied " <> versionFileName <> " to: " <> versionFileLocalPath - where - versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion - versionFileRemotePath = remoteVersionFilePath projectNameAndVersion - versionFileLocalPath = carthageBuildDirectory versionFileName - versionFileLocalCachePath cPrefix = - lCacheDir cPrefix versionFileRemotePath +getAndSaveVersionFileFromLocalCache lCacheDir reverseRomeMap fVector = do + case + ( temp_versionFileLocalPath reverseRomeMap fVector + , temp_versionFileRemotePath reverseRomeMap fVector + ) + of + (Just versionFileLocalPath, Just versionFileRemotePath) -> do + (cachePrefix@(CachePrefix prefix), verbose) <- ask + let finalVersionFileLocalCachePath = versionFileLocalCachePath prefix + let sayFunc = if verbose then sayLnWithTime else sayLn + versionFileBinary <- getVersionFileFromLocalCache lCacheDir + cachePrefix + reverseRomeMap + fVector + sayFunc + $ "Found " + <> verboseDebugFileName + <> " in local cache at: " + <> finalVersionFileLocalCachePath + liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath + sayFunc + $ "Copied " + <> verboseDebugFileName + <> " to: " + <> versionFileLocalPath + where + verboseDebugFileName = takeFileName $ versionFileRemotePath + versionFileLocalCachePath cPrefix = + lCacheDir cPrefix versionFileRemotePath + _ -> pure mempty diff --git a/src/Caches/S3/Downloading.hs b/src/Caches/S3/Downloading.hs index 6def07f..6eb8cda 100644 --- a/src/Caches/S3/Downloading.hs +++ b/src/Caches/S3/Downloading.hs @@ -31,7 +31,9 @@ import qualified Data.Text as T import qualified Network.AWS as AWS import qualified Network.AWS.S3 as S3 import System.Directory ( doesFileExist ) -import System.FilePath ( () ) +import System.FilePath ( () + , takeFileName + ) import Types hiding ( version ) import Utils import Xcode.DWARF @@ -93,22 +95,23 @@ getDSYMFromS3 s3BucketName reverseRomeMap fVector platform = do -- | Carthage only, not necessary for PodBuilder getVersionFileFromS3 :: S3.BucketName - -> ProjectNameAndVersion + -> InvertedRepositoryMap + -> FrameworkVector -> ExceptT String (ReaderT (AWS.Env, CachePrefix, Bool) IO) LBS.ByteString -getVersionFileFromS3 s3BucketName projectNameAndVersion = do - (env, CachePrefix prefix, verbose) <- ask - let finalVersionFileRemotePath = prefix versionFileRemotePath - mapExceptT (withReaderT (const (env, verbose))) $ getArtifactFromS3 - s3BucketName - finalVersionFileRemotePath - versionFileName - where - versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion - versionFileRemotePath = remoteVersionFilePath projectNameAndVersion - +getVersionFileFromS3 s3BucketName reverseRomeMap fVector = do + case temp_versionFileRemotePath reverseRomeMap fVector of + Just versionFileRemotePath -> do + (env, CachePrefix prefix, verbose) <- ask + let finalVersionFileRemotePath = prefix versionFileRemotePath + mapExceptT (withReaderT (const (env, verbose))) $ getArtifactFromS3 + s3BucketName + finalVersionFileRemotePath + verboseDebugFileName + where verboseDebugFileName = takeFileName $ versionFileRemotePath + _ -> pure mempty -- | Retrieves a bcsymbolmap from an S3 Cache diff --git a/src/Lib.hs b/src/Lib.hs index 43449ee..8cd2180 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -469,7 +469,8 @@ downloadArtifacts buildTypeConfig mS3BucketName mlCacheDir reverseRepositoryMap CarthageConfig{} -> runReaderT (downloadVersionFilesFromCaches s3BucketName lCacheDir - gitRepoNamesAndVersions + reverseRepositoryMap + frameworkVectors ) uploadDownloadEnv PodBuilderConfig{} -> mempty -- PodBuilder does not have .version files, rather PodBuilder.plist files that are part of the .framework @@ -496,25 +497,17 @@ downloadArtifacts buildTypeConfig mS3BucketName mlCacheDir reverseRepositoryMap mapM_ (whenLeft sayFunc) errors ) readerEnv - case buildTypeConfig of - CarthageConfig{} -> do - runReaderT - (do - errors <- mapM runExceptT $ getAndSaveVersionFilesFromLocalCache - lCacheDir - gitRepoNamesAndVersions - mapM_ (whenLeft sayFunc) errors - ) - readerEnv - PodBuilderConfig{} -> liftIO mempty -- PodBuilder does not have .version files, rather PodBuilder.plist files that are part of the .framework + runReaderT + (do + errors <- mapM runExceptT $ getAndSaveVersionFilesFromLocalCache + lCacheDir + reverseRepositoryMap + frameworkVectors + mapM_ (whenLeft sayFunc) errors + ) + readerEnv (Nothing, Nothing) -> throwError bothCacheKeysMissingMessage - where - - gitRepoNamesAndVersions :: [ProjectNameAndVersion] - gitRepoNamesAndVersions = repoNamesAndVersionForFrameworkVectors - reverseRepositoryMap - frameworkVectors @@ -841,10 +834,11 @@ saveFrameworkAndArtifactsToLocalCache buildTypeConfig lCacheDir reverseRomeMap f downloadVersionFilesFromCaches :: S3.BucketName -- ^ The cache definition. -> Maybe FilePath -- ^ Just the local cache path or Nothing - -> [ProjectNameAndVersion] -- ^ A list of `ProjectName`s and `Version`s information. + -> InvertedRepositoryMap -- ^ The map used to resolve `FrameworkName`s to `GitRepoName`s. + -> [FrameworkVector] -- ^ A list of `FrameworkVector` used to derive the name and path of the .version files. -> ReaderT UploadDownloadCmdEnv IO () -downloadVersionFilesFromCaches s3BucketName lDir = - mapM_ (downloadVersionFileFromCaches s3BucketName lDir) +downloadVersionFilesFromCaches s3BucketName lDir reverseRomeMap = + mapM_ (downloadVersionFileFromCaches s3BucketName lDir reverseRomeMap) @@ -855,71 +849,79 @@ downloadVersionFilesFromCaches s3BucketName lDir = downloadVersionFileFromCaches :: S3.BucketName -- ^ The cache definition. -> Maybe FilePath -- ^ Just the local cache path or Nothing - -> ProjectNameAndVersion -- ^ The `ProjectName` and `Version` information. + -> InvertedRepositoryMap -- ^ The map used to resolve `FrameworkName`s to `GitRepoName`s. + -> FrameworkVector -- ^ A `FrameworkVector` used to derive the name and path of the .version file. -> ReaderT UploadDownloadCmdEnv IO () -downloadVersionFileFromCaches s3BucketName (Just lCacheDir) projectNameAndVersion - = do - (env, cachePrefix@(CachePrefix prefix), SkipLocalCacheFlag skipLocalCache, _, verbose) <- - ask - - when skipLocalCache $ downloadVersionFileFromCaches s3BucketName - Nothing - projectNameAndVersion +downloadVersionFileFromCaches s3BucketName (Just lCacheDir) reverseRomeMap fVector + = + case + ( temp_versionFileLocalPath reverseRomeMap fVector + , temp_versionFileRemotePath reverseRomeMap fVector + ) + of + (Just versionFileLocalPath, Just versionFileRemotePath) -> do + (env, cachePrefix@(CachePrefix prefix), SkipLocalCacheFlag skipLocalCache, _, verbose) <- ask + + when skipLocalCache $ downloadVersionFileFromCaches s3BucketName + Nothing + reverseRomeMap + fVector + + unless skipLocalCache $ do + eitherSuccess <- runReaderT + (runExceptT $ getAndSaveVersionFileFromLocalCache + lCacheDir + reverseRomeMap + fVector + ) + (cachePrefix, verbose) + case eitherSuccess of + Right _ -> return () + Left e -> liftIO $ do + let sayFunc :: MonadIO m => String -> m () + sayFunc = if verbose then sayLnWithTime else sayLn + sayFunc e + runReaderT + (do + e2 <- runExceptT $ do + versionFileBinary <- getVersionFileFromS3 + s3BucketName + reverseRomeMap + fVector + saveBinaryToLocalCache lCacheDir + versionFileBinary + (prefix versionFileRemotePath) + verboseDebugFileName + verbose + liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath + sayFunc + $ "Copied " + <> verboseDebugFileName + <> " to: " + <> versionFileLocalPath + whenLeft sayFunc e2 + ) + (env, cachePrefix, verbose) + where verboseDebugFileName = takeFileName $ versionFileRemotePath + _ -> pure mempty - unless skipLocalCache $ do - eitherSuccess <- runReaderT - (runExceptT $ getAndSaveVersionFileFromLocalCache - lCacheDir - projectNameAndVersion +downloadVersionFileFromCaches s3BucketName Nothing reverseRomeMap fVector = do + case temp_versionFileLocalPath reverseRomeMap fVector of + Just versionFileLocalPath -> do + (env, cachePrefix, _, _, verbose) <- ask + let sayFunc :: MonadIO m => String -> m () + sayFunc = if verbose then sayLnWithTime else sayLn + eitherError <- liftIO $ runReaderT + (runExceptT $ do + versionFileBinary <- getVersionFileFromS3 s3BucketName reverseRomeMap fVector + liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath + sayFunc $ "Copied " <> verboseDebugFileName <> " to: " <> versionFileLocalPath ) - (cachePrefix, verbose) - case eitherSuccess of - Right _ -> return () - Left e -> liftIO $ do - let sayFunc :: MonadIO m => String -> m () - sayFunc = if verbose then sayLnWithTime else sayLn - sayFunc e - runReaderT - (do - e2 <- runExceptT $ do - versionFileBinary <- getVersionFileFromS3 - s3BucketName - projectNameAndVersion - saveBinaryToLocalCache lCacheDir - versionFileBinary - (prefix versionFileRemotePath) - versionFileName - verbose - liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath - sayFunc - $ "Copied " - <> versionFileName - <> " to: " - <> versionFileLocalPath - whenLeft sayFunc e2 - ) - (env, cachePrefix, verbose) - where - versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion - versionFileLocalPath = carthageBuildDirectory versionFileName - versionFileRemotePath = remoteVersionFilePath projectNameAndVersion - -downloadVersionFileFromCaches s3BucketName Nothing projectNameAndVersion = do - (env, cachePrefix, _, _, verbose) <- ask - let sayFunc :: MonadIO m => String -> m () - sayFunc = if verbose then sayLnWithTime else sayLn - eitherError <- liftIO $ runReaderT - (runExceptT $ do - versionFileBinary <- getVersionFileFromS3 s3BucketName - projectNameAndVersion - liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath - sayFunc $ "Copied " <> versionFileName <> " to: " <> versionFileLocalPath - ) - (env, cachePrefix, verbose) - whenLeft sayFunc eitherError - where - versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion - versionFileLocalPath = carthageBuildDirectory versionFileName + (env, cachePrefix, verbose) + whenLeft sayFunc eitherError + where + verboseDebugFileName = takeFileName $ versionFileLocalPath + _ -> pure mempty