mirror of
https://github.com/sol/hpack.git
synced 2024-10-04 11:47:15 +03:00
Allow version constraint for source dependencies
This commit is contained in:
parent
65db9de3bb
commit
1c541ac940
@ -1366,7 +1366,7 @@ toBuildTool packageName_ executableNames = \ case
|
||||
(UnqualifiedBuildTool executable, v)
|
||||
| executable `elem` executableNames -> localBuildTool executable v
|
||||
| Just pkg <- lookup executable legacyTools -> legacyBuildTool pkg executable v
|
||||
| executable `elem` legacySystemTools, VersionConstraint c <- v -> legacySystemBuildTool executable c
|
||||
| executable `elem` legacySystemTools, DependencyVersion Nothing c <- v -> legacySystemBuildTool executable c
|
||||
| otherwise -> buildTool executable executable v
|
||||
where
|
||||
buildTool pkg executable v = return . Right $ (BuildTool pkg executable, v)
|
||||
|
@ -316,9 +316,7 @@ renderDependency :: (String, DependencyVersion) -> String
|
||||
renderDependency (name, version) = name ++ renderVersion version
|
||||
|
||||
renderVersion :: DependencyVersion -> String
|
||||
renderVersion version = case version of
|
||||
VersionConstraint c -> renderVersionConstraint c
|
||||
SourceDependency _ -> ""
|
||||
renderVersion (DependencyVersion _ c) = renderVersionConstraint c
|
||||
|
||||
renderVersionConstraint :: VersionConstraint -> String
|
||||
renderVersionConstraint version = case version of
|
||||
|
@ -59,7 +59,7 @@ instance FromValue BuildTools where
|
||||
fromCabal :: D.ExeDependency -> (ParseBuildTool, DependencyVersion)
|
||||
fromCabal (D.ExeDependency package executable version) = (
|
||||
QualifiedBuildTool (D.unPackageName package) (D.unUnqualComponentName executable)
|
||||
, VersionConstraint $ versionConstraintFromCabal version
|
||||
, DependencyVersion Nothing $ versionConstraintFromCabal version
|
||||
)
|
||||
|
||||
parseUnqualifiedBuildTool :: Monad m => Text -> m (ParseBuildTool, DependencyVersion)
|
||||
|
@ -43,4 +43,4 @@ parseDependency :: Monad m => String -> Text -> m (String, DependencyVersion)
|
||||
parseDependency subject = fmap fromCabal . cabalParse subject . T.unpack
|
||||
where
|
||||
fromCabal :: D.Dependency -> (String, DependencyVersion)
|
||||
fromCabal d = (D.unPackageName $ D.depPkgName d, VersionConstraint . versionConstraintFromCabal $ D.depVerRange d)
|
||||
fromCabal d = (D.unPackageName $ D.depPkgName d, DependencyVersion Nothing . versionConstraintFromCabal $ D.depVerRange d)
|
||||
|
@ -55,14 +55,12 @@ versionConstraint v = case v of
|
||||
_ -> typeMismatch "Null, Number, or String" v
|
||||
|
||||
anyVersion :: DependencyVersion
|
||||
anyVersion = VersionConstraint AnyVersion
|
||||
anyVersion = DependencyVersion Nothing AnyVersion
|
||||
|
||||
versionRange :: String -> DependencyVersion
|
||||
versionRange = VersionConstraint . VersionRange
|
||||
versionRange = DependencyVersion Nothing . VersionRange
|
||||
|
||||
data DependencyVersion =
|
||||
VersionConstraint VersionConstraint
|
||||
| SourceDependency SourceDependency
|
||||
data DependencyVersion = DependencyVersion (Maybe SourceDependency) VersionConstraint
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance FromValue DependencyVersion where
|
||||
@ -72,8 +70,8 @@ dependencyVersion :: Value -> Parser DependencyVersion
|
||||
dependencyVersion v = case v of
|
||||
Null -> return anyVersion
|
||||
Object o -> sourceDependency o
|
||||
Number n -> return (VersionConstraint $ numericVersionConstraint n)
|
||||
String s -> VersionConstraint <$> stringVersionConstraint s
|
||||
Number n -> return (DependencyVersion Nothing $ numericVersionConstraint n)
|
||||
String s -> DependencyVersion Nothing <$> stringVersionConstraint s
|
||||
_ -> typeMismatch "Null, Object, Number, or String" v
|
||||
|
||||
data SourceDependency = GitRef GitUrl GitRef (Maybe FilePath) | Local FilePath
|
||||
@ -99,7 +97,7 @@ sourceDependency o = let
|
||||
subdir :: Parser (Maybe FilePath)
|
||||
subdir = o .:? "subdir"
|
||||
|
||||
in SourceDependency <$> (local <|> git)
|
||||
in DependencyVersion . Just <$> (local <|> git) <*> pure AnyVersion
|
||||
|
||||
numericVersionConstraint :: Scientific -> VersionConstraint
|
||||
numericVersionConstraint n = VersionRange ("==" ++ version)
|
||||
|
@ -58,20 +58,20 @@ spec = do
|
||||
]
|
||||
|
||||
it "accepts source dependencies with a qualified name" $ do
|
||||
let source = GitRef "https://github.com/sol/hpack" "master" Nothing
|
||||
let source = Just (GitRef "https://github.com/sol/hpack" "master" Nothing)
|
||||
[yaml|
|
||||
- name: hpack:foo
|
||||
github: sol/hpack
|
||||
ref: master
|
||||
|] `shouldDecodeTo_` BuildTools [(QualifiedBuildTool "hpack" "foo", SourceDependency source)]
|
||||
|] `shouldDecodeTo_` BuildTools [(QualifiedBuildTool "hpack" "foo", DependencyVersion source AnyVersion)]
|
||||
|
||||
it "accepts source dependencies with an unqualified name" $ do
|
||||
let source = GitRef "https://github.com/sol/hpack" "master" Nothing
|
||||
let source = Just (GitRef "https://github.com/sol/hpack" "master" Nothing)
|
||||
[yaml|
|
||||
- name: hpack
|
||||
github: sol/hpack
|
||||
ref: master
|
||||
|] `shouldDecodeTo_` BuildTools [(UnqualifiedBuildTool "hpack", SourceDependency source)]
|
||||
|] `shouldDecodeTo_` BuildTools [(UnqualifiedBuildTool "hpack", DependencyVersion source AnyVersion)]
|
||||
|
||||
context "when parsing SystemBuildTools" $ do
|
||||
context "with a scalar" $ do
|
||||
|
@ -51,36 +51,36 @@ spec = do
|
||||
|] `shouldDecodeTo_` Dependencies [("hpack", versionRange ">=1.2.3.4 && <1.3")]
|
||||
|
||||
it "accepts git dependencies" $ do
|
||||
let source = GitRef "https://github.com/sol/hpack" "master" Nothing
|
||||
let source = Just (GitRef "https://github.com/sol/hpack" "master" Nothing)
|
||||
[yaml|
|
||||
- name: hpack
|
||||
git: https://github.com/sol/hpack
|
||||
ref: master
|
||||
|] `shouldDecodeTo_` Dependencies [("hpack", SourceDependency source)]
|
||||
|] `shouldDecodeTo_` Dependencies [("hpack", DependencyVersion source AnyVersion)]
|
||||
|
||||
it "accepts github dependencies" $ do
|
||||
let source = GitRef "https://github.com/sol/hpack" "master" Nothing
|
||||
let source = Just (GitRef "https://github.com/sol/hpack" "master" Nothing)
|
||||
[yaml|
|
||||
- name: hpack
|
||||
github: sol/hpack
|
||||
ref: master
|
||||
|] `shouldDecodeTo_` Dependencies [("hpack", SourceDependency source)]
|
||||
|] `shouldDecodeTo_` Dependencies [("hpack", DependencyVersion source AnyVersion)]
|
||||
|
||||
it "accepts an optional subdirectory for git dependencies" $ do
|
||||
let source = GitRef "https://github.com/yesodweb/wai" "master" (Just "warp")
|
||||
let source = Just (GitRef "https://github.com/yesodweb/wai" "master" (Just "warp"))
|
||||
[yaml|
|
||||
- name: warp
|
||||
github: yesodweb/wai
|
||||
ref: master
|
||||
subdir: warp
|
||||
|] `shouldDecodeTo_` Dependencies [("warp", SourceDependency source)]
|
||||
|] `shouldDecodeTo_` Dependencies [("warp", DependencyVersion source AnyVersion)]
|
||||
|
||||
it "accepts local dependencies" $ do
|
||||
let source = Local "../hpack"
|
||||
let source = Just (Local "../hpack")
|
||||
[yaml|
|
||||
- name: hpack
|
||||
path: ../hpack
|
||||
|] `shouldDecodeTo_` Dependencies [("hpack", SourceDependency source)]
|
||||
|] `shouldDecodeTo_` Dependencies [("hpack", DependencyVersion source AnyVersion)]
|
||||
|
||||
context "when ref is missing" $ do
|
||||
it "produces accurate error messages" $ do
|
||||
@ -163,16 +163,18 @@ spec = do
|
||||
|
||||
context "when the constraint is an Object" $ do
|
||||
it "accepts github dependencies" $ do
|
||||
let source = Just (GitRef "https://github.com/haskell/cabal" "d53b6e0d908dfedfdf4337b2935519fb1d689e76" (Just "Cabal"))
|
||||
[yaml|
|
||||
Cabal:
|
||||
github: haskell/cabal
|
||||
ref: d53b6e0d908dfedfdf4337b2935519fb1d689e76
|
||||
subdir: Cabal
|
||||
|] `shouldDecodeTo_` Dependencies [("Cabal", SourceDependency (GitRef "https://github.com/haskell/cabal" "d53b6e0d908dfedfdf4337b2935519fb1d689e76" (Just "Cabal")))]
|
||||
|] `shouldDecodeTo_` Dependencies [("Cabal", DependencyVersion source AnyVersion)]
|
||||
|
||||
it "ignores names in nested hashes" $ do
|
||||
let source = Just (Local "somewhere")
|
||||
[yaml|
|
||||
outer-name:
|
||||
name: inner-name
|
||||
path: somewhere
|
||||
|] `shouldDecodeTo` Right (Dependencies [("outer-name", SourceDependency (Local "somewhere"))], ["$.outer-name.name"])
|
||||
|] `shouldDecodeTo` Right (Dependencies [("outer-name", DependencyVersion source AnyVersion)], ["$.outer-name.name"])
|
||||
|
Loading…
Reference in New Issue
Block a user