Skip to content

Commit 6322071

Browse files
mpilgremsol
authored andcommitted
Fix #618 Infer cabal-version: 3.12 when PackageInfo_* is used
Also bumps stack.yaml to Stackage LTS Haskell 24.6
1 parent d64261e commit 6322071

File tree

7 files changed

+67
-12
lines changed

7 files changed

+67
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Changes in 0.38.2
2+
- Infer `cabal-version: 3.12` when `PackageInfo_*` is used (see #620)
3+
14
## Changes in 0.38.1
25
- Add support for `extra-files` (see #603)
36
- Preserve empty lines in `description` when `cabal-version >= 3` (see #612)

hpack.cabal

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
spec-version: 0.36.0
22
name: hpack
3-
version: 0.38.1
3+
version: 0.38.2
44
synopsis: A modern format for Haskell packages
55
description: See README at <https://github.com/sol/hpack#readme>
66
author: Simon Hengel <sol@typeful.net>

src/Hpack/Config.hs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,12 +846,24 @@ ensureRequiredCabalVersion inferredLicense pkg@Package{..} = pkg {
846846
makeVersion [1,22] <$ guard (has libraryReexportedModules)
847847
, makeVersion [2,0] <$ guard (has librarySignatures)
848848
, makeVersion [2,0] <$ guard (has libraryGeneratedModules)
849+
, makeVersion [3,12] <$ guard (libraryHasPackageInfoModule sect)
849850
, makeVersion [3,0] <$ guard (has libraryVisibility)
850851
, sectionCabalVersion (concatMap getLibraryModules) sect
851852
]
852853
where
853854
has field = any (not . null . field) sect
854855

856+
libraryHasPackageInfoModule :: Section Library -> Bool
857+
libraryHasPackageInfoModule =
858+
any (hasPackageInfoModule . libraryGeneratedModules)
859+
860+
packageInfoModule :: Module
861+
packageInfoModule =
862+
Module ("PackageInfo_" ++ moduleNameFromPackageName packageName)
863+
864+
hasPackageInfoModule :: [Module] -> Bool
865+
hasPackageInfoModule = any (== packageInfoModule)
866+
855867
internalLibsCabalVersion :: Map String (Section Library) -> Maybe CabalVersion
856868
internalLibsCabalVersion internalLibraries
857869
| Map.null internalLibraries = Nothing
@@ -865,12 +877,17 @@ ensureRequiredCabalVersion inferredLicense pkg@Package{..} = pkg {
865877
executableCabalVersion :: Section Executable -> Maybe CabalVersion
866878
executableCabalVersion sect = maximum [
867879
makeVersion [2,0] <$ guard (executableHasGeneratedModules sect)
880+
, makeVersion [3,12] <$ guard (executableHasPackageInfoModule sect)
868881
, sectionCabalVersion (concatMap getExecutableModules) sect
869882
]
870883

871884
executableHasGeneratedModules :: Section Executable -> Bool
872885
executableHasGeneratedModules = any (not . null . executableGeneratedModules)
873886

887+
executableHasPackageInfoModule :: Section Executable -> Bool
888+
executableHasPackageInfoModule =
889+
any (hasPackageInfoModule . executableGeneratedModules)
890+
874891
sectionCabalVersion :: (Section a -> [Module]) -> Section a -> Maybe CabalVersion
875892
sectionCabalVersion getMentionedModules sect = maximum $ [
876893
makeVersion [2,2] <$ guard (sectionSatisfies (not . null . sectionCxxSources) sect)
@@ -1659,7 +1676,11 @@ toBuildTool packageName_ executableNames = \ case
16591676
warnLegacySystemTool name = tell ["Listing " ++ show name ++ " under build-tools is deperecated! Please list system executables under system-build-tools instead!"]
16601677

16611678
pathsModuleFromPackageName :: String -> Module
1662-
pathsModuleFromPackageName name = Module ("Paths_" ++ map f name)
1663-
where
1664-
f '-' = '_'
1665-
f x = x
1679+
pathsModuleFromPackageName name =
1680+
Module ("Paths_" ++ moduleNameFromPackageName name)
1681+
1682+
moduleNameFromPackageName :: String -> String
1683+
moduleNameFromPackageName = map f
1684+
where
1685+
f '-' = '_'
1686+
f x = x

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
snapshot: lts-22.25 # GHC 9.6.5
1+
snapshot: lts-24.6 # GHC 9.10.2

stack.yaml.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# This file was autogenerated by Stack.
22
# You should not edit this file by hand.
33
# For more information, please see the documentation at:
4-
# https://docs.haskellstack.org/en/stable/lock_files
4+
# https://docs.haskellstack.org/en/stable/topics/lock_files
55

66
packages: []
77
snapshots:
88
- completed:
9-
sha256: 9b43e51f2c54211993d5954da8b49604704d8288103b8d9150a19a703f4e55e7
10-
size: 719126
11-
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/25.yaml
12-
original: lts-22.25
9+
sha256: 473840099b95facf73ec72dcafe53a2487bfadeceb03a981a19e16469503a342
10+
size: 726266
11+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/24/6.yaml
12+
original: lts-24.6

test/EndToEndSpec.hs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,20 @@ spec = around_ (inTempDirectoryNamed "my-package") $ do
13271327
default-language: Haskell2010
13281328
|]) {packageCabalVersion = "2.0"}
13291329

1330+
context "with PackageInfo_my_package" $ do
1331+
it "infers cabal-version 3.12" $ do
1332+
[i|
1333+
spec-version: 0.36.0
1334+
library:
1335+
generated-other-modules: PackageInfo_my_package
1336+
|] `shouldRenderTo` (library [i|
1337+
other-modules:
1338+
PackageInfo_my_package
1339+
autogen-modules:
1340+
PackageInfo_my_package
1341+
default-language: Haskell2010
1342+
|]) {packageCabalVersion = "3.12"}
1343+
13301344
describe "internal-libraries" $ do
13311345
it "accepts internal-libraries" $ do
13321346
touch "src/Foo.hs"
@@ -1684,6 +1698,23 @@ spec = around_ (inTempDirectoryNamed "my-package") $ do
16841698
default-language: Haskell2010
16851699
|]) {packageCabalVersion = "2.0"}
16861700

1701+
context "with PackageInfo_my_package" $ do
1702+
it "infers cabal-version 3.12" $ do
1703+
[i|
1704+
spec-version: 0.36.0
1705+
executables:
1706+
foo:
1707+
main: Main.hs
1708+
generated-other-modules: PackageInfo_my_package
1709+
|] `shouldRenderTo` (executable "foo" [i|
1710+
main-is: Main.hs
1711+
other-modules:
1712+
PackageInfo_my_package
1713+
autogen-modules:
1714+
PackageInfo_my_package
1715+
default-language: Haskell2010
1716+
|]) {packageCabalVersion = "3.12"}
1717+
16871718
context "with a conditional" $ do
16881719
it "doesn't infer any modules mentioned in that conditional" $ do
16891720
touch "src/Foo.hs"

0 commit comments

Comments
 (0)