Skip to content

Commit 4d5e960

Browse files
committed
Resolve haskell#5586. Treat all packages as remote except LocalUnpackedPackage
Also calculate hashes for all locally available tarballs.
1 parent 68e9e1a commit 4d5e960

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

cabal-install/Distribution/Client/FetchUtils.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ checkFetched loc = case loc of
9999
return (Just $ RemoteTarballPackage uri file)
100100
RepoTarballPackage repo pkgid (Just file) ->
101101
return (Just $ RepoTarballPackage repo pkgid file)
102-
RemoteSourceRepoPackage repo (Just dir) ->
103-
return (Just $ RemoteSourceRepoPackage repo dir)
102+
RemoteSourceRepoPackage repo (Just file) ->
103+
return (Just $ RemoteSourceRepoPackage repo file)
104104

105105
RemoteTarballPackage _uri Nothing -> return Nothing
106106
RemoteSourceRepoPackage _repo Nothing -> return Nothing

cabal-install/Distribution/Client/ProjectBuilding.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,8 @@ rebuildTargetsDryRun distDirLayout@DistDirLayout{..} shared =
200200
-- artifacts under the shared dist directory.
201201
dryRunLocalPkg pkg depsBuildStatus srcdir
202202

203-
Just (RemoteSourceRepoPackage _repo srcdir) ->
204-
-- At this point, source repos are essentially the same as local
205-
-- dirs, since we've already download them.
206-
dryRunLocalPkg pkg depsBuildStatus srcdir
207-
208-
-- The three tarball cases are handled the same as each other,
209-
-- though depending on the build style.
203+
-- The rest cases are all tarball cases are,
204+
-- and handled the same as each other though depending on the build style.
210205
Just (LocalTarballPackage tarball) ->
211206
dryRunTarballPkg pkg depsBuildStatus tarball
212207

@@ -216,6 +211,10 @@ rebuildTargetsDryRun distDirLayout@DistDirLayout{..} shared =
216211
Just (RepoTarballPackage _ _ tarball) ->
217212
dryRunTarballPkg pkg depsBuildStatus tarball
218213

214+
Just (RemoteSourceRepoPackage _repo tarball) ->
215+
dryRunTarballPkg pkg depsBuildStatus tarball
216+
217+
219218
dryRunTarballPkg :: ElaboratedConfiguredPackage
220219
-> [BuildStatus]
221220
-> FilePath

cabal-install/Distribution/Client/ProjectConfig.hs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ import Distribution.Version
127127
( Version )
128128
import qualified Distribution.Deprecated.ParseUtils as OldParser
129129
( ParseResult(..), locatedErrorMsg, showPWarning )
130+
import Distribution.Client.SrcDist
131+
( packageDirToSdist )
130132

131133
import qualified Codec.Archive.Tar as Tar
132134
import qualified Codec.Archive.Tar.Entry as Tar
@@ -1170,6 +1172,7 @@ syncAndReadSourcePackagesRemoteRepos verbosity
11701172
syncSourceRepos verbosity vcs
11711173
[ (repo, repoPath)
11721174
| (repo, _, repoPath) <- repoGroupWithPaths ]
1175+
-- TODO phadej 2020-06-18 add post-sync script
11731176

11741177
-- But for reading we go through each 'SourceRepo' including its subdir
11751178
-- value and have to know which path each one ended up in.
@@ -1199,24 +1202,30 @@ syncAndReadSourcePackagesRemoteRepos verbosity
11991202
: [ pathStem ++ "-" ++ show (i :: Int) | i <- [2..] ]
12001203

12011204
readPackageFromSourceRepo
1202-
:: SourceRepositoryPackage Maybe -> FilePath
1205+
:: SourceRepositoryPackage Maybe
1206+
-> FilePath
12031207
-> Rebuild (PackageSpecifier (SourcePackage UnresolvedPkgLoc))
12041208
readPackageFromSourceRepo repo repoPath = do
1205-
let packageDir = maybe repoPath (repoPath </>) (srpSubdir repo)
1209+
let packageDir :: FilePath
1210+
packageDir = maybe repoPath (repoPath </>) (srpSubdir repo)
1211+
12061212
entries <- liftIO $ getDirectoryContents packageDir
1207-
--TODO: wrap exceptions
1213+
--TODO: dcoutts 2018-06-23: wrap exceptions
12081214
case filter (\e -> takeExtension e == ".cabal") entries of
12091215
[] -> liftIO $ throwIO $ NoCabalFileFound packageDir
12101216
(_:_:_) -> liftIO $ throwIO $ MultipleCabalFilesFound packageDir
12111217
[cabalFileName] -> do
1218+
let cabalFilePath = packageDir </> cabalFileName
12121219
monitorFiles [monitorFileHashed cabalFilePath]
1213-
liftIO $ fmap (mkSpecificSourcePackage location)
1214-
. readSourcePackageCabalFile verbosity cabalFilePath
1215-
=<< BS.readFile cabalFilePath
1216-
where
1217-
cabalFilePath = packageDir </> cabalFileName
1218-
location = RemoteSourceRepoPackage repo packageDir
1220+
gpd <- liftIO $ readSourcePackageCabalFile verbosity cabalFilePath =<< BS.readFile cabalFilePath
1221+
1222+
-- write sdist tarball, to repoPath-pgkid
1223+
tarball <- liftIO $ packageDirToSdist verbosity gpd packageDir
1224+
let tarballPath = repoPath ++ "-" ++ prettyShow (packageId gpd) ++ ".tar.gz"
1225+
liftIO $ LBS.writeFile tarballPath tarball
12191226

1227+
let location = RemoteSourceRepoPackage repo tarballPath
1228+
return $ mkSpecificSourcePackage location gpd
12201229

12211230
reportSourceRepoProblems :: [(SourceRepoList, SourceRepoProblem)] -> Rebuild a
12221231
reportSourceRepoProblems = liftIO . die' verbosity . renderSourceRepoProblems
@@ -1231,13 +1240,11 @@ syncAndReadSourcePackagesRemoteRepos verbosity
12311240
--
12321241
mkSpecificSourcePackage :: PackageLocation FilePath
12331242
-> GenericPackageDescription
1234-
-> PackageSpecifier
1235-
(SourcePackage (PackageLocation (Maybe FilePath)))
1243+
-> PackageSpecifier (SourcePackage UnresolvedPkgLoc)
12361244
mkSpecificSourcePackage location pkg =
12371245
SpecificSourcePackage SourcePackage
12381246
{ srcpkgPackageId = packageId pkg
12391247
, srcpkgDescription = pkg
1240-
--TODO: it is silly that we still have to use a Maybe FilePath here
12411248
, srcpkgSource = fmap Just location
12421249
, srcpkgDescrOverride = Nothing
12431250
}

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,14 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
823823

824824
-- Tarballs from remote URLs. We must have downloaded these already
825825
-- (since we extracted the .cabal file earlier)
826-
--TODO: [required eventually] finish remote tarball functionality
827-
-- allRemoteTarballPkgs =
828-
-- [ (pkgid, )
829-
-- | (pkgid, RemoteTarballPackage ) <- allPkgLocations ]
826+
remoteTarballPkgs =
827+
[ (pkgid, tarball)
828+
| (pkgid, RemoteTarballPackage _ (Just tarball)) <- allPkgLocations ]
829+
830+
-- tarballs from source-repository-package stanzas
831+
sourceRepoTarballPkgs =
832+
[ (pkgid, tarball)
833+
| (pkgid, RemoteSourceRepoPackage _ (Just tarball)) <- allPkgLocations ]
830834

831835
-- Tarballs from repositories, either where the repository provides
832836
-- hashes as part of the repo metadata, or where we will have to
@@ -906,6 +910,8 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
906910
--
907911
let allTarballFilePkgs :: [(PackageId, FilePath)]
908912
allTarballFilePkgs = localTarballPkgs
913+
++ remoteTarballPkgs
914+
++ sourceRepoTarballPkgs
909915
++ repoTarballPkgsDownloaded
910916
++ repoTarballPkgsNewlyDownloaded
911917
hashesFromTarballFiles <- liftIO $
@@ -1928,13 +1934,9 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
19281934
where
19291935
shouldBeLocal :: PackageSpecifier (SourcePackage (PackageLocation loc)) -> Maybe PackageId
19301936
shouldBeLocal NamedPackage{} = Nothing
1931-
shouldBeLocal (SpecificSourcePackage pkg)
1932-
| LocalTarballPackage _ <- srcpkgSource pkg = Nothing
1933-
| otherwise = Just (packageId pkg)
1934-
-- TODO: Is it only LocalTarballPackages we can know about without
1935-
-- them being "local" in the sense meant here?
1936-
--
1937-
-- Also, review use of SourcePackage's loc vs ProjectPackageLocation
1937+
shouldBeLocal (SpecificSourcePackage pkg) = case srcpkgSource pkg of
1938+
LocalUnpackedPackage _ -> Just (packageId pkg)
1939+
_ -> Nothing
19381940

19391941
pkgsUseSharedLibrary :: Set PackageId
19401942
pkgsUseSharedLibrary =

0 commit comments

Comments
 (0)