Skip to content

Commit

Permalink
Add more provenance information to PackageLocation for better error m…
Browse files Browse the repository at this point in the history
…essages
  • Loading branch information
fendor committed Feb 13, 2022
1 parent cda45c6 commit 66b03d5
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/CmdSdist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ packageToSdist :: Verbosity -> FilePath -> OutputFormat -> FilePath -> Unresolve
packageToSdist verbosity projectRootDir format outputFile pkg = do
let death = die' verbosity ("The impossible happened: a local package isn't local" <> (show pkg))
dir0 <- case srcpkgSource pkg of
LocalUnpackedPackage path -> pure (Right path)
LocalUnpackedPackage path _ -> pure (Right path)
RemoteSourceRepoPackage _ (Just tgz) -> pure (Left tgz)
RemoteSourceRepoPackage {} -> death
LocalTarballPackage tgz -> pure (Left tgz)
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ configure verbosity packageDBs repoCtxt comp platform progdb
let installPlan = InstallPlan.configureInstallPlan configFlags installPlan0
in case fst (InstallPlan.ready installPlan) of
[pkg@(ReadyPackage
(ConfiguredPackage _ (SourcePackage _ _ (LocalUnpackedPackage _) _)
(ConfiguredPackage _ (SourcePackage _ _ (LocalUnpackedPackage _ _) _)
_ _ _))] -> do
configurePackage verbosity
platform (compilerInfo comp)
Expand Down Expand Up @@ -307,7 +307,7 @@ planLocalPackage verbosity comp platform configFlags configExFlags
localPkg = SourcePackage {
srcpkgPackageId = packageId pkg,
srcpkgDescription = pkg,
srcpkgSource = LocalUnpackedPackage ".",
srcpkgSource = LocalUnpackedPackage "." Nothing,
srcpkgDescrOverride = Nothing
}

Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/Fetch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ checkTarget verbosity target = case target of

fetchPackage :: Verbosity -> RepoContext -> PackageLocation a -> IO ()
fetchPackage verbosity repoCtxt pkgsrc = case pkgsrc of
LocalUnpackedPackage _dir -> return ()
LocalUnpackedPackage _dir _cabalFile -> return ()
LocalTarballPackage _file -> return ()

RemoteTarballPackage _uri _ ->
Expand Down
10 changes: 5 additions & 5 deletions cabal-install/src/Distribution/Client/FetchUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import qualified Hackage.Security.Client as Sec
--
isFetched :: UnresolvedPkgLoc -> IO Bool
isFetched loc = case loc of
LocalUnpackedPackage _dir -> return True
LocalUnpackedPackage _dir _ -> return True
LocalTarballPackage _file -> return True
RemoteTarballPackage _uri local -> return (isJust local)
RepoTarballPackage repo pkgid _ -> doesFileExist (packageFile repo pkgid)
Expand All @@ -91,8 +91,8 @@ isFetched loc = case loc of
checkFetched :: UnresolvedPkgLoc
-> IO (Maybe ResolvedPkgLoc)
checkFetched loc = case loc of
LocalUnpackedPackage dir ->
return (Just $ LocalUnpackedPackage dir)
LocalUnpackedPackage dir cabalFile ->
return (Just $ LocalUnpackedPackage dir cabalFile)
LocalTarballPackage file ->
return (Just $ LocalTarballPackage file)
RemoteTarballPackage uri (Just file) ->
Expand Down Expand Up @@ -126,8 +126,8 @@ fetchPackage :: Verbosity
-> UnresolvedPkgLoc
-> IO ResolvedPkgLoc
fetchPackage verbosity repoCtxt loc = case loc of
LocalUnpackedPackage dir ->
return (LocalUnpackedPackage dir)
LocalUnpackedPackage dir cabalFile ->
return (LocalUnpackedPackage dir cabalFile)
LocalTarballPackage file ->
return (LocalTarballPackage file)
RemoteTarballPackage uri (Just file) ->
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/Get.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ get verbosity repoCtxt _ getFlags userTargets = do
die' verbosity $ "The 'get' command does no yet support targets "
++ "that are remote source repositories."

LocalUnpackedPackage _ ->
LocalUnpackedPackage _ _ ->
error "Distribution.Client.Get.unpack: the impossible happened."
where
usePristine :: Bool
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/IndexUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ readRepoIndex verbosity repoCtxt repo idxState =
, srcpkgDescription = pkgdesc
, srcpkgSource = case pkgEntry of
NormalPackage _ _ _ _ -> RepoTarballPackage repo pkgid Nothing
BuildTreeRef _ _ _ path _ -> LocalUnpackedPackage path
BuildTreeRef _ _ _ path _ -> LocalUnpackedPackage path Nothing
, srcpkgDescrOverride = case pkgEntry of
NormalPackage _ _ pkgtxt _ -> Just pkgtxt
_ -> Nothing
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ installLocalPackage verbosity pkgid location distPref installPkg =

case location of

LocalUnpackedPackage dir ->
LocalUnpackedPackage dir _cabalFile ->
installPkg (Just dir)

RemoteSourceRepoPackage _repo dir ->
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/ProjectBuilding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ rebuildTargetsDryRun distDirLayout@DistDirLayout{..} shared =
case mloc of
Nothing -> return BuildStatusDownload

Just (LocalUnpackedPackage srcdir) ->
Just (LocalUnpackedPackage srcdir _) ->
-- For the case of a user-managed local dir, irrespective of the
-- build style, we build from that directory and put build
-- artifacts under the shared dist directory.
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ readSourcePackageLocalDirectory
readSourcePackageLocalDirectory verbosity dir cabalFile = do
monitorFiles [monitorFileHashed cabalFile]
root <- askRoot
let location = LocalUnpackedPackage (root </> dir)
let location = LocalUnpackedPackage (root </> dir) (Just cabalFile)
liftIO $ fmap (mkSpecificSourcePackage location)
. readSourcePackageCabalFile verbosity cabalFile
=<< BS.readFile (root </> cabalFile)
Expand Down
4 changes: 0 additions & 4 deletions cabal-install/src/Distribution/Client/ProjectOrchestration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,6 @@ resolveTargets selectPackageTargets selectComponentTarget

checkTarget (TargetPackage _ pkgids _)
= Left (TargetProblemNotSinglePackage pkgids)
-- For the moment this error cannot happen here, because it gets
-- detected when the package config is being constructed. This case
-- will need handling properly when we do add support.
--
-- TODO: how should this use case play together with the
-- '--cabal-file' option of 'configure' which allows using multiple
-- .cabal files for a single package?
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/ProjectPlanOutput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
packageLocationToJ :: PackageLocation (Maybe FilePath) -> J.Value
packageLocationToJ pkgloc =
case pkgloc of
LocalUnpackedPackage local ->
LocalUnpackedPackage local _cabalFile ->
J.object [ "type" J..= J.String "local"
, "path" J..= J.String local
]
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2075,8 +2075,8 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
shouldBeLocal :: PackageSpecifier (SourcePackage (PackageLocation loc)) -> Maybe PackageId
shouldBeLocal NamedPackage{} = Nothing
shouldBeLocal (SpecificSourcePackage pkg) = case srcpkgSource pkg of
LocalUnpackedPackage _ -> Just (packageId pkg)
_ -> Nothing
LocalUnpackedPackage _ _ -> Just (packageId pkg)
_ -> Nothing

-- | Given a 'ElaboratedPlanPackage', report if it matches a 'ComponentName'.
matchPlanPkg :: (ComponentName -> Bool) -> ElaboratedPlanPackage -> Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ dataDirEnvVarForPackage distDirLayout pkg =
, Just $ srcPath (elabPkgSourceLocation pkg)
</> dataDir (elabPkgDescription pkg))
where
srcPath (LocalUnpackedPackage path) = path
srcPath (LocalUnpackedPackage path _cabalFile) = path
srcPath (LocalTarballPackage _path) = unpackedPath
srcPath (RemoteTarballPackage _uri _localTar) = unpackedPath
srcPath (RepoTarballPackage _repo _packageId _localTar) = unpackedPath
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/ScriptUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ fakeProjectSourcePackage projectRoot = sourcePackage
sourcePackage = SourcePackage
{ srcpkgPackageId = fakePackageId
, srcpkgDescription = genericPackageDescription
, srcpkgSource = LocalUnpackedPackage projectRoot
, srcpkgSource = LocalUnpackedPackage projectRoot Nothing
, srcpkgDescrOverride = Nothing
}
genericPackageDescription = emptyGenericPackageDescription
Expand Down
18 changes: 9 additions & 9 deletions cabal-install/src/Distribution/Client/TargetSelector.hs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,14 @@ reportTargetSelectorProblems verbosity problems = do
where


case [ t | TargetSelectorNoScript t <- problems ] of
[] -> return ()
target:_ ->
die' verbosity $
"The script '" ++ showTargetString target ++ "' does not exist, "
++ "and only script targets may contain whitespace characters or end "
++ "with ':'"

fail "reportTargetSelectorProblems: internal error"
where
noPackageErrorMessage =
Expand All @@ -842,14 +850,6 @@ reportTargetSelectorProblems verbosity problems = do
++ "packages in your project and all other build configuration. "
++ "See the Cabal user guide for full details."

case [ t | TargetSelectorNoScript t <- problems ] of
[] -> return ()
target:_ ->
die' verbosity $
"The script '" ++ showTargetString target ++ "' does not exist, "
++ "and only script targets may contain whitespace characters or end "
++ "with ':'"


----------------------------------
-- Syntax type
Expand Down Expand Up @@ -1828,7 +1828,7 @@ collectKnownPackageInfo dirActions@DirActions{..}
(pkgdir, pkgfile) <-
case loc of
--TODO: local tarballs, remote tarballs etc
LocalUnpackedPackage dir -> do
LocalUnpackedPackage dir _cabalFile -> do
dirabs <- canonicalizePath dir
dirrel <- makeRelativeToCwd dirActions dirabs
--TODO: ought to get this earlier in project reading
Expand Down
8 changes: 4 additions & 4 deletions cabal-install/src/Distribution/Client/Targets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import qualified Data.ByteString.Lazy as BS
import qualified Distribution.Client.GZipUtils as GZipUtils
import qualified Distribution.Compat.CharParsing as P
import System.FilePath
( takeExtension, dropExtension, takeDirectory, splitPath )
( takeExtension, dropExtension, takeDirectory, splitPath, takeFileName )
import System.Directory
( doesFileExist, doesDirectoryExist )
import Network.URI
Expand Down Expand Up @@ -348,12 +348,12 @@ expandUserTarget verbosity userTarget = case userTarget of
in return [PackageTargetNamedFuzzy name props userTarget]

UserTargetLocalDir dir ->
return [ PackageTargetLocation (LocalUnpackedPackage dir) ]
return [ PackageTargetLocation (LocalUnpackedPackage dir Nothing) ]

UserTargetLocalCabalFile file -> do
let dir = takeDirectory file
_ <- tryFindPackageDesc verbosity dir (localPackageError dir) -- just as a check
return [ PackageTargetLocation (LocalUnpackedPackage dir) ]
return [ PackageTargetLocation (LocalUnpackedPackage dir (Just $ takeFileName file)) ]

UserTargetLocalTarball tarballFile ->
return [ PackageTargetLocation (LocalTarballPackage tarballFile) ]
Expand Down Expand Up @@ -392,7 +392,7 @@ readPackageTarget verbosity = traverse modifyLocation
modifyLocation :: ResolvedPkgLoc -> IO UnresolvedSourcePackage
modifyLocation location = case location of

LocalUnpackedPackage dir -> do
LocalUnpackedPackage dir _cabalFile -> do
pkg <- tryFindPackageDesc verbosity dir (localPackageError dir) >>=
readGenericPackageDescription verbosity
return SourcePackage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ type ResolvedPkgLoc = PackageLocation FilePath

data PackageLocation local =

-- | An unpacked package in the given dir, or current dir
LocalUnpackedPackage FilePath
-- | An unpacked package in the given dir, or current dir,
-- with the given .cabal file name within the given dir.
-- If Nothing, this will default to @'PackageId' <.> "cabal"@.
LocalUnpackedPackage FilePath (Maybe FilePath)

-- | A package as a tarball that's available as a local tarball
| LocalTarballPackage FilePath
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ testTargetSelectorAmbiguous reportSubCase = do
mkpkgAt pkgidstr exes loc =
SourcePackage {
srcpkgPackageId = pkgid,
srcpkgSource = LocalUnpackedPackage loc,
srcpkgSource = LocalUnpackedPackage loc Nothing,
srcpkgDescrOverride = Nothing,
srcpkgDescription = GenericPackageDescription {
packageDescription = emptyPackageDescription { package = pkgid },
Expand Down

0 comments on commit 66b03d5

Please sign in to comment.