Skip to content

Commit

Permalink
Restore old licence acceptance logic for pre-cabal-version:2.2
Browse files Browse the repository at this point in the history
In 5c06aba the legacy licence enum was
mapped to SPDX licences, thereby implicitly disallowing the use of
`OtherLicence`; this commit avoids mapping legacy licences to SPDX and
restores the original acceptance-check, thereby re-allowing `OtherLicence`s
  • Loading branch information
hvr committed Apr 30, 2018
1 parent c574405 commit af9096e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Distribution/Server/Packages/Unpack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Distribution.Package
import Distribution.PackageDescription
( GenericPackageDescription(..), PackageDescription(..)
, allBuildInfo, allLibraries
, mixins, signatures, specVersion, license
, mixins, signatures, specVersion, licenseRaw
)
import Distribution.PackageDescription.Configuration
( flattenPackageDescription )
Expand All @@ -39,6 +39,7 @@ import Distribution.Text
( Text(..), display, simpleParse )
import Distribution.Server.Util.ParseSpecVer
import qualified Distribution.SPDX as SPDX
import qualified Distribution.License as License
import qualified Distribution.Compat.ReadP as Parse

import Control.Monad.Except
Expand Down Expand Up @@ -515,11 +516,12 @@ startsWithBOM bs = LBS.take 3 bs == LBS.pack [0xEF, 0xBB, 0xBF]
-- OSI-accepted licenses or CC0
--
isAcceptableLicense :: PackageDescription -> Bool
isAcceptableLicense = go . license
isAcceptableLicense = either goSpdx goLegacy . licenseRaw
where
go :: SPDX.License -> Bool
go SPDX.NONE = False
go (SPDX.License expr) = goExpr expr
-- `cabal-version: 2.2` and later
goSpdx :: SPDX.License -> Bool
goSpdx SPDX.NONE = False
goSpdx (SPDX.License expr) = goExpr expr
where
goExpr (SPDX.EAnd a b) = goExpr a && goExpr b
goExpr (SPDX.EOr a b) = goExpr a || goExpr b
Expand All @@ -530,3 +532,7 @@ isAcceptableLicense = go . license
goSimple (SPDX.ELicenseIdPlus _) = False -- don't allow + licenses (use GPL-3.0-or-later e.g.)
goSimple (SPDX.ELicenseId SPDX.CC0_1_0) = True -- CC0 isn't OSI approved, but we allow it as "PublicDomain", this is eg. PublicDomain in http://hackage.haskell.org/package/string-qq-0.0.2/src/LICENSE
goSimple (SPDX.ELicenseId lid) = SPDX.licenseIsOsiApproved lid -- allow only OSI approved licenses.

-- pre `cabal-version: 2.2`
goLegacy License.AllRightsReserved = False
goLegacy _ = True

0 comments on commit af9096e

Please sign in to comment.