@@ -48,6 +48,8 @@ module Distribution.Client.ProjectConfig (
48
48
import Prelude ()
49
49
import Distribution.Client.Compat.Prelude
50
50
51
+ import Distribution.Client.Get
52
+ ( BranchCmd (.. ), findUsableBranchers , findBranchCmd )
51
53
import Distribution.Client.ProjectConfig.Types
52
54
import Distribution.Client.ProjectConfig.Legacy
53
55
import Distribution.Client.RebuildMonad
@@ -56,7 +58,7 @@ import Distribution.Client.Glob
56
58
57
59
import Distribution.Client.Types
58
60
import Distribution.Client.DistDirLayout
59
- ( CabalDirLayout (.. ) )
61
+ ( CabalDirLayout (.. ), DistDirLayout ( .. ) )
60
62
import Distribution.Client.GlobalFlags
61
63
( RepoContext (.. ), withRepoContext' )
62
64
import Distribution.Client.BuildReports.Types
@@ -115,6 +117,8 @@ import Data.Either
115
117
import qualified Data.Map as Map
116
118
import Data.Set (Set )
117
119
import qualified Data.Set as Set
120
+ import System.Exit
121
+ ( ExitCode (.. ) )
118
122
import System.FilePath hiding (combine )
119
123
import System.Directory
120
124
import Network.URI (URI (.. ), URIAuth (.. ), parseAbsoluteURI )
@@ -862,14 +866,17 @@ mplusMaybeT ma mb = do
862
866
-- Note here is where we convert from project-root relative paths to absolute
863
867
-- paths.
864
868
--
865
- readSourcePackage :: Verbosity -> ProjectPackageLocation
869
+ readSourcePackage :: Verbosity -> DistDirLayout -> ProjectPackageLocation
866
870
-> Rebuild UnresolvedSourcePackage
867
- readSourcePackage verbosity (ProjectPackageLocalCabalFile cabalFile) =
868
- readSourcePackage verbosity (ProjectPackageLocalDirectory dir cabalFile)
871
+ readSourcePackage verbosity distDirLayout (ProjectPackageLocalCabalFile cabalFile) =
872
+ readSourcePackage
873
+ verbosity
874
+ distDirLayout
875
+ (ProjectPackageLocalDirectory dir cabalFile)
869
876
where
870
877
dir = takeDirectory cabalFile
871
878
872
- readSourcePackage verbosity (ProjectPackageLocalDirectory dir cabalFile) = do
879
+ readSourcePackage verbosity _ (ProjectPackageLocalDirectory dir cabalFile) = do
873
880
monitorFiles [monitorFileHashed cabalFile]
874
881
root <- askRoot
875
882
pkgdesc <- liftIO $ readGenericPackageDescription verbosity (root </> cabalFile)
@@ -879,7 +886,45 @@ readSourcePackage verbosity (ProjectPackageLocalDirectory dir cabalFile) = do
879
886
packageSource = LocalUnpackedPackage (root </> dir),
880
887
packageDescrOverride = Nothing
881
888
}
882
- readSourcePackage _verbosity _ =
889
+
890
+ readSourcePackage verbosity distDirLayout (ProjectPackageRemoteRepo repo) = do
891
+
892
+ when (isNothing (repoTag repo)) $ do
893
+ fail (" Source repository without tag are not allowed" )
894
+
895
+ branchers <- liftIO findUsableBranchers
896
+ let
897
+ tag = fromJust (repoTag repo)
898
+ destDir = distUnpackedSrcRootDirectory distDirLayout </> (" src-" ++ tag)
899
+ subdir = fromMaybe " " (repoSubdir repo)
900
+ pkgdir = destDir </> subdir
901
+ repoloc = fromMaybe " " (repoLocation repo)
902
+
903
+ repoExists <- liftIO $ doesDirectoryExist destDir
904
+ when (not repoExists) $ do
905
+ case findBranchCmd branchers [repo] Nothing of
906
+ Just (BranchCmd fork) -> do
907
+ exitCode <- liftIO $ fork verbosity destDir
908
+ case exitCode of
909
+ ExitSuccess -> return ()
910
+ ExitFailure _ -> fail (" Couldn't fork package from " ++ repoloc)
911
+ Nothing -> fail (" No usable brancher found for " ++ repoloc)
912
+
913
+ pkgdirExists <- liftIO $ doesDirectoryExist pkgdir
914
+ when (not pkgdirExists) $ do
915
+ fail (" Subdirectory does not exists in repository " ++ repoloc)
916
+
917
+ matches <- matchFileGlob (globStarDotCabal pkgdir)
918
+ case matches of
919
+ [cabalFile]
920
+ -> readSourcePackage
921
+ verbosity
922
+ distDirLayout
923
+ (ProjectPackageLocalDirectory pkgdir cabalFile)
924
+ [] -> fail (" No cabal file found in source repository" )
925
+ _ -> fail (" More than one cabal file found in source repository" )
926
+
927
+ readSourcePackage _verbosity _ _ =
883
928
fail $ " TODO: add support for fetching and reading local tarballs, remote "
884
929
++ " tarballs, remote repos and passing named packages through"
885
930
0 commit comments