Commit e81f0e90 authored by Oleg Grenrus's avatar Oleg Grenrus
Browse files

Make license files field SymbolicPath

parent 81d997ac
......@@ -231,16 +231,9 @@ roundtripTest testFieldsTransform fpath bs = do
let bs' = showGenericPackageDescription x0
y0 <- parse "2nd" (toUTF8BS bs')
-- we mungled license here
let y1 = y0
-- license-files: ""
let stripEmpty = filter (/="")
let x1 = x0 & L.packageDescription . L.licenseFiles %~ stripEmpty
let y2 = y1 & L.packageDescription . L.licenseFiles %~ stripEmpty
let y = y2 & L.packageDescription . L.description .~ mempty
let x = x1 & L.packageDescription . L.description .~ mempty
-- strip description, there are format variations
let y = y0 & L.packageDescription . L.description .~ mempty
let x = x0 & L.packageDescription . L.description .~ mempty
assertEqual' bs' x y
......
......@@ -333,7 +333,7 @@ GenericPackageDescription
foreignLibs = [],
homepage = "https://github.com/mgajda/octree",
library = Nothing,
licenseFiles = ["LICENSE"],
licenseFiles = [SymbolicPath "LICENSE"],
licenseRaw = Right BSD3,
maintainer = "mjgajda@googlemail.com",
package = PackageIdentifier
......
......@@ -744,7 +744,7 @@ GenericPackageDescription
foreignLibs = [],
homepage = "",
library = Nothing,
licenseFiles = ["LICENSE"],
licenseFiles = [SymbolicPath "LICENSE"],
licenseRaw = Right BSD3,
maintainer = "andres@well-typed.com",
package = PackageIdentifier
......
......@@ -444,7 +444,7 @@ GenericPackageDescription
foreignLibs = [],
homepage = "",
library = Nothing,
licenseFiles = ["LICENSE"],
licenseFiles = [SymbolicPath "LICENSE"],
licenseRaw = Left
(License (ELicense (ELicenseId BSD_3_Clause) Nothing)),
maintainer = "Sam Halliday",
......
......@@ -652,7 +652,7 @@ GenericPackageDescription
foreignLibs = [],
homepage = "https://github.com/phadej/postgresql-libpq",
library = Nothing,
licenseFiles = ["LICENSE"],
licenseFiles = [SymbolicPath "LICENSE"],
licenseRaw = Right BSD3,
maintainer = "Oleg Grenrus <oleg.grenrus@iki.fi>",
package = PackageIdentifier
......
......@@ -652,7 +652,7 @@ GenericPackageDescription
foreignLibs = [],
homepage = "https://github.com/phadej/postgresql-libpq",
library = Nothing,
licenseFiles = ["LICENSE"],
licenseFiles = [SymbolicPath "LICENSE"],
licenseRaw = Left
(License (ELicense (ELicenseId BSD_3_Clause) Nothing)),
maintainer = "Oleg Grenrus <oleg.grenrus@iki.fi>",
......
......@@ -126,7 +126,7 @@ GenericPackageDescription
foreignLibs = [],
homepage = "http://comonad.com/haskell/monad-param/dist/doc/html/Control-Monad-Parameterized.html",
library = Nothing,
licenseFiles = ["LICENSE"],
licenseFiles = [SymbolicPath "LICENSE"],
licenseRaw = Right BSD3,
maintainer = "Edward Kmett <ekmett@gmail.com>",
package = PackageIdentifier
......
......@@ -2499,7 +2499,7 @@ GenericPackageDescription
foreignLibs = [],
homepage = "http://shakebuild.com",
library = Nothing,
licenseFiles = ["LICENSE"],
licenseFiles = [SymbolicPath "LICENSE"],
licenseRaw = Right BSD3,
maintainer = "Neil Mitchell <ndmitchell@gmail.com>",
package = PackageIdentifier
......
......@@ -551,7 +551,7 @@ GenericPackageDescription
foreignLibs = [],
homepage = "http://github.com/bennofs/th-lift-instances/",
library = Nothing,
licenseFiles = ["LICENSE"],
licenseFiles = [SymbolicPath "LICENSE"],
licenseRaw = Right BSD3,
maintainer = "Benno F\252nfst\252ck <benno.fuenfstueck@gmail.com>",
package = PackageIdentifier
......
......@@ -196,7 +196,7 @@ GenericPackageDescription
foreignLibs = [],
homepage = "",
library = Nothing,
licenseFiles = ["LICENSE"],
licenseFiles = [SymbolicPath "LICENSE"],
licenseRaw = Right BSD3,
maintainer = "Noam Lewis <jones.noamle@gmail.com>",
package = PackageIdentifier
......
......@@ -24,7 +24,7 @@ tests = testGroup "Distribution.Utils.Structured"
, testCase "SPDX.License" $ structureHash (Proxy :: Proxy License) @?= md5FromInteger 0xd3d4a09f517f9f75bc3d16370d5a853a
-- The difference is in encoding of newtypes
#if MIN_VERSION_base(4,7,0)
, testCase "GenericPackageDescription" $ structureHash (Proxy :: Proxy GenericPackageDescription) @?= md5FromInteger 0x7c423920f9ef69d0bb662ced46d6c764
, testCase "LocalBuildInfo" $ structureHash (Proxy :: Proxy LocalBuildInfo) @?= md5FromInteger 0x2903e5b827c9fc28ac8353e22867939b
, testCase "GenericPackageDescription" $ structureHash (Proxy :: Proxy GenericPackageDescription) @?= md5FromInteger 0x1e02ad776ad91e10d644d1ead8927205
, testCase "LocalBuildInfo" $ structureHash (Proxy :: Proxy LocalBuildInfo) @?= md5FromInteger 0x06bf760ed08809b56b165f72d485b9c5
#endif
]
......@@ -1135,7 +1135,7 @@ checkPaths pkg =
[ (path, "extra-doc-files", PathKindGlob) | path <- extraDocFiles pkg ] ++
[ (path, "data-files", PathKindGlob) | path <- dataFiles pkg ] ++
[ (path, "data-dir", PathKindDirectory) | path <- [dataDir pkg]] ++
[ (path, "license-file", PathKindFile) | path <- licenseFiles pkg ] ++
[ (path, "license-file", PathKindFile) | path <- map getSymbolicPath $ licenseFiles pkg ] ++
concat
[ [ (path, "asm-sources", PathKindFile) | path <- asmSources bi ] ++
[ (path, "cmm-sources", PathKindFile) | path <- cmmSources bi ] ++
......@@ -1875,11 +1875,11 @@ checkLicensesExist :: (Monad m, Applicative m)
-> PackageDescription
-> m [PackageCheck]
checkLicensesExist ops pkg = do
exists <- traverse (doesFileExist ops) (licenseFiles pkg)
exists <- traverse (doesFileExist ops . getSymbolicPath) (licenseFiles pkg)
return
[ PackageBuildWarning $
"The '" ++ fieldname ++ "' field refers to the file "
++ quote file ++ " which does not exist."
++ quote (getSymbolicPath file) ++ " which does not exist."
| (file, False) <- zip (licenseFiles pkg) exists ]
where
fieldname | length (licenseFiles pkg) == 1 = "license-file"
......
......@@ -57,7 +57,7 @@ import Language.Haskell.Extension
import Prelude ()
import Distribution.CabalSpecVersion
import Distribution.Compat.Newtype (Newtype)
import Distribution.Compat.Newtype (Newtype, pack', unpack')
import Distribution.Compiler (CompilerFlavor (..), PerCompilerFlavor (..))
import Distribution.FieldGrammar
import Distribution.Fields
......@@ -69,9 +69,10 @@ import Distribution.Pretty (Pretty (..), prettyShow, showToken)
import Distribution.Utils.Path
import Distribution.Version (Version, VersionRange)
import qualified Data.ByteString.Char8 as BS8
import qualified Distribution.SPDX as SPDX
import qualified Distribution.Types.Lens as L
import qualified Data.ByteString.Char8 as BS8
import qualified Distribution.Compat.CharParsing as P
import qualified Distribution.SPDX as SPDX
import qualified Distribution.Types.Lens as L
-------------------------------------------------------------------------------
-- PackageDescription
......@@ -84,9 +85,11 @@ packageDescriptionFieldGrammar
, c (Identity Version)
, c (List FSep FilePathNT String)
, c (List FSep CompatFilePath String)
, c (List FSep (Identity (SymbolicPath PackageDir LicenseFile)) (SymbolicPath PackageDir LicenseFile))
, c (List FSep TestedWith (CompilerFlavor, VersionRange))
, c (List VCat FilePathNT String)
, c FilePathNT
, c CompatLicenseFile
, c CompatFilePath
, c SpecLicense
, c SpecVersion
......@@ -97,7 +100,6 @@ packageDescriptionFieldGrammar = PackageDescription
<*> blurFieldGrammar L.package packageIdentifierGrammar
<*> optionalFieldDefAla "license" SpecLicense L.licenseRaw (Left SPDX.NONE)
<*> licenseFilesGrammar
^^^ fmap (filter (not . null)) -- strip empty filepaths
<*> freeTextFieldDefST "copyright" L.copyright
<*> freeTextFieldDefST "maintainer" L.maintainer
<*> freeTextFieldDefST "author" L.author
......@@ -136,8 +138,8 @@ packageDescriptionFieldGrammar = PackageDescription
-- TODO: neither field is deprecated
-- should we pretty print license-file if there's single license file
-- and license-files when more
<$> monoidalFieldAla "license-file" (alaList' FSep CompatFilePath) L.licenseFiles
<*> monoidalFieldAla "license-files" (alaList' FSep CompatFilePath) L.licenseFiles
<$> monoidalFieldAla "license-file" CompatLicenseFile L.licenseFiles
<*> monoidalFieldAla "license-files" (alaList FSep) L.licenseFiles
^^^ hiddenField
-------------------------------------------------------------------------------
......@@ -745,6 +747,23 @@ instance Parsec CompatFilePath where
instance Pretty CompatFilePath where
pretty = showToken . getCompatFilePath
newtype CompatLicenseFile = CompatLicenseFile { getCompatLicenseFile :: [SymbolicPath PackageDir LicenseFile] }
instance Newtype [SymbolicPath PackageDir LicenseFile] CompatLicenseFile
-- TODO
instance Parsec CompatLicenseFile where
parsec = emptyToken <|> CompatLicenseFile . unpack' (alaList FSep) <$> parsec
where
emptyToken = P.try $ do
token <- parsecToken
if null token
then return (CompatLicenseFile [])
else P.unexpected "non-empty-token"
instance Pretty CompatLicenseFile where
pretty = pretty . pack' (alaList FSep) . getCompatLicenseFile
-------------------------------------------------------------------------------
-- vim syntax definitions
-------------------------------------------------------------------------------
......
......@@ -279,6 +279,16 @@ patches = Map.fromList
(Fingerprint 12566783342663020458 17562089389615949789)
(Fingerprint 15745683452603944938 10556498036622072844)
(bsReplace "\"\"" ".")
-- absolute license-file
, mk "name: reheat\nversion: 0.1.4\ncabal-version: >=1.8\nbuild-type: Simple\nlicense: GPL\nlicense-file: /home/palo/dev/haskell-workspace/playground/reheat/gpl-3.0.txt\ncopyright: GPL\nmaintainer: Ingolf Wagner <palipalo9@gmail.com>\nstability: experimental\nhomepage: h"
(Fingerprint 9155400339287317061 14812953666990892802)
(Fingerprint 7687053346032173923 15384472501136606592)
(bsReplace "/home/palo/dev/haskell-workspace/playground/reheat/gpl-3.0.txt" "")
, mk "name: reheat\nversion: 0.1.5\ncabal-version: >=1.8\nbuild-type: Simple\nlicense: GPL\nlicense-file: /home/palo/dev/haskell-workspace/playground/reheat/gpl-3.0.txt\ncopyright: GPL\nmaintainer: Ingolf Wagner <palipalo9@gmail.com>\nstability: experimental\nhomepage: h"
(Fingerprint 2984391146441073709 11728234882049907993)
(Fingerprint 12058479081855347701 14017937756688869826)
(bsReplace "/home/palo/dev/haskell-workspace/playground/reheat/gpl-3.0.txt" "")
]
where
mk a b c d = ((a, b), (c, d))
......
......@@ -43,6 +43,7 @@ import Distribution.Simple.Compiler
import Distribution.Simple.Setup
( CopyFlags(..), fromFlag, HaddockTarget(ForDevelopment) )
import Distribution.Simple.BuildTarget
import Distribution.Utils.Path (getSymbolicPath)
import qualified Distribution.Simple.GHC as GHC
import qualified Distribution.Simple.GHCJS as GHCJS
......@@ -136,9 +137,10 @@ copyPackage verbosity pkg_descr lbi distPref copydest = do
let lfiles = licenseFiles pkg_descr
unless (null lfiles) $ do
createDirectoryIfMissingVerbose verbosity True docPref
sequence_
[ installOrdinaryFile verbosity lfile (docPref </> takeFileName lfile)
| lfile <- lfiles ]
for_ lfiles $ \lfile' -> do
let lfile :: FilePath
lfile = getSymbolicPath lfile'
installOrdinaryFile verbosity lfile (docPref </> takeFileName lfile)
-- | Copy files associated with a component.
copyComponent :: Verbosity -> PackageDescription
......
......@@ -235,7 +235,7 @@ listPackageSources' verbosity rip cwd pkg_descr pps =
matchDirFileGlobWithDie verbosity rip (specVersion pkg_descr) cwd filename
-- License file(s).
, return (licenseFiles pkg_descr)
, return (map getSymbolicPath $ licenseFiles pkg_descr)
-- Install-include files, without autogen-include files
, fmap concat
......
......@@ -87,6 +87,7 @@ import Distribution.Compiler
import Distribution.License
import Distribution.Package
import Distribution.Version
import Distribution.Utils.Path
import Distribution.Utils.ShortText
import qualified Distribution.SPDX as SPDX
......@@ -108,7 +109,7 @@ data PackageDescription
specVersion :: CabalSpecVersion,
package :: PackageIdentifier,
licenseRaw :: Either SPDX.License License,
licenseFiles :: [FilePath],
licenseFiles :: [SymbolicPath PackageDir LicenseFile],
copyright :: !ShortText,
maintainer :: !ShortText,
author :: !ShortText,
......
......@@ -30,6 +30,7 @@ import Distribution.Types.SetupBuildInfo (SetupBuildInfo)
import Distribution.Types.SourceRepo (SourceRepo)
import Distribution.Types.TestSuite (TestSuite, testModules)
import Distribution.Types.TestSuite.Lens (testBuildInfo, testName)
import Distribution.Utils.Path (LicenseFile, PackageDir, SymbolicPath)
import Distribution.Utils.ShortText (ShortText)
import Distribution.Version (VersionRange)
......@@ -44,7 +45,7 @@ licenseRaw :: Lens' PackageDescription (Either SPDX.License License)
licenseRaw f s = fmap (\x -> s { T.licenseRaw = x }) (f (T.licenseRaw s))
{-# INLINE licenseRaw #-}
licenseFiles :: Lens' PackageDescription [FilePath]
licenseFiles :: Lens' PackageDescription [SymbolicPath PackageDir LicenseFile]
licenseFiles f s = fmap (\x -> s { T.licenseFiles = x }) (f (T.licenseFiles s))
{-# INLINE licenseFiles #-}
......
......@@ -10,6 +10,7 @@ module Distribution.Utils.Path (
-- * Path ends
PackageDir,
SourceDir,
LicenseFile,
IsDir,
) where
......@@ -91,9 +92,12 @@ class IsDir dir
data PackageDir deriving (Typeable)
data SourceDir deriving (Typeable)
data LicenseFile deriving (Typeable)
-- These instances needs to be derived standalone at least on GHC-7.6
deriving instance Data PackageDir
deriving instance Data SourceDir
deriving instance Data LicenseFile
instance IsDir PackageDir
instance IsDir SourceDir
......@@ -120,13 +120,13 @@ doctest-cli :
# tests
check-tests :
$(CABALRUN) check-tests -- --cwd Cabal ${TEST}
$(CABALRUN) check-tests -- --cwd Cabal-tests ${TEST}
parser-tests :
$(CABALRUN) parser-tests -- --cwd Cabal ${TEST}
$(CABALRUN) parser-tests -- --cwd Cabal-tests ${TEST}
parser-tests-accept :
$(CABALRUN) parser-tests -- --cwd Cabal --accept ${TEST}
$(CABALRUN) parser-tests -- --cwd Cabal-tests --accept ${TEST}
custom-setup-tests :
$(CABALRUN) custom-setup-tests --
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment