mirror of
https://github.com/gren-lang/compiler.git
synced 2024-08-16 12:00:22 +03:00
Move helper function to seperate module, as it's useful in several places. Also remove redundant imports from several modules.
This commit is contained in:
parent
9c0cd44ef4
commit
9ae28f538d
@ -18,8 +18,6 @@ import qualified Data.List as List
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Name as Name
|
||||
import qualified Data.Set as Set
|
||||
import qualified System.Directory as Dir
|
||||
import System.FilePath ((</>))
|
||||
|
||||
import qualified Elm.Compiler.Type as Type
|
||||
import qualified Elm.Docs as Docs
|
||||
@ -27,9 +25,6 @@ import qualified Elm.Magnitude as M
|
||||
import qualified Elm.ModuleName as ModuleName
|
||||
import qualified Elm.Package as Pkg
|
||||
import qualified Elm.Version as V
|
||||
import qualified File
|
||||
import qualified Json.Decode as D
|
||||
import qualified Reporting.Exit as Exit
|
||||
import qualified Directories as Dirs
|
||||
|
||||
|
||||
@ -354,6 +349,6 @@ changeMagnitude (Changes added changed removed) =
|
||||
|
||||
|
||||
getDocs :: Dirs.PackageCache -> Pkg.Name -> V.Version -> IO (Either () Docs.Documentation)
|
||||
getDocs cache name version =
|
||||
getDocs _ _ _ =
|
||||
-- TODO: Implement using local git clones
|
||||
return $ Right Docs.tmpEmpty
|
||||
|
30
builder/src/Deps/Package.hs
Normal file
30
builder/src/Deps/Package.hs
Normal file
@ -0,0 +1,30 @@
|
||||
module Deps.Package
|
||||
( getVersions
|
||||
)
|
||||
where
|
||||
|
||||
|
||||
import qualified System.Directory as Dir
|
||||
|
||||
import qualified Elm.Package as Pkg
|
||||
import qualified Elm.Version as V
|
||||
import qualified Git
|
||||
import qualified Directories as Dirs
|
||||
|
||||
|
||||
|
||||
getVersions :: Dirs.PackageCache -> Pkg.Name -> IO (Either Git.Error (V.Version, [V.Version]))
|
||||
getVersions cache name = do
|
||||
let repoPath = Dirs.basePackage cache name
|
||||
repoExists <- Dir.doesDirectoryExist repoPath
|
||||
retVal <-
|
||||
if repoExists then
|
||||
Git.update name repoPath
|
||||
else
|
||||
Git.clone (Git.githubUrl name) repoPath
|
||||
case retVal of
|
||||
Left problem ->
|
||||
return $ Left problem
|
||||
|
||||
Right () ->
|
||||
Git.tags repoPath
|
@ -16,10 +16,8 @@ module Deps.Solver
|
||||
|
||||
|
||||
import Control.Monad (foldM)
|
||||
import Control.Concurrent (forkIO, newEmptyMVar, putMVar, readMVar)
|
||||
import qualified Data.Map as Map
|
||||
import Data.Map ((!))
|
||||
import qualified System.Directory as Dir
|
||||
import System.FilePath ((</>))
|
||||
|
||||
import qualified Elm.Constraint as C
|
||||
@ -31,6 +29,7 @@ import qualified Git
|
||||
import qualified Json.Decode as D
|
||||
import qualified Reporting.Exit as Exit
|
||||
import qualified Directories as Dirs
|
||||
import qualified Deps.Package as Package
|
||||
|
||||
|
||||
|
||||
@ -244,8 +243,8 @@ addConstraint solved unsolved (name, newConstraint) =
|
||||
getRelevantVersions :: Pkg.Name -> C.Constraint -> Solver (V.Version, [V.Version])
|
||||
getRelevantVersions name constraint =
|
||||
Solver $ \state@(State cache _) ok back err -> do
|
||||
maybeVersions <- getRelevantVersionsHelper cache name
|
||||
case maybeVersions of
|
||||
versionsResult <- Package.getVersions cache name
|
||||
case versionsResult of
|
||||
Right (newest, previous) ->
|
||||
case filter (C.satisfies constraint) (newest:previous) of
|
||||
[] -> back state
|
||||
@ -255,22 +254,6 @@ getRelevantVersions name constraint =
|
||||
err $ Exit.SolverBadGitOperationUnversionedPkg name gitErr
|
||||
|
||||
|
||||
getRelevantVersionsHelper :: Dirs.PackageCache -> Pkg.Name -> IO (Either Git.Error (V.Version, [V.Version]))
|
||||
getRelevantVersionsHelper cache name = do
|
||||
let repoPath = Dirs.basePackage cache name
|
||||
repoExists <- Dir.doesDirectoryExist repoPath
|
||||
retVal <-
|
||||
if repoExists then
|
||||
Git.update name repoPath
|
||||
else
|
||||
Git.clone (Git.githubUrl name) repoPath
|
||||
case retVal of
|
||||
Left problem ->
|
||||
return $ Left problem
|
||||
|
||||
Right () ->
|
||||
Git.tags repoPath
|
||||
|
||||
|
||||
-- GET CONSTRAINTS
|
||||
|
||||
|
@ -27,9 +27,7 @@ import qualified Data.Name as Name
|
||||
import qualified Data.NonEmptyList as NE
|
||||
import qualified Data.OneOrMore as OneOrMore
|
||||
import qualified Data.Set as Set
|
||||
import qualified Data.Utf8 as Utf8
|
||||
import Data.Word (Word64)
|
||||
import qualified System.Directory as Dir
|
||||
import System.FilePath ((</>), (<.>))
|
||||
|
||||
import qualified AST.Canonical as Can
|
||||
@ -47,7 +45,6 @@ import qualified Elm.Outline as Outline
|
||||
import qualified Elm.Package as Pkg
|
||||
import qualified Elm.Version as V
|
||||
import qualified File
|
||||
import qualified Json.Decode as D
|
||||
import qualified Json.Encode as E
|
||||
import qualified Parse.Module as Parse
|
||||
import qualified Reporting
|
||||
|
@ -19,16 +19,14 @@ import qualified Data.Binary as Binary
|
||||
import qualified Data.ByteString as BS
|
||||
import qualified Data.ByteString.Internal as BS
|
||||
import qualified Data.ByteString.Builder as B
|
||||
import qualified Data.ByteString.Lazy as LBS
|
||||
import qualified Data.Fixed as Fixed
|
||||
import qualified Data.List as List
|
||||
import qualified Data.Time.Clock as Time
|
||||
import qualified Data.Time.Clock.POSIX as Time
|
||||
import qualified Foreign.ForeignPtr as FPtr
|
||||
import GHC.IO.Exception (IOException, IOErrorType(InvalidArgument))
|
||||
import qualified System.Directory as Dir
|
||||
import qualified System.FilePath as FP
|
||||
import System.FilePath ((</>))
|
||||
import System.FilePath ()
|
||||
import qualified System.IO as IO
|
||||
import System.IO.Error (ioeGetErrorType, annotateIOError, modifyIOError)
|
||||
|
||||
|
@ -72,7 +72,7 @@ clone (GitUrl (pkgName, gitUrl)) targetFolder = do
|
||||
let args = [ "clone" , "--bare", gitUrl, targetFolder ]
|
||||
(exitCode, _, stderr) <-
|
||||
Process.readCreateProcessWithExitCode
|
||||
(Process.proc "git" args)
|
||||
(Process.proc git args)
|
||||
""
|
||||
case exitCode of
|
||||
Exit.ExitFailure _ -> do
|
||||
@ -159,12 +159,12 @@ tags path = do
|
||||
|
||||
Exit.ExitSuccess ->
|
||||
let
|
||||
tags =
|
||||
tagList =
|
||||
map BS.pack $ lines stdout
|
||||
|
||||
-- Ignore tags that aren't semantic versions
|
||||
versions =
|
||||
Either.rights $ map (Parser.fromByteString V.parser (,)) tags
|
||||
Either.rights $ map (Parser.fromByteString V.parser (,)) tagList
|
||||
in
|
||||
case versions of
|
||||
[] -> return $ Left $ NoVersions path
|
||||
|
@ -41,7 +41,7 @@ import qualified Elm.ModuleName as ModuleName
|
||||
import qualified Elm.Package as Pkg
|
||||
import qualified Elm.Version as V
|
||||
import qualified Json.Encode as Encode
|
||||
import Reporting.Doc ((<+>), (<>))
|
||||
import Reporting.Doc ((<+>))
|
||||
import qualified Reporting.Doc as D
|
||||
import qualified Reporting.Exit as Exit
|
||||
import qualified Reporting.Exit.Help as Help
|
||||
|
@ -27,7 +27,6 @@ module Reporting.Exit
|
||||
|
||||
|
||||
import qualified Data.ByteString as BS
|
||||
import qualified Data.ByteString.UTF8 as BS_UTF8
|
||||
import qualified Data.List as List
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Name as N
|
||||
@ -47,7 +46,6 @@ import qualified Json.Encode as Encode
|
||||
import qualified Json.String as Json
|
||||
import Parse.Primitives (Row, Col)
|
||||
import qualified Reporting.Annotation as A
|
||||
import Reporting.Doc ((<>))
|
||||
import qualified Reporting.Doc as D
|
||||
import qualified Reporting.Error.Import as Import
|
||||
import qualified Reporting.Error.Json as Json
|
||||
@ -1220,7 +1218,7 @@ toGitErrorReport title err context =
|
||||
, D.indent 4 $ D.reflow errorMsg
|
||||
]
|
||||
|
||||
Git.NoVersions path ->
|
||||
Git.NoVersions _ ->
|
||||
toGitReport (context ++ ", no valid semantic version tags in this repo.")
|
||||
[ D.reflow "Gren packages are just git repositories with tags following the \
|
||||
\ semantic versioning scheme. However, it seems that this particular repo \
|
||||
|
@ -46,11 +46,7 @@ import qualified Data.String as Chars
|
||||
import qualified Data.Utf8 as Utf8
|
||||
import GHC.Exts
|
||||
( Int(I#), Ptr
|
||||
, MutableByteArray#
|
||||
, isTrue#
|
||||
, newByteArray#
|
||||
, sizeofByteArray#
|
||||
, unsafeFreezeByteArray#
|
||||
)
|
||||
import GHC.ST (ST(ST), runST)
|
||||
import GHC.Prim
|
||||
|
@ -49,16 +49,7 @@ import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
|
||||
import Foreign.Ptr (minusPtr, plusPtr)
|
||||
import GHC.Exts
|
||||
( Int(I#), Ptr(Ptr), Char(C#)
|
||||
, RealWorld
|
||||
, ByteArray#, MutableByteArray#
|
||||
, isTrue#
|
||||
, newByteArray#
|
||||
, unsafeFreezeByteArray#
|
||||
, sizeofByteArray#
|
||||
, copyByteArray#
|
||||
, copyAddrToByteArray#
|
||||
, copyByteArrayToAddr#
|
||||
, writeWord8Array#
|
||||
)
|
||||
import GHC.IO
|
||||
import GHC.ST (ST(ST), runST)
|
||||
|
@ -34,7 +34,6 @@ import qualified Data.Coerce as Coerce
|
||||
import qualified Data.List as List
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Name as Name
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Data.Utf8 as Utf8
|
||||
import Data.Word (Word8)
|
||||
import Foreign.Ptr (Ptr, plusPtr, minusPtr)
|
||||
|
@ -7,7 +7,6 @@ module Generate.Html
|
||||
|
||||
|
||||
import qualified Data.ByteString.Builder as B
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Data.Name as Name
|
||||
import Text.RawString.QQ (r)
|
||||
|
||||
|
@ -9,7 +9,6 @@ module Generate.JavaScript
|
||||
|
||||
import Prelude hiding (cycle, print)
|
||||
import qualified Data.ByteString.Builder as B
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Data.List as List
|
||||
import Data.Map ((!))
|
||||
import qualified Data.Map as Map
|
||||
|
@ -18,7 +18,6 @@ import Prelude hiding (lines)
|
||||
import qualified Data.List as List
|
||||
import qualified Data.ByteString as BS
|
||||
import Data.ByteString.Builder as B
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Generate.JavaScript.Name as Name
|
||||
import Generate.JavaScript.Name (Name)
|
||||
import qualified Json.Encode as Json
|
||||
|
@ -19,7 +19,6 @@ module Generate.JavaScript.Name
|
||||
|
||||
|
||||
import qualified Data.ByteString.Builder as B
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Name as Name
|
||||
import qualified Data.Set as Set
|
||||
|
@ -28,7 +28,6 @@ import qualified Data.ByteString.Char8 as BSC
|
||||
import qualified Data.ByteString.Builder as B
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Scientific as Sci
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Data.Name as Name
|
||||
import qualified Data.Utf8 as Utf8
|
||||
|
||||
|
@ -46,7 +46,6 @@ module Reporting.Doc
|
||||
|
||||
import Prelude hiding (cycle)
|
||||
import qualified Data.List as List
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Data.Name as Name
|
||||
import qualified System.Console.ANSI.Types as Ansi
|
||||
import qualified System.Info as Info
|
||||
@ -348,6 +347,8 @@ sgrToStyle sgrs style@(Style bold underline color) =
|
||||
Ansi.SetSwapForegroundBackground _ -> style
|
||||
Ansi.SetColor l i c -> Style bold underline (toColor l i c)
|
||||
Ansi.SetRGBColor _ _ -> style
|
||||
Ansi.SetPaletteColor _ _ -> style
|
||||
Ansi.SetDefaultColor _ -> style
|
||||
|
||||
|
||||
isBold :: Ansi.ConsoleIntensity -> Bool
|
||||
|
@ -26,7 +26,7 @@ import qualified Data.Index as Index
|
||||
import qualified Elm.ModuleName as ModuleName
|
||||
import qualified Reporting.Annotation as A
|
||||
import qualified Reporting.Doc as D
|
||||
import Reporting.Doc (Doc, (<+>), (<>))
|
||||
import Reporting.Doc (Doc, (<+>))
|
||||
import qualified Reporting.Render.Code as Code
|
||||
import qualified Reporting.Render.Type as RT
|
||||
import qualified Reporting.Report as Report
|
||||
|
@ -16,7 +16,6 @@ import qualified Data.NonEmptyList as NE
|
||||
import Parse.Primitives (Row, Col)
|
||||
import Parse.Symbol (BadOperator(..))
|
||||
import qualified Reporting.Annotation as A
|
||||
import Reporting.Doc ((<>))
|
||||
import qualified Reporting.Doc as D
|
||||
import qualified Reporting.Render.Code as Code
|
||||
import qualified Reporting.Error.Syntax as E
|
||||
|
@ -10,7 +10,6 @@ import qualified Data.List as List
|
||||
|
||||
import qualified Elm.String as ES
|
||||
import qualified Nitpick.PatternMatches as P
|
||||
import Reporting.Doc ((<>))
|
||||
import qualified Reporting.Doc as D
|
||||
import qualified Reporting.Report as Report
|
||||
import qualified Reporting.Render.Code as Code
|
||||
|
@ -21,7 +21,6 @@ module Reporting.Error.Type
|
||||
|
||||
import Prelude hiding (round)
|
||||
import qualified Data.Map as Map
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Data.Name as Name
|
||||
|
||||
import qualified AST.Canonical as Can
|
||||
|
@ -21,7 +21,7 @@ import qualified AST.Source as Src
|
||||
import qualified AST.Canonical as Can
|
||||
import qualified Reporting.Annotation as A
|
||||
import qualified Reporting.Doc as D
|
||||
import Reporting.Doc ( Doc, (<+>), (<>) )
|
||||
import Reporting.Doc ( Doc, (<+>) )
|
||||
import qualified Reporting.Render.Type.Localizer as L
|
||||
|
||||
|
||||
|
@ -17,7 +17,6 @@ import qualified Data.Set as Set
|
||||
|
||||
import qualified AST.Source as Src
|
||||
import qualified Elm.ModuleName as ModuleName
|
||||
import Reporting.Doc ((<>))
|
||||
import qualified Reporting.Doc as D
|
||||
import qualified Reporting.Annotation as A
|
||||
|
||||
|
@ -8,7 +8,6 @@ module Reporting.Warning
|
||||
where
|
||||
|
||||
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Data.Name as Name
|
||||
|
||||
import qualified AST.Canonical as Can
|
||||
|
@ -20,7 +20,6 @@ module Type.Error
|
||||
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Maybe as Maybe
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Data.Name as Name
|
||||
|
||||
import qualified Data.Bag as Bag
|
||||
|
@ -78,6 +78,7 @@ Executable gren
|
||||
Build
|
||||
BackgroundWriter
|
||||
Deps.Diff
|
||||
Deps.Package
|
||||
Deps.Solver
|
||||
File
|
||||
Generate
|
||||
|
@ -12,7 +12,6 @@ module Terminal.Error
|
||||
where
|
||||
|
||||
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Data.List as List
|
||||
import qualified Data.Maybe as Maybe
|
||||
import GHC.IO.Handle (hIsTerminalDevice)
|
||||
|
@ -9,8 +9,6 @@ module Terminal.Helpers
|
||||
|
||||
import qualified Data.ByteString.UTF8 as BS_UTF8
|
||||
import qualified Data.Char as Char
|
||||
import qualified Data.List as List
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Utf8 as Utf8
|
||||
import qualified System.FilePath as FP
|
||||
|
||||
@ -18,8 +16,6 @@ import Terminal (Parser(..))
|
||||
import qualified Elm.Package as Pkg
|
||||
import qualified Elm.Version as V
|
||||
import qualified Parse.Primitives as P
|
||||
import qualified Directories as Dirs
|
||||
import qualified Reporting.Suggest as Suggest
|
||||
|
||||
|
||||
|
||||
|
@ -9,7 +9,6 @@ module Develop.Generate.Help
|
||||
|
||||
|
||||
import qualified Data.ByteString.Builder as B
|
||||
import Data.Monoid ((<>))
|
||||
import qualified Data.Name as Name
|
||||
import Text.RawString.QQ (r)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user