From 3fac0c59b876f98936f5e5bf0d6753f4f52259ed Mon Sep 17 00:00:00 2001 From: Francesco Ariis Date: Sat, 14 Sep 2024 13:25:51 +0200 Subject: [PATCH] Handle licences starting with a digit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cabal has a devscript that parses a json file (containing SPDX licences) and returns a number of of Haskell data constructors. There have been problems when the SPDX short identifier starts with a digit (e.g. “0BSD”), as that would generate an data constructor starting with a digit, which is not valid Haskell. The way to handle such occourrences was in an ad-hoc basis. This patch prepend “NN_” to the beginning of every SPDX licence starting with a digit, future-proofing the script. --- cabal-dev-scripts/src/GenUtils.hs | 8 +++++--- changelog.d/pr-10356 | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 changelog.d/pr-10356 diff --git a/cabal-dev-scripts/src/GenUtils.hs b/cabal-dev-scripts/src/GenUtils.hs index 7d7b39c2add..c47b34df92f 100644 --- a/cabal-dev-scripts/src/GenUtils.hs +++ b/cabal-dev-scripts/src/GenUtils.hs @@ -15,6 +15,7 @@ import Data.Text (Text) import GHC.Generics (Generic) import qualified Data.Algorithm.Diff as Diff +import qualified Data.Char as C import qualified Data.Map as Map import qualified Data.Set as Set import qualified Data.Text as T @@ -160,9 +161,10 @@ toConstructorName t = t f c = c special :: Text -> Text - special "0BSD" = "NullBSD" - special "389_exception" = "DS389_exception" - special u = u + special u + | Just (c, _) <- T.uncons u + , C.isDigit c = "NN_" <> u + special u = u mkList :: [Text] -> Text mkList [] = " []" diff --git a/changelog.d/pr-10356 b/changelog.d/pr-10356 new file mode 100644 index 00000000000..5c73e4fdbf6 --- /dev/null +++ b/changelog.d/pr-10356 @@ -0,0 +1,11 @@ +synopsis: New licence constructors for SPDX licences starting with a digit +packages: Cabal-syntax +prs: #10356 + +description: { + +- LicenseId constructor `NullBSD` is now `NN_0BSD`. +- LicenseId constructor `DS389_exception` is now and `NN_389_exception`. +- LicenseId constructor `X3D_Slicer_1_0` is now and `NN_3D_Slicer_1_0`. + +}