Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cabal-QuickCheck/src/Test/QuickCheck/Instances/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Distribution.Simple.Setup (HaddockTarget (..), TestShow
import Distribution.SPDX
import Distribution.System
import Distribution.Types.Dependency
import Distribution.Types.ExtraSource
import Distribution.Types.Flag (FlagAssignment, FlagName, mkFlagAssignment, mkFlagName, unFlagAssignment)
import Distribution.Types.IncludeRenaming
import Distribution.Types.LibraryName
Expand All @@ -38,6 +39,7 @@ import Distribution.Types.SourceRepo
import Distribution.Types.UnqualComponentName
import Distribution.Types.VersionRange.Internal
import Distribution.Utils.NubList
import Distribution.Utils.Path (makeSymbolicPath)
import Distribution.Verbosity
import Distribution.Version

Expand Down Expand Up @@ -145,6 +147,24 @@ instance Arbitrary VersionIntervals where
instance Arbitrary Bound where
arbitrary = elements [ExclusiveBound, InclusiveBound]

-------------------------------------------------------------------------------
-- ExtraSource
-------------------------------------------------------------------------------

instance Arbitrary ExtraSource where
arbitrary = ExtraSource . makeSymbolicPath
<$> arbitraryShortPath
<*> arbitraryExtraSourceOpts
where
-- The options are kept verbatim, but '(', ')' and '\\' are structural
-- in the rendered form and have to be escaped to survive a round-trip,
-- so make sure the generator produces plenty of them.
arbitraryExtraSourceOpts =
frequency [(1, pure ""), (4, shortListOf1 10 optChar)]
optChar = elements $ ' ' : '"' : ['#' .. '~']

shrink (ExtraSource p opts) = ExtraSource p <$> shrink opts

-------------------------------------------------------------------------------
-- Backpack
-------------------------------------------------------------------------------
Expand Down
25 changes: 24 additions & 1 deletion Cabal-described/src/Distribution/Described.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
module Distribution.Described (
Described (..),
describeDoc,
Expand Down Expand Up @@ -31,6 +32,7 @@ module Distribution.Described (
csUpper,
csNotSpace,
csNotSpaceOrComma,
csExtraSourceOptChar,
-- * tasty
testDescribed,
) where
Expand Down Expand Up @@ -77,6 +79,7 @@ import Distribution.Types.Dependency (Dependency)
import Distribution.Types.ExecutableScope (ExecutableScope)
import Distribution.Types.ExeDependency (ExeDependency)
import Distribution.Types.ExposedModule (ExposedModule)
import Distribution.Types.ExtraSource (ExtraSource)
import Distribution.Types.Flag (FlagAssignment, FlagName)
import Distribution.Types.ForeignLib (LibVersionInfo)
import Distribution.Types.ForeignLibOption (ForeignLibOption)
Expand All @@ -96,7 +99,7 @@ import Distribution.Types.SourceRepo (RepoType)
import Distribution.Types.TestType (TestType)
import Distribution.Types.UnitId (UnitId)
import Distribution.Types.UnqualComponentName (UnqualComponentName)
import Distribution.Utils.Path (SymbolicPath, RelativePath)
import Distribution.Utils.Path (SymbolicPath, RelativePath, FileOrDir(..), Pkg)
import Distribution.Verbosity (VerbosityFlags)
import Distribution.Version (Version, VersionRange)
import Language.Haskell.Extension (Extension, Language, knownLanguages)
Expand Down Expand Up @@ -203,6 +206,13 @@ csNotSpace = CS.difference CS.universe $ CS.singleton ' '
csNotSpaceOrComma :: CS.CharSet
csNotSpaceOrComma = CS.difference csNotSpace $ CS.singleton ','

-- | Characters that may appear verbatim in the per-file options on an extra
-- source. Keep in sync with @parsecExtraSourceOpts@ in
-- "Distribution.Types.ExtraSource": there @(@, @)@ and @\\@ are the only
-- characters with any meaning.
csExtraSourceOptChar :: CS.CharSet
csExtraSourceOptChar = CS.difference csNotSpace $ CS.fromList "()\\"

-------------------------------------------------------------------------------
-- Special
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -403,6 +413,19 @@ instance Described ExposedModule where
instance Described Extension where
describe _ = RETodo

instance Described ExtraSource where
describe _ = REAppend
[ describe (Proxy :: Proxy (SymbolicPath Pkg File))
, REOpt (RESpaces1 <> reChar '(' <> reSpacedList opt <> reChar ')')
]
where
-- The text between the parentheses is taken verbatim; only a
-- parenthesis or a backslash has to be escaped. Parentheses may also
-- nest as long as they balance, which a regular grammar cannot
-- express; escaping them always works.
opt = REMunch1 reEps (REUnion [RECharSet csExtraSourceOptChar, escaped])
escaped = reChar '\\' <> reChars "()\\"

instance Described FlagAssignment where
describe _ = REMunch RESpaces1 $
REUnion [fromString "+", fromString "-"] <> describe (Proxy :: Proxy FlagName)
Expand Down
2 changes: 2 additions & 0 deletions Cabal-hooks/src/Distribution/Simple/SetupHooks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ module Distribution.Simple.SetupHooks
, Component(..), ComponentName(..), componentName
, ModuleName
, BuildInfo(..), emptyBuildInfo
, ExtraSource(..), extraSourceFromPath
, TargetInfo(..), ComponentLocalBuildInfo(..)

-- **** Components
Expand All @@ -232,6 +233,7 @@ import Distribution.PackageDescription
, emptyLibrary, emptyForeignLib
, emptyExecutable, emptyBenchmark, emptyTestSuite
, BuildInfo(..), emptyBuildInfo
, ExtraSource(..), extraSourceFromPath
, ComponentName(..), LibraryName(..)
)
import Distribution.Simple.BuildPaths
Expand Down
1 change: 1 addition & 0 deletions Cabal-syntax/Cabal-syntax.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ library
Distribution.Types.Executable
Distribution.Types.Executable.Lens
Distribution.Types.ExecutableScope
Distribution.Types.ExtraSource
Distribution.Types.ExposedModule
Distribution.Types.Flag
Distribution.Types.ForeignLib
Expand Down
2 changes: 1 addition & 1 deletion Cabal-syntax/src/Distribution/CabalSpecVersion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ showCabalSpecVersion CabalSpecV1_2 = "1.2"
showCabalSpecVersion CabalSpecV1_0 = "1.0"

cabalSpecLatest :: CabalSpecVersion
cabalSpecLatest = CabalSpecV3_16
cabalSpecLatest = CabalSpecV3_20

-- | Parse 'CabalSpecVersion' from version digits.
--
Expand Down
4 changes: 4 additions & 0 deletions Cabal-syntax/src/Distribution/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ module Distribution.PackageDescription
, module Distribution.Types.HookedBuildInfo
, module Distribution.Types.SetupBuildInfo

-- * Extra sources
, module Distribution.Types.ExtraSource

-- * Flags
, module Distribution.Types.Flag

Expand Down Expand Up @@ -99,6 +102,7 @@ import Distribution.Types.Dependency
import Distribution.Types.ExeDependency
import Distribution.Types.Executable
import Distribution.Types.ExecutableScope
import Distribution.Types.ExtraSource
import Distribution.Types.Flag
import Distribution.Types.ForeignLib
import Distribution.Types.ForeignLibOption
Expand Down
25 changes: 14 additions & 11 deletions Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ libraryFieldGrammar
, c (List CommaFSep (Identity PkgconfigDependency) PkgconfigDependency)
, c (List CommaVCat (Identity Dependency) Dependency)
, c (List CommaVCat (Identity Mixin) Mixin)
, c (List VCat (Identity ExtraSource) ExtraSource)
, c (List CommaVCat (Identity ModuleReexport) ModuleReexport)
, c (List FSep (MQuoted Extension) Extension)
, c (List FSep (MQuoted Language) Language)
Expand All @@ -184,7 +185,6 @@ libraryFieldGrammar
, c (List FSep (SymbolicPathNT Include File) (SymbolicPath Include File))
, c (List FSep (RelativePathNT Framework File) (RelativePath Framework File))
, c (List FSep (RelativePathNT Include File) (RelativePath Include File))
, c (List VCat (SymbolicPathNT Pkg File) (SymbolicPath Pkg File))
, c (List VCat Token String)
, c (MQuoted Language)
)
Expand Down Expand Up @@ -225,6 +225,7 @@ foreignLibFieldGrammar
, c (List CommaFSep (Identity PkgconfigDependency) PkgconfigDependency)
, c (List CommaVCat (Identity Dependency) Dependency)
, c (List CommaVCat (Identity Mixin) Mixin)
, c (List VCat (Identity ExtraSource) ExtraSource)
, c (List FSep (Identity ForeignLibOption) ForeignLibOption)
, c (List FSep (MQuoted Extension) Extension)
, c (List FSep (MQuoted Language) Language)
Expand All @@ -236,7 +237,6 @@ foreignLibFieldGrammar
, c (List FSep (RelativePathNT Framework File) (RelativePath Framework File))
, c (List FSep (RelativePathNT Include File) (RelativePath Include File))
, c (List FSep (RelativePathNT Source File) (RelativePath Source File))
, c (List VCat (SymbolicPathNT Pkg File) (SymbolicPath Pkg File))
, c (List NoCommaFSep Token' String)
, c (List VCat (MQuoted ModuleName) ModuleName)
, c (List VCat Token String)
Expand Down Expand Up @@ -267,6 +267,7 @@ executableFieldGrammar
, c (List CommaFSep (Identity PkgconfigDependency) PkgconfigDependency)
, c (List CommaVCat (Identity Dependency) Dependency)
, c (List CommaVCat (Identity Mixin) Mixin)
, c (List VCat (Identity ExtraSource) ExtraSource)
, c (List FSep (MQuoted Extension) Extension)
, c (List FSep (MQuoted Language) Language)
, c (List FSep (SymbolicPathNT Pkg (Dir Framework)) (SymbolicPath Pkg (Dir Framework)))
Expand All @@ -276,7 +277,6 @@ executableFieldGrammar
, c (List FSep (SymbolicPathNT Include File) (SymbolicPath Include File))
, c (List FSep (RelativePathNT Framework File) (RelativePath Framework File))
, c (List FSep (RelativePathNT Include File) (RelativePath Include File))
, c (List VCat (SymbolicPathNT Pkg File) (SymbolicPath Pkg File))
, c (RelativePathNT Source File)
, c (List NoCommaFSep Token' String)
, c (List VCat (MQuoted ModuleName) ModuleName)
Expand Down Expand Up @@ -343,6 +343,7 @@ testSuiteFieldGrammar
, c (List CommaFSep Token String)
, c (List CommaVCat (Identity Dependency) Dependency)
, c (List CommaVCat (Identity Mixin) Mixin)
, c (List VCat (Identity ExtraSource) ExtraSource)
, c (List FSep (MQuoted Extension) Extension)
, c (List FSep (MQuoted Language) Language)
, c (List NoCommaFSep Token' String)
Expand All @@ -354,7 +355,6 @@ testSuiteFieldGrammar
, c (List FSep (SymbolicPathNT Include File) (SymbolicPath Include File))
, c (List FSep (RelativePathNT Framework File) (RelativePath Framework File))
, c (List FSep (RelativePathNT Include File) (RelativePath Include File))
, c (List VCat (SymbolicPathNT Pkg File) (SymbolicPath Pkg File))
, c (RelativePathNT Source File)
, c (List VCat Token String)
, c (MQuoted Language)
Expand Down Expand Up @@ -490,6 +490,7 @@ benchmarkFieldGrammar
, c (List CommaFSep (Identity PkgconfigDependency) PkgconfigDependency)
, c (List CommaVCat (Identity Dependency) Dependency)
, c (List CommaVCat (Identity Mixin) Mixin)
, c (List VCat (Identity ExtraSource) ExtraSource)
, c (List FSep (MQuoted Extension) Extension)
, c (List FSep (MQuoted Language) Language)
, c (List NoCommaFSep Token' String)
Expand All @@ -501,7 +502,6 @@ benchmarkFieldGrammar
, c (List FSep (SymbolicPathNT Include File) (SymbolicPath Include File))
, c (List FSep (RelativePathNT Framework File) (RelativePath Framework File))
, c (List FSep (RelativePathNT Include File) (RelativePath Include File))
, c (List VCat (SymbolicPathNT Pkg File) (SymbolicPath Pkg File))
, c (RelativePathNT Source File)
, c (List VCat Token String)
, c (MQuoted Language)
Expand Down Expand Up @@ -595,6 +595,7 @@ buildInfoFieldGrammar
, c (List CommaFSep (Identity PkgconfigDependency) PkgconfigDependency)
, c (List CommaVCat (Identity Dependency) Dependency)
, c (List CommaVCat (Identity Mixin) Mixin)
, c (List VCat (Identity ExtraSource) ExtraSource)
, c (List FSep (MQuoted Extension) Extension)
, c (List FSep (MQuoted Language) Language)
, c (List NoCommaFSep Token' String)
Expand All @@ -606,7 +607,6 @@ buildInfoFieldGrammar
, c (List FSep (SymbolicPathNT Include File) (SymbolicPath Include File))
, c (List FSep (RelativePathNT Framework File) (RelativePath Framework File))
, c (List FSep (RelativePathNT Include File) (RelativePath Include File))
, c (List VCat (SymbolicPathNT Pkg File) (SymbolicPath Pkg File))
, c (List VCat Token String)
, c (MQuoted Language)
)
Expand Down Expand Up @@ -649,16 +649,16 @@ buildInfoFieldGrammar = do
frameworks <- monoidalFieldAla "frameworks" (alaList' FSep RelativePathNT) L.frameworks
extraFrameworkDirs <- monoidalFieldAla "extra-framework-dirs" (alaList' FSep SymbolicPathNT) L.extraFrameworkDirs
asmSources <-
monoidalFieldAla "asm-sources" (alaList' VCat SymbolicPathNT) L.asmSources
monoidalFieldAla "asm-sources" formatExtraSources L.asmSources
^^^ availableSince CabalSpecV3_0 []
cmmSources <-
monoidalFieldAla "cmm-sources" (alaList' VCat SymbolicPathNT) L.cmmSources
monoidalFieldAla "cmm-sources" formatExtraSources L.cmmSources
^^^ availableSince CabalSpecV3_0 []
cSources <- monoidalFieldAla "c-sources" (alaList' VCat SymbolicPathNT) L.cSources
cSources <- monoidalFieldAla "c-sources" formatExtraSources L.cSources
cxxSources <-
monoidalFieldAla "cxx-sources" (alaList' VCat SymbolicPathNT) L.cxxSources
monoidalFieldAla "cxx-sources" formatExtraSources L.cxxSources
^^^ availableSince CabalSpecV2_2 []
jsSources <- monoidalFieldAla "js-sources" (alaList' VCat SymbolicPathNT) L.jsSources
jsSources <- monoidalFieldAla "js-sources" formatExtraSources L.jsSources
hsSourceDirs <- hsSourceDirsGrammar
otherModules <- monoidalFieldAla "other-modules" formatOtherModules L.otherModules
virtualModules <-
Expand Down Expand Up @@ -872,6 +872,9 @@ formatOtherExtensions = alaList' FSep MQuoted
formatOtherModules :: [ModuleName] -> List VCat (MQuoted ModuleName) ModuleName
formatOtherModules = alaList' VCat MQuoted

formatExtraSources :: [ExtraSource] -> List VCat (Identity ExtraSource) ExtraSource
formatExtraSources = alaList' VCat Identity

-------------------------------------------------------------------------------
-- newtypes
-------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions Cabal-syntax/src/Distribution/SPDX/LicenseListVersion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data LicenseListVersion
deriving (Eq, Ord, Show, Enum, Bounded)

cabalSpecVersionToSPDXListVersion :: CabalSpecVersion -> LicenseListVersion
cabalSpecVersionToSPDXListVersion CabalSpecV3_20 = LicenseListVersion_3_28
cabalSpecVersionToSPDXListVersion CabalSpecV3_18 = LicenseListVersion_3_28
cabalSpecVersionToSPDXListVersion CabalSpecV3_16 = LicenseListVersion_3_26
cabalSpecVersionToSPDXListVersion CabalSpecV3_14 = LicenseListVersion_3_25
Expand Down
18 changes: 11 additions & 7 deletions Cabal-syntax/src/Distribution/Types/BuildInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Prelude ()

import Distribution.Types.Dependency
import Distribution.Types.ExeDependency
import Distribution.Types.ExtraSource
import Distribution.Types.LegacyExeDependency
import Distribution.Types.Mixin
import Distribution.Types.PkgconfigDependency
Expand Down Expand Up @@ -72,13 +73,16 @@ data BuildInfo = BuildInfo
-- ^ support frameworks for Mac OS X
, extraFrameworkDirs :: [SymbolicPath Pkg (Dir Framework)]
-- ^ extra locations to find frameworks.
, asmSources :: [SymbolicPath Pkg File]
-- ^ Assembly files.
, cmmSources :: [SymbolicPath Pkg File]
-- ^ C-- files.
, cSources :: [SymbolicPath Pkg File]
, cxxSources :: [SymbolicPath Pkg File]
, jsSources :: [SymbolicPath Pkg File]
, asmSources :: [ExtraSource]
-- ^ Assembly source files
, cmmSources :: [ExtraSource]
-- ^ C-- source files
, cSources :: [ExtraSource]
-- ^ C source files
, cxxSources :: [ExtraSource]
-- ^ C++ source files
, jsSources :: [ExtraSource]
-- ^ JavaScript source files
, hsSourceDirs :: [SymbolicPath Pkg (Dir Source)]
-- ^ where to look for the Haskell module hierarchy
, -- NB: these are symbolic paths are not relative paths,
Expand Down
11 changes: 6 additions & 5 deletions Cabal-syntax/src/Distribution/Types/BuildInfo/Lens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Distribution.ModuleName (ModuleName)
import Distribution.Types.BuildInfo (BuildInfo)
import Distribution.Types.Dependency (Dependency)
import Distribution.Types.ExeDependency (ExeDependency)
import Distribution.Types.ExtraSource (ExtraSource)
import Distribution.Types.LegacyExeDependency (LegacyExeDependency)
import Distribution.Types.Mixin (Mixin)
import Distribution.Types.PkgconfigDependency (PkgconfigDependency)
Expand Down Expand Up @@ -83,23 +84,23 @@ class HasBuildInfo a where
extraFrameworkDirs = buildInfo . extraFrameworkDirs
{-# INLINE extraFrameworkDirs #-}

asmSources :: Lens' a [SymbolicPath Pkg File]
asmSources :: Lens' a [ExtraSource]
asmSources = buildInfo . asmSources
{-# INLINE asmSources #-}

cmmSources :: Lens' a [SymbolicPath Pkg File]
cmmSources :: Lens' a [ExtraSource]
cmmSources = buildInfo . cmmSources
{-# INLINE cmmSources #-}

cSources :: Lens' a [SymbolicPath Pkg File]
cSources :: Lens' a [ExtraSource]
cSources = buildInfo . cSources
{-# INLINE cSources #-}

cxxSources :: Lens' a [SymbolicPath Pkg File]
cxxSources :: Lens' a [ExtraSource]
cxxSources = buildInfo . cxxSources
{-# INLINE cxxSources #-}

jsSources :: Lens' a [SymbolicPath Pkg File]
jsSources :: Lens' a [ExtraSource]
jsSources = buildInfo . jsSources
{-# INLINE jsSources #-}

Expand Down
Loading
Loading