From 72315e003857e2a6c6e5904716d440925990ec21 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferrai Date: Mon, 22 Feb 2021 14:38:09 +0100 Subject: [PATCH] Backport some fixes from compiling with GHC 8.10 (#748) --- src/Spago/Command/Ls.hs | 4 ++-- src/Spago/Config.hs | 4 ++-- src/Spago/FetchPackage.hs | 8 ++++---- src/Spago/PackageSet.hs | 7 ------- src/Spago/Purs.hs | 2 +- test/BumpVersionSpec.hs | 1 + test/SpagoSpec.hs | 6 +----- 7 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/Spago/Command/Ls.hs b/src/Spago/Command/Ls.hs index d9bf0f1c8..c5b2fa197 100644 --- a/src/Spago/Command/Ls.hs +++ b/src/Spago/Command/Ls.hs @@ -65,13 +65,13 @@ formatPackageNames = \case formatPackageNamesJson :: [(PackageName, Package)] -> [Text] formatPackageNamesJson pkgs = let - asJson (PackageName{..}, Package{ location = loc@Remote{..}, ..}) + asJson (PackageName{..}, Package{ location = loc@Remote{..} }) = JsonPackageOutput { json_packageName = packageName , json_repo = toJSON loc , json_version = version } - asJson (PackageName{..}, Package { location = loc@Local{..}, ..}) + asJson (PackageName{..}, Package { location = loc@(Local _), ..}) = JsonPackageOutput { json_packageName = packageName , json_repo = toJSON loc diff --git a/src/Spago/Config.hs b/src/Spago/Config.hs index cda08ae8e..8b0e617e7 100644 --- a/src/Spago/Config.hs +++ b/src/Spago/Config.hs @@ -71,7 +71,7 @@ parsePackage (Dhall.RecordLit ks') = do let location = Remote{..} pure Package{..} parsePackage (Dhall.App - (Dhall.Field union (Dhall.FieldSelection { fieldSelectionLabel = "Local", ..})) + (Dhall.Field union (Dhall.FieldSelection { fieldSelectionLabel = "Local" })) (Dhall.TextLit (Dhall.Chunks [] spagoConfigPath))) | isLocationType union = do localPath <- case Text.isSuffixOf "/spago.dhall" spagoConfigPath of @@ -272,7 +272,7 @@ migrateBower Bower.PackageMeta{..} PackageSet{..} = (packageName, dependencies) Nothing -> Left $ NonPureScript name Just packageSetName | package <- PackageName packageSetName -> case Map.lookup package packagesDB of Nothing -> Left $ MissingFromTheSet package - Just Package{ location = Local {..} } -> Right package + Just Package{ location = Local _ } -> Right package Just Package{ location = Remote {..} } -> case SemVer.parseSemVer version of Right v | SemVer.matches range v -> Right package _ -> Left $ WrongVersion package range version diff --git a/src/Spago/FetchPackage.hs b/src/Spago/FetchPackage.hs index 8ecef33c0..37a46d701 100644 --- a/src/Spago/FetchPackage.hs +++ b/src/Spago/FetchPackage.hs @@ -96,9 +96,9 @@ fetchPackage . (HasLogFunc env, HasGlobalCache env) => GlobalCache.ReposMetadataV1 -> (PackageName, Package) -> RIO env () -fetchPackage _ (PackageName package, Package { location = Local{..}, .. }) = +fetchPackage _ (PackageName package, Package { location = Local{..} }) = logInfo $ display $ Messages.foundLocalPackage package localPath -fetchPackage metadata pair@(packageName'@PackageName{..}, Package{ location = Remote{..}, .. } ) = do +fetchPackage metadata pair@(packageName'@PackageName{..}, Package{ location = Remote{..} } ) = do logDebug $ "Fetching package " <> display packageName GlobalCache globalCacheDir cacheFlag <- view (the @GlobalCache) let useGlobalCache = cacheFlag /= Just SkipCache @@ -194,9 +194,9 @@ getPackageDir PackageName{..} version = Text.unpack packageName <> "/" <> Text.u -- If the package is from a remote git repo, return the folder inside the local cache -- Otherwise return the local folder getLocalCacheDir :: (PackageName, Package) -> FilePath.FilePath -getLocalCacheDir (packageName, Package{ location = Remote{..}, .. }) = do +getLocalCacheDir (packageName, Package{ location = Remote{..} }) = do localCacheDir <> "/" <> getPackageDir packageName version -getLocalCacheDir (_, Package{ location = Local{..}, .. }) = +getLocalCacheDir (_, Package{ location = Local{..} }) = Text.unpack localPath diff --git a/src/Spago/PackageSet.hs b/src/Spago/PackageSet.hs index 544fefb7e..aef45b978 100644 --- a/src/Spago/PackageSet.hs +++ b/src/Spago/PackageSet.hs @@ -158,11 +158,8 @@ updatePackageSetVersion maybeTag = do , directory = Dhall.Directory { components = [ currentTag, "download", "releases", repo, org ]} } - , .. } - , .. } - , .. } = [(org, repo, currentTag)] getCurrentTag _ = [] @@ -177,11 +174,9 @@ updatePackageSetVersion maybeTag = do { file = "packages.dhall" , directory = Dhall.Directory { components = [ _currentTag, "download", "releases", upgradeRepo, upgradeOrg ]} - , .. } , .. } - , .. } , .. }) | upgradeRepo == repo && upgradeOrg == org = @@ -234,9 +229,7 @@ isRemoteFrozen (Dhall.Import { importHashed = Dhall.ImportHashed { importType = Dhall.Remote _ , hash - , .. } - , .. }) = [isJust hash] isRemoteFrozen _ = [] diff --git a/src/Spago/Purs.hs b/src/Spago/Purs.hs index c2a9c8282..faa010a62 100644 --- a/src/Spago/Purs.hs +++ b/src/Spago/Purs.hs @@ -104,7 +104,7 @@ docs format sourcePaths = do pursVersion :: RIO env (Either Text Version.SemVer) pursVersion = Turtle.Bytes.shellStrictWithErr (purs <> " --version") empty >>= \case (ExitSuccess, out, _err) -> do - let versionText = headMay $ Text.split (== ' ') (Text.Encoding.decodeUtf8With lenientDecode out) + let versionText = headMay $ Text.split (== ' ') (Text.strip $ Text.Encoding.decodeUtf8With lenientDecode out) parsed = versionText >>= (hush . Version.semver) pure $ case parsed of diff --git a/test/BumpVersionSpec.hs b/test/BumpVersionSpec.hs index c7cb05fe0..771fdb592 100644 --- a/test/BumpVersionSpec.hs +++ b/test/BumpVersionSpec.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE OverloadedLists #-} module BumpVersionSpec (spec) where import Data.Versions (SemVer (..), VUnit (..)) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 36b9d4b83..7b4ddc6e1 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -5,7 +5,7 @@ import qualified Data.Text as Text import Prelude hiding (FilePath) import qualified System.IO.Temp as Temp import Test.Hspec (Spec, around_, describe, it, shouldBe, shouldNotSatisfy, - shouldReturn, shouldSatisfy) + shouldNotBe, shouldReturn, shouldSatisfy) import Turtle (ExitCode (..), cd, cp, decodeString, empty, encodeString, mkdir, mktree, mv, pwd, readTextFile, rm, shell, shellStrictWithErr, testdir, writeTextFile, ()) @@ -607,9 +607,6 @@ spec = around_ setup $ do newPackages <- Text.strip <$> readTextFile "packages.dhall" newPackages `shouldBe` packageSetUrl - {- - -- Note: this is commented because of https://github.com/purescript/spago/issues/685#issuecomment-694342262 - it "Spago should migrate a package set from an alternative repository from src/packages.dhall" $ do spago ["init"] >>= shouldBeSuccess @@ -618,7 +615,6 @@ spec = around_ setup $ do newPackages <- Text.strip <$> readTextFile "packages.dhall" newPackages `shouldNotBe` "https://github.com/purerl/package-sets/releases/download/erl-0.13.6-20200713/packages.dhall" newPackages `shouldSatisfy` Text.isPrefixOf "https://github.com/purerl/package-sets/releases/download" - -} it "Spago should migrate package-set from src/packages.dhall to the user-specified one if it exists" $ do -- initialize the project, so that it uses latest package set release