Skip to content

Commit

Permalink
introduce temp_versionFileLocalPath and temp_versionFileRemotePath wh…
Browse files Browse the repository at this point in the history
…ich return Maybes instead of checking for buildTypeConfig in Lib - implemented for uploading
  • Loading branch information
fabb committed Mar 24, 2019
1 parent 52473ba commit 17a409d
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 82 deletions.
63 changes: 35 additions & 28 deletions src/Caches/Local/Uploading.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -121,33 +123,36 @@ 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)



-- | Saves a .version file to a local Cache
-- | 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



Expand All @@ -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
32 changes: 20 additions & 12 deletions src/Caches/S3/Uploading.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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



Expand Down
82 changes: 41 additions & 41 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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



Expand All @@ -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)



Expand All @@ -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



Expand Down
33 changes: 32 additions & 1 deletion src/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 17a409d

Please sign in to comment.