From beb5a37119e99b8d414ca8f5729e01af6b767e7e Mon Sep 17 00:00:00 2001
From: Herbert Valerio Riedel <hvr@gnu.org>
Date: Mon, 5 Feb 2018 07:36:03 +0100
Subject: Add `SPDX-License-Identifier` as alised for "license" module header
 tokens

C.f. SPDX 2.1 - Appendix V
 https://spdx.org/spdx-specification-21-web-version#h.twlc0ztnng3b

    The tag should appear on its own line in the source file, generally as part of a comment.

    SPDX-License-Identifier: <SPDX License Expression>

Cherry-picked from #743
---
 CHANGES.md                                             |  3 +++
 haddock-api/src/Haddock/Interface/ParseModuleHeader.hs | 11 ++++++-----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 38346c00..ab2ef01a 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -28,6 +28,9 @@
  * Overhaul Haddock's rendering of kind signatures so that invisible kind
    parameters are not printed (#681)
 
+ * Recognise `SPDX-License-Identifier` as alias for `License` in module header
+   parser (#743)
+
 ## Changes in version 2.18.1
 
  * Synopsis is working again (#599)
diff --git a/haddock-api/src/Haddock/Interface/ParseModuleHeader.hs b/haddock-api/src/Haddock/Interface/ParseModuleHeader.hs
index 768a31ce..6690c22d 100644
--- a/haddock-api/src/Haddock/Interface/ParseModuleHeader.hs
+++ b/haddock-api/src/Haddock/Interface/ParseModuleHeader.hs
@@ -37,21 +37,22 @@ parseModuleHeader dflags str0 =
       (copyrightOpt,str3) = getKey "Copyright" str2
       (licenseOpt,str4) = getKey "License" str3
       (licenceOpt,str5) = getKey "Licence" str4
-      (maintainerOpt,str6) = getKey "Maintainer" str5
-      (stabilityOpt,str7) = getKey "Stability" str6
-      (portabilityOpt,str8) = getKey "Portability" str7
+      (spdxLicenceOpt,str6) = getKey "SPDX-License-Identifier" str5
+      (maintainerOpt,str7) = getKey "Maintainer" str6
+      (stabilityOpt,str8) = getKey "Stability" str7
+      (portabilityOpt,str9) = getKey "Portability" str8
 
    in (HaddockModInfo {
           hmi_description = parseString dflags <$> descriptionOpt,
           hmi_copyright = copyrightOpt,
-          hmi_license = licenseOpt `mplus` licenceOpt,
+          hmi_license = spdxLicenceOpt `mplus` licenseOpt `mplus` licenceOpt,
           hmi_maintainer = maintainerOpt,
           hmi_stability = stabilityOpt,
           hmi_portability = portabilityOpt,
           hmi_safety = Nothing,
           hmi_language = Nothing, -- set in LexParseRn
           hmi_extensions = [] -- also set in LexParseRn
-          }, parseParas dflags str8)
+          }, parseParas dflags str9)
 
 -- | This function is how we read keys.
 --
-- 
cgit v1.2.3