From df33ffd4090bfe9916969342b8d41e03fe1e1b22 Mon Sep 17 00:00:00 2001 From: Peter Becich Date: Sun, 3 Mar 2024 16:41:59 -0800 Subject: [PATCH] offline flag disables `source-repository-package` sync https://github.com/haskell/cabal/issues/9641 warning when offline mode skips `source-repository-package`s i.e. ``` Warning: --offline was specified, skipping sync of repositories: Warning: https://github.com/haskell/text.git ``` (cherry picked from commit df8f0c58643f5d6e471af6a2bfbab9d98984fdd1) --- .../src/Distribution/Client/ProjectConfig.hs | 21 +++++++++++++------ changelog.d/issue-9641 | 8 +++++++ 2 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 changelog.d/issue-9641 diff --git a/cabal-install/src/Distribution/Client/ProjectConfig.hs b/cabal-install/src/Distribution/Client/ProjectConfig.hs index a80f517765a..70d99ad8e1d 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig.hs @@ -1196,6 +1196,7 @@ fetchAndReadSourcePackages verbosity distDirLayout projectConfigShared + (fromFlag (projectConfigOfflineMode projectConfigBuildOnly)) [repo | ProjectPackageRemoteRepo repo <- pkgLocations] let pkgsNamed = @@ -1312,6 +1313,7 @@ syncAndReadSourcePackagesRemoteRepos :: Verbosity -> DistDirLayout -> ProjectConfigShared + -> Bool -> [SourceRepoList] -> Rebuild [PackageSpecifier (SourcePackage UnresolvedPkgLoc)] syncAndReadSourcePackagesRemoteRepos @@ -1320,6 +1322,7 @@ syncAndReadSourcePackagesRemoteRepos ProjectConfigShared { projectConfigProgPathExtra } + offlineMode repos = do repos' <- either reportSourceRepoProblems return $ @@ -1374,12 +1377,18 @@ syncAndReadSourcePackagesRemoteRepos -- For syncing we don't care about different 'SourceRepo' values that -- are just different subdirs in the same repo. - syncSourceRepos - verbosity - vcs - [ (repo, repoPath) - | (repo, _, repoPath) <- repoGroupWithPaths - ] + -- Do not sync source repositories when `--offline` flag applied. + if not offlineMode + then + syncSourceRepos + verbosity + vcs + [ (repo, repoPath) + | (repo, _, repoPath) <- repoGroupWithPaths + ] + else do + liftIO . warn verbosity $ "--offline was specified, skipping sync of repositories:" + liftIO . for_ repoGroupWithPaths $ \(repo, _, _) -> warn verbosity $ srpLocation repo -- Run post-checkout-command if it is specified for_ repoGroupWithPaths $ \(repo, _, repoPath) -> diff --git a/changelog.d/issue-9641 b/changelog.d/issue-9641 new file mode 100644 index 00000000000..34666f0ad59 --- /dev/null +++ b/changelog.d/issue-9641 @@ -0,0 +1,8 @@ +synopsis: offline flag applied to `source-repository-package`s +packages: Cabal-install +prs: #9771 +issues: #9641 + +description: { +`--offline` flag is already used to block access to Hackage. Now with this PR, this also applies to remote dependency `source-repository-package` in `cabal.project`. +}