Skip to content

Commit

Permalink
WIP fix local+noindex on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Jan 8, 2025
1 parent 1c7243f commit 71b3427
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 12 deletions.
17 changes: 17 additions & 0 deletions Cabal-syntax/src/Distribution/Utils/Path.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ module Distribution.Utils.Path

-- ** Module names
, moduleNameSymbolicPath

-- * Windows
, posixizePath
) where

import Distribution.Compat.Prelude
Expand Down Expand Up @@ -531,3 +534,17 @@ data Response
--
-- See Note [Symbolic paths] in Distribution.Utils.Path.
data PkgConf

-------------------------------------------------------------------------------

-- * Windows utils

-------------------------------------------------------------------------------

-- | Sometimes we need to represent a Windows path (that might have been
-- normalized) as a POSIX path, for example in URIs.
posixizePath :: FilePath -> FilePath
posixizePath = map (\x -> case x of
'\\' -> '/'
_ -> x
)
11 changes: 9 additions & 2 deletions cabal-install/src/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ import System.Directory
, renameFile
)
import System.FilePath
( takeDirectory
( normalise
, takeDirectory
, (<.>)
, (</>)
)
Expand Down Expand Up @@ -1693,7 +1694,13 @@ postProcessRepo lineno reponameStr repo0 = do
-- Note: the trailing colon is important
"file+noindex:" -> do
let uri = remoteRepoURI repo0
return $ Left $ LocalRepo reponame (uriPath uri) (uriFragment uri == "#shared-cache")
return $ Left $
LocalRepo
reponame
-- Normalization of Windows paths that use @//./@ does not fully
-- normalize the path (see filepath#247), but it is still usable.
(normalise (uriPath uri))
(uriFragment uri == "#shared-cache")
_ -> do
let repo = repo0{remoteRepoName = reponame}

Expand Down
7 changes: 3 additions & 4 deletions cabal-install/src/Distribution/Client/GlobalFlags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ import Network.URI
, uriScheme
)
import System.FilePath
( (</>)
( isAbsolute
, (</>)
)

import qualified Distribution.Client.Security.DNS as Sec.DNS
Expand All @@ -69,8 +70,6 @@ import qualified Hackage.Security.Client.Repository.Remote as Sec.Remote
import qualified Hackage.Security.Util.Path as Sec
import qualified Hackage.Security.Util.Pretty as Sec

import qualified System.FilePath.Posix as FilePath.Posix

-- ------------------------------------------------------------

-- * Global flags
Expand Down Expand Up @@ -192,7 +191,7 @@ withRepoContext'
ignoreExpiry
extraPaths = \callback -> do
for_ localNoIndexRepos $ \local ->
unless (FilePath.Posix.isAbsolute (localRepoPath local)) $
unless (isAbsolute (localRepoPath local)) $
warn verbosity $
"file+noindex " ++ unRepoName (localRepoName local) ++ " repository path is not absolute; this is fragile, and not recommended"

Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/IndexUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ readRepoIndex verbosity repoCtxt repo idxState =
RepoSecure{..} -> warn verbosity $ exceptionMessageCabalInstall $ MissingPackageList repoRemote
RepoLocalNoIndex local _ ->
warn verbosity $
"Error during construction of local+noindex "
"Error during construction of file+noindex "
++ unRepoName (localRepoName local)
++ " repository index: "
++ show e
Expand Down Expand Up @@ -526,7 +526,7 @@ whenCacheOutOfDate index action = do
then action
else
if localNoIndex index
then return () -- TODO: don't update cache for local+noindex repositories
then return () -- TODO: don't update cache for file+noindex repositories
else do
indexTime <- getModTime $ indexFile index
cacheTime <- getModTime $ cacheFile index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,13 @@ remoteRepoSectionDescr =
localToRemote :: LocalRepo -> RemoteRepo
localToRemote (LocalRepo name path sharedCache) =
(emptyRemoteRepo name)
{ remoteRepoURI = URI "file+noindex:" Nothing path "" (if sharedCache then "#shared-cache" else "")
{ remoteRepoURI =
URI
"file+noindex:"
Nothing
((if isWindows then joinDrive "//./" . posixizePath else id) path)

Check failure on line 2047 in cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs

View workflow job for this annotation

GitHub Actions / Doctest Cabal

Variable not in scope: isWindows :: Bool

Check failure on line 2047 in cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs

View workflow job for this annotation

GitHub Actions / Doctest Cabal

Variable not in scope: joinDrive :: String -> FilePath -> FilePath
""
(if sharedCache then "#shared-cache" else "")
}

-------------------------------
Expand Down
4 changes: 1 addition & 3 deletions cabal-testsuite/src/Test/Cabal/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,7 @@ withRepoNoUpdate repo_dir m = do
-- TODO: Arguably should undo everything when we're done...
where
repoUri env ="file+noindex://" ++ (if isWindows
then map (\x -> case x of
'\\' -> '/'
_ -> x)
then joinDrive "//./" . posixizePath
else id) (testRepoDir env)

-- | Given a directory (relative to the 'testCurrentDir') containing
Expand Down
4 changes: 4 additions & 0 deletions doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ repository.
``package-name-version.tar.gz`` files in the directory, and will use optional
corresponding ``package-name-version.cabal`` files as new revisions.

.. note::
On Windows systems, the path has to be prefixed by ``//./`` as in
``url: file+noindex:////./C:/absolute/path/to/directory``.

For example, if ``/absolute/path/to/directory`` looks like
::

Expand Down

0 comments on commit 71b3427

Please sign in to comment.