From 17a409dd79fdabb5aeab9dacb0d240ba87440a05 Mon Sep 17 00:00:00 2001 From: Fabian Ehrentraud Date: Sat, 23 Mar 2019 16:16:09 +0100 Subject: [PATCH] introduce temp_versionFileLocalPath and temp_versionFileRemotePath which return Maybes instead of checking for buildTypeConfig in Lib - implemented for uploading --- src/Caches/Local/Uploading.hs | 63 +++++++++++++++------------ src/Caches/S3/Uploading.hs | 32 +++++++++----- src/Lib.hs | 82 +++++++++++++++++------------------ src/Utils.hs | 33 +++++++++++++- 4 files changed, 128 insertions(+), 82 deletions(-) diff --git a/src/Caches/Local/Uploading.hs b/src/Caches/Local/Uploading.hs index b46b065..1f233b3 100644 --- a/src/Caches/Local/Uploading.hs +++ b/src/Caches/Local/Uploading.hs @@ -13,7 +13,9 @@ import Data.Carthage.TargetPlatform import Data.Monoid ((<>)) import Data.Romefile (Framework (..)) import System.Directory -import System.FilePath (()) +import System.FilePath ( () + , takeFileName + ) import Types hiding (version) import Types.Commands (SkipLocalCacheFlag (..)) import Utils @@ -121,10 +123,11 @@ saveBinaryToLocalCache cachePath binaryZip destinationPath objectName verbose = -- | Carthage only, not necessary for PodBuilder saveVersionFilesToLocalCache :: FilePath -- ^ The cache definition. - -> [ProjectNameAndVersion] -- ^ The information used to derive the name and path for the .version file. + -> InvertedRepositoryMap -- ^ The map used to resolve `FrameworkName`s to `GitRepoName`s. + -> [FrameworkVector] -- ^ The information used to derive the name and path for the .version file. -> ReaderT (CachePrefix, Bool) IO () -saveVersionFilesToLocalCache lCacheDir = - mapM_ (saveVersonFileToLocalCache lCacheDir) +saveVersionFilesToLocalCache lCacheDir reverseRomeMap = + mapM_ (saveVersonFileToLocalCache lCacheDir reverseRomeMap) @@ -132,22 +135,24 @@ saveVersionFilesToLocalCache lCacheDir = -- | Carthage only, not necessary for PodBuilder saveVersonFileToLocalCache :: FilePath -- ^ The cache definition. - -> ProjectNameAndVersion -- ^ The information used to derive the name and path for the .version file. + -> InvertedRepositoryMap -- ^ The map used to resolve `FrameworkName`s to `GitRepoName`s. + -> FrameworkVector -- ^ The information used to derive the name and path for the .version file. -> ReaderT (CachePrefix, Bool) IO () -saveVersonFileToLocalCache lCacheDir projectNameAndVersion = do - (cachePrefix, verbose) <- ask - versionFileExists <- liftIO $ doesFileExist versionFileLocalPath - - when versionFileExists $ do - versionFileContent <- liftIO $ LBS.readFile versionFileLocalPath - saveVersionFileBinaryToLocalCache lCacheDir - cachePrefix - versionFileContent - projectNameAndVersion - verbose - where - versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion - versionFileLocalPath = carthageBuildDirectory versionFileName +saveVersonFileToLocalCache lCacheDir reverseRomeMap fVector = do + case temp_versionFileLocalPath reverseRomeMap fVector of + Just versionFileLocalPath -> do + (cachePrefix, verbose) <- ask + versionFileExists <- liftIO $ doesFileExist versionFileLocalPath + + when versionFileExists $ do + versionFileContent <- liftIO $ LBS.readFile versionFileLocalPath + saveVersionFileBinaryToLocalCache lCacheDir + cachePrefix + versionFileContent + reverseRomeMap + fVector + verbose + _ -> pure mempty @@ -158,14 +163,16 @@ saveVersionFileBinaryToLocalCache => FilePath -- ^ The destinationf file. -> CachePrefix -- ^ A prefix for folders at top level in the cache. -> LBS.ByteString -- ^ The contents of the .version file - -> ProjectNameAndVersion -- ^ The information used to derive the name and path for the .version file. + -> InvertedRepositoryMap -- ^ The map used to resolve `FrameworkName`s to `GitRepoName`s. + -> FrameworkVector -- ^ The information used to derive the name and path for the .version file. -> Bool -- ^ A flag controlling verbosity. -> m () -saveVersionFileBinaryToLocalCache lCacheDir (CachePrefix prefix) versionFileContent projectNameAndVersion - = saveBinaryToLocalCache lCacheDir - versionFileContent - (prefix versionFileRemotePath) - versionFileName - where - versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion - versionFileRemotePath = remoteVersionFilePath projectNameAndVersion +saveVersionFileBinaryToLocalCache lCacheDir (CachePrefix prefix) versionFileContent reverseRomeMap fVector + = case temp_versionFileRemotePath reverseRomeMap fVector of + Just versionFileRemotePath -> do + saveBinaryToLocalCache lCacheDir + versionFileContent + (prefix versionFileRemotePath) + verboseDebugName + where verboseDebugName = takeFileName $ versionFileRemotePath + _ -> liftIO . mempty diff --git a/src/Caches/S3/Uploading.hs b/src/Caches/S3/Uploading.hs index 92c097e..f5f5c9c 100644 --- a/src/Caches/S3/Uploading.hs +++ b/src/Caches/S3/Uploading.hs @@ -13,7 +13,9 @@ import Data.Romefile ( Framework(..) ) import qualified Data.Text as T import qualified Network.AWS as AWS import qualified Network.AWS.S3 as S3 -import System.FilePath ( () ) +import System.FilePath ( () + , takeFileName + ) import Types hiding ( version ) import Utils import Xcode.DWARF @@ -100,19 +102,25 @@ uploadBcsymbolmapToS3 dwarfUUID dwarfArchive s3BucketName reverseRomeMap fVector uploadVersionFileToS3 :: S3.BucketName -- ^ The cache definition. -> LBS.ByteString -- ^ The contents of the .version file. - -> ProjectNameAndVersion -- ^ The information used to derive the name and path for the .version file. + -> InvertedRepositoryMap -- ^ The map used to resolve `FrameworkName`s to `GitRepoName`s. + -> FrameworkVector -- ^ The information used to derive the name and path for the .version file. -> ReaderT (AWS.Env, CachePrefix, Bool) IO () -uploadVersionFileToS3 s3BucketName versionFileContent projectNameAndVersion = +uploadVersionFileToS3 s3BucketName versionFileContent reverseRomeMap fVector = do - (env, CachePrefix prefix, verbose) <- ask - withReaderT (const (env, verbose)) $ uploadBinary - s3BucketName - versionFileContent - (prefix versionFileRemotePath) - versionFileName - where - versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion - versionFileRemotePath = remoteVersionFilePath projectNameAndVersion + case + ( temp_versionFileLocalPath reverseRomeMap fVector + , temp_versionFileRemotePath reverseRomeMap fVector + ) + of + (Just versionFileLocalPath, Just versionFileRemotePath) -> do + (env, CachePrefix prefix, verbose) <- ask + withReaderT (const (env, verbose)) $ uploadBinary + s3BucketName + versionFileContent + (prefix versionFileRemotePath) + verboseDebugName + where verboseDebugName = takeFileName $ versionFileLocalPath + _ -> pure mempty diff --git a/src/Lib.hs b/src/Lib.hs index a097bc3..43449ee 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -557,7 +557,8 @@ uploadArtifacts buildTypeConfig mS3BucketName mlCacheDir reverseRepositoryMap fr CarthageConfig{} -> runReaderT (uploadVersionFilesToCaches s3BucketName lCacheDir - gitRepoNamesAndVersions + reverseRepositoryMap + frameworkVectors ) uploadDownloadEnv PodBuilderConfig{} -> mempty -- PodBuilder does not have .version files, rather PodBuilder.plist files that are part of the .framework @@ -577,18 +578,14 @@ uploadArtifacts buildTypeConfig mS3BucketName mlCacheDir reverseRepositoryMap fr platforms ) readerEnv - >> case buildTypeConfig of - CarthageConfig{} -> do - runReaderT - (saveVersionFilesToLocalCache lCacheDir gitRepoNamesAndVersions) - readerEnv - PodBuilderConfig{} -> mempty -- PodBuilder does not have .version files, rather PodBuilder.plist files that are part of the .framework + >> runReaderT + (saveVersionFilesToLocalCache lCacheDir + reverseRepositoryMap + frameworkVectors + ) + readerEnv + (Nothing, Nothing) -> throwError bothCacheKeysMissingMessage - where - gitRepoNamesAndVersions :: [ProjectNameAndVersion] - gitRepoNamesAndVersions = repoNamesAndVersionForFrameworkVectors - reverseRepositoryMap - frameworkVectors @@ -597,10 +594,11 @@ uploadArtifacts buildTypeConfig mS3BucketName mlCacheDir reverseRepositoryMap fr uploadVersionFilesToCaches :: S3.BucketName -- ^ The cache definition. -> Maybe FilePath -- ^ Just the path to the local cache or Nothing. - -> [ProjectNameAndVersion] -- ^ A list of `ProjectName` and `Version` 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 () -uploadVersionFilesToCaches s3Bucket mlCacheDir = - mapM_ (uploadVersionFileToCaches s3Bucket mlCacheDir) +uploadVersionFilesToCaches s3Bucket mlCacheDir reverseRomeMap = + mapM_ (uploadVersionFileToCaches s3Bucket mlCacheDir reverseRomeMap) @@ -609,33 +607,35 @@ uploadVersionFilesToCaches s3Bucket mlCacheDir = uploadVersionFileToCaches :: S3.BucketName -- ^ The cache definition. -> Maybe FilePath -- ^ Just the path to the local cache or Nothing. - -> ProjectNameAndVersion -- ^ The information used to derive the name and path for the .version file. + -> 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 () -uploadVersionFileToCaches s3BucketName mlCacheDir projectNameAndVersion = do - (env, cachePrefix, SkipLocalCacheFlag skipLocalCache, _, verbose) <- ask - - versionFileExists <- liftIO $ doesFileExist versionFileLocalPath - - when versionFileExists $ do - versionFileContent <- liftIO $ LBS.readFile versionFileLocalPath - unless skipLocalCache - $ maybe (return ()) liftIO - $ saveVersionFileBinaryToLocalCache - <$> mlCacheDir - <*> Just cachePrefix - <*> Just versionFileContent - <*> Just projectNameAndVersion - <*> Just verbose - liftIO $ runReaderT - (uploadVersionFileToS3 s3BucketName - versionFileContent - projectNameAndVersion - ) - (env, cachePrefix, verbose) - where - - versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion - versionFileLocalPath = carthageBuildDirectory versionFileName +uploadVersionFileToCaches s3BucketName mlCacheDir reverseRomeMap fVector = do + case (temp_versionFileLocalPath reverseRomeMap fVector) of + Just versionFileLocalPath -> do + (env, cachePrefix, SkipLocalCacheFlag skipLocalCache, _, verbose) <- ask + + versionFileExists <- liftIO $ doesFileExist versionFileLocalPath + + when versionFileExists $ do + versionFileContent <- liftIO $ LBS.readFile versionFileLocalPath + unless skipLocalCache + $ maybe (return ()) liftIO + $ saveVersionFileBinaryToLocalCache + <$> mlCacheDir + <*> Just cachePrefix + <*> Just versionFileContent + <*> Just reverseRomeMap + <*> Just fVector + <*> Just verbose + liftIO $ runReaderT + (uploadVersionFileToS3 s3BucketName + versionFileContent + reverseRomeMap + fVector + ) + (env, cachePrefix, verbose) + _ -> pure mempty diff --git a/src/Utils.hs b/src/Utils.hs index 33a20d7..d682480 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -6,7 +6,9 @@ module Utils where import qualified Codec.Archive.Zip as Zip -import Configuration (artifactsBuildDirectoryForPlatform) +import Configuration ( artifactsBuildDirectoryForPlatform + , carthageBuildDirectory + ) import Control.Applicative ( (<|>) ) import Control.Arrow (left) import Control.Exception as E (try) @@ -374,6 +376,10 @@ remoteCacheDirectory p r f = repoName show p ++ "/" -- | `ProjectNameAndVersion` remoteVersionFilePath :: ProjectNameAndVersion -> String remoteVersionFilePath (projectName, version) = + remoteVersionFilePath' projectName version + +remoteVersionFilePath' :: ProjectName -> Version -> String +remoteVersionFilePath' projectName version = unProjectName projectName versionFileNameForProjectNameVersioned projectName version @@ -925,3 +931,28 @@ temp_remoteBcSymbolmapPath platform reverseRomeMap fVector dwarfUUID reverseRomeMap (_framework $ _vectorFrameworkVersion fVector) (_frameworkVersion $ _vectorFrameworkVersion fVector) + + +-- TODO Nothing for PodBuilder +temp_versionFileLocalPath + :: InvertedRepositoryMap -> FrameworkVector -> Maybe FilePath +temp_versionFileLocalPath reverseRomeMap fVector = + Just $ carthageBuildDirectory versionFileName + where + projectName = + repoNameForFrameworkName reverseRomeMap + $ _framework + $ _vectorFrameworkVersion fVector + versionFileName = versionFileNameForProjectName projectName + +-- TODO Nothing for PodBuilder +temp_versionFileRemotePath + :: InvertedRepositoryMap -> FrameworkVector -> Maybe FilePath +temp_versionFileRemotePath reverseRomeMap fVector = + Just $ remoteVersionFilePath' projectName version + where + projectName = + repoNameForFrameworkName reverseRomeMap + $ _framework + $ _vectorFrameworkVersion fVector + version = (_frameworkVersion $ _vectorFrameworkVersion fVector)