Skip to content

Commit 2b6cd51

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

File tree

4 files changed

+53
-39
lines changed

4 files changed

+53
-39
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: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -593,19 +593,25 @@ rebuildInstallPlan verbosity
593593
Map.fromList
594594
[ (pkgname, stanzas)
595595
| pkg <- localPackages
596+
-- TODO: misnormer: we should separate
597+
-- builtin/global/inplace/local packages
598+
-- and packages explicitly mentioned in the project
599+
--
596600
, let pkgname = pkgSpecifierTarget pkg
597601
testsEnabled = lookupLocalPackageConfig
598602
packageConfigTests
599603
projectConfig pkgname
600604
benchmarksEnabled = lookupLocalPackageConfig
601605
packageConfigBenchmarks
602606
projectConfig pkgname
603-
stanzas =
604-
Map.fromList $
607+
isLocal = isJust (shouldBeLocal pkg)
608+
stanzas
609+
| isLocal = Map.fromList $
605610
[ (TestStanzas, enabled)
606-
| enabled <- flagToList testsEnabled ]
607-
++ [ (BenchStanzas , enabled)
611+
| enabled <- flagToList testsEnabled ] ++
612+
[ (BenchStanzas , enabled)
608613
| enabled <- flagToList benchmarksEnabled ]
614+
| otherwise = Map.fromList [(TestStanzas, False), (BenchStanzas, False) ]
609615
]
610616

611617
-- Elaborate the solver's install plan to get a fully detailed plan. This
@@ -823,10 +829,14 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
823829

824830
-- Tarballs from remote URLs. We must have downloaded these already
825831
-- (since we extracted the .cabal file earlier)
826-
--TODO: [required eventually] finish remote tarball functionality
827-
-- allRemoteTarballPkgs =
828-
-- [ (pkgid, )
829-
-- | (pkgid, RemoteTarballPackage ) <- allPkgLocations ]
832+
remoteTarballPkgs =
833+
[ (pkgid, tarball)
834+
| (pkgid, RemoteTarballPackage _ (Just tarball)) <- allPkgLocations ]
835+
836+
-- tarballs from source-repository-package stanzas
837+
sourceRepoTarballPkgs =
838+
[ (pkgid, tarball)
839+
| (pkgid, RemoteSourceRepoPackage _ (Just tarball)) <- allPkgLocations ]
830840

831841
-- Tarballs from repositories, either where the repository provides
832842
-- hashes as part of the repo metadata, or where we will have to
@@ -906,6 +916,8 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
906916
--
907917
let allTarballFilePkgs :: [(PackageId, FilePath)]
908918
allTarballFilePkgs = localTarballPkgs
919+
++ remoteTarballPkgs
920+
++ sourceRepoTarballPkgs
909921
++ repoTarballPkgsDownloaded
910922
++ repoTarballPkgsNewlyDownloaded
911923
hashesFromTarballFiles <- liftIO $
@@ -1925,16 +1937,6 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
19251937
Set.fromList (catMaybes (map shouldBeLocal localPackages))
19261938
--TODO: localPackages is a misnomer, it's all project packages
19271939
-- here is where we decide which ones will be local!
1928-
where
1929-
shouldBeLocal :: PackageSpecifier (SourcePackage (PackageLocation loc)) -> Maybe PackageId
1930-
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
19381940

19391941
pkgsUseSharedLibrary :: Set PackageId
19401942
pkgsUseSharedLibrary =
@@ -1995,6 +1997,12 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
19951997

19961998
-- TODO: Drop matchPlanPkg/matchElabPkg in favor of mkCCMapping
19971999

2000+
shouldBeLocal :: PackageSpecifier (SourcePackage (PackageLocation loc)) -> Maybe PackageId
2001+
shouldBeLocal NamedPackage{} = Nothing
2002+
shouldBeLocal (SpecificSourcePackage pkg) = case srcpkgSource pkg of
2003+
LocalUnpackedPackage _ -> Just (packageId pkg)
2004+
_ -> Nothing
2005+
19982006
-- | Given a 'ElaboratedPlanPackage', report if it matches a 'ComponentName'.
19992007
matchPlanPkg :: (ComponentName -> Bool) -> ElaboratedPlanPackage -> Bool
20002008
matchPlanPkg p = InstallPlan.foldPlanPackage (p . ipiComponentName) (matchElabPkg p)

0 commit comments

Comments
 (0)