Skip to content

Commit df09931

Browse files
zlonastSwordlash
andcommitted
Add jsp-options (#10721)
Co-authored-by: Mateusz Goslinowski <[email protected]>
1 parent 96ce5a8 commit df09931

File tree

10 files changed

+58
-1
lines changed

10 files changed

+58
-1
lines changed

Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ buildInfoFieldGrammar =
621621
<*> monoidalFieldAla "cc-options" (alaList' NoCommaFSep Token') L.ccOptions
622622
<*> monoidalFieldAla "cxx-options" (alaList' NoCommaFSep Token') L.cxxOptions
623623
^^^ availableSince CabalSpecV2_2 []
624+
<*> monoidalFieldAla "jsp-options" (alaList' NoCommaFSep Token') L.jspOptions
625+
^^^ availableSince CabalSpecV3_14 []
624626
<*> monoidalFieldAla "ld-options" (alaList' NoCommaFSep Token') L.ldOptions
625627
<*> monoidalFieldAla "hsc2hs-options" (alaList' NoCommaFSep Token') L.hsc2hsOptions
626628
^^^ availableSince CabalSpecV3_6 []

Cabal-syntax/src/Distribution/Types/BuildInfo.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ data BuildInfo = BuildInfo
6161
-- ^ options for C compiler
6262
, cxxOptions :: [String]
6363
-- ^ options for C++ compiler
64+
, jspOptions :: [String]
65+
-- ^ options for pre-processing JavaScript code
6466
, ldOptions :: [String]
6567
-- ^ options for linker
6668
, hsc2hsOptions :: [String]
@@ -161,6 +163,7 @@ instance Monoid BuildInfo where
161163
, cmmOptions = []
162164
, ccOptions = []
163165
, cxxOptions = []
166+
, jspOptions = []
164167
, ldOptions = []
165168
, hsc2hsOptions = []
166169
, pkgconfigDepends = []
@@ -214,6 +217,7 @@ instance Semigroup BuildInfo where
214217
, cmmOptions = combine cmmOptions
215218
, ccOptions = combine ccOptions
216219
, cxxOptions = combine cxxOptions
220+
, jspOptions = combine jspOptions
217221
, ldOptions = combine ldOptions
218222
, hsc2hsOptions = combine hsc2hsOptions
219223
, pkgconfigDepends = combine pkgconfigDepends

Cabal-syntax/src/Distribution/Types/BuildInfo/Lens.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class HasBuildInfo a where
5959
cxxOptions = buildInfo . cxxOptions
6060
{-# INLINE cxxOptions #-}
6161

62+
jspOptions :: Lens' a [String]
63+
jspOptions = buildInfo . jspOptions
64+
{-# INLINE jspOptions #-}
65+
6266
ldOptions :: Lens' a [String]
6367
ldOptions = buildInfo . ldOptions
6468
{-# INLINE ldOptions #-}

Cabal/src/Distribution/PackageDescription/Check/Target.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ checkBuildInfoOptions t bi = do
814814
checkCLikeOptions LangC "cc-options" (ccOptions bi) ldOpts
815815
checkCLikeOptions LangCPlusPlus "cxx-options" (cxxOptions bi) ldOpts
816816
checkCPPOptions (cppOptions bi)
817+
checkJSPOptions (jspOptions bi)
817818

818819
-- | Checks GHC options for commonly misused or non-portable flags.
819820
checkGHCOptions
@@ -904,6 +905,12 @@ checkGHCOptions title t opts = do
904905
( [(flag, flag) | flag@('-' : 'D' : _) <- ghcNoRts]
905906
++ [(flag, flag) | flag@('-' : 'U' : _) <- ghcNoRts]
906907
)
908+
checkAlternatives
909+
title
910+
"jsp-options"
911+
( [(flag, flag) | flag@('-' : 'D' : _) <- ghcNoRts]
912+
++ [(flag, flag) | flag@('-' : 'U' : _) <- ghcNoRts]
913+
)
907914
checkAlternatives
908915
title
909916
"include-dirs"
@@ -1093,3 +1100,21 @@ checkCPPOptions opts = do
10931100
(PackageBuildWarning (COptCPP opt))
10941101
)
10951102
opts
1103+
1104+
checkJSPOptions
1105+
:: Monad m
1106+
=> [String] -- Options in String form.
1107+
-> CheckM m ()
1108+
checkJSPOptions opts = do
1109+
checkAlternatives
1110+
"jsp-options"
1111+
"include-dirs"
1112+
[(flag, dir) | flag@('-' : 'I' : dir) <- opts]
1113+
mapM_
1114+
( \opt ->
1115+
checkP
1116+
(not $ any (`isPrefixOf` opt) ["-D", "-U", "-I"])
1117+
(PackageBuildWarning (OptJSP opt))
1118+
)
1119+
opts
1120+

Cabal/src/Distribution/PackageDescription/Check/Warning.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ data CheckExplanation
214214
| OptWithRts String
215215
| COptONumber String WarnLang
216216
| COptCPP String
217+
| OptJSP String
217218
| OptAlternatives String String [(String, String)]
218219
| RelativeOutside String FilePath
219220
| AbsolutePath String FilePath
@@ -380,6 +381,7 @@ data CheckExplanationID
380381
| CIOptWithRts
381382
| CICOptONumber
382383
| CICOptCPP
384+
| CIOptJSP
383385
| CIOptAlternatives
384386
| CIRelativeOutside
385387
| CIAbsolutePath
@@ -525,6 +527,7 @@ checkExplanationId (OptRts{}) = CIOptRts
525527
checkExplanationId (OptWithRts{}) = CIOptWithRts
526528
checkExplanationId (COptONumber{}) = CICOptONumber
527529
checkExplanationId (COptCPP{}) = CICOptCPP
530+
checkExplanationId (OptJSP{}) = CIOptJSP
528531
checkExplanationId (OptAlternatives{}) = CIOptAlternatives
529532
checkExplanationId (RelativeOutside{}) = CIRelativeOutside
530533
checkExplanationId (AbsolutePath{}) = CIAbsolutePath
@@ -677,6 +680,7 @@ ppCheckExplanationId CIOptRts = "option-rtsopts"
677680
ppCheckExplanationId CIOptWithRts = "option-with-rtsopts"
678681
ppCheckExplanationId CICOptONumber = "option-opt-c"
679682
ppCheckExplanationId CICOptCPP = "cpp-options"
683+
ppCheckExplanationId CIOptJSP = "jsp-options"
680684
ppCheckExplanationId CIOptAlternatives = "misplaced-c-opt"
681685
ppCheckExplanationId CIRelativeOutside = "relative-path-outside"
682686
ppCheckExplanationId CIAbsolutePath = "absolute-path"
@@ -1086,6 +1090,8 @@ ppExplanation (COptONumber prefix label) =
10861090
++ " --disable-optimization flag."
10871091
ppExplanation (COptCPP opt) =
10881092
"'cpp-options: " ++ opt ++ "' is not a portable C-preprocessor flag."
1093+
ppExplanation (OptJSP opt) =
1094+
"'jsp-options: " ++ opt ++ "' is not a portable C-preprocessor flag."
10891095
ppExplanation (OptAlternatives badField goodField flags) =
10901096
"Instead of "
10911097
++ quote (badField ++ ": " ++ unwords badFlags)

Cabal/src/Distribution/Simple/GHC/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ componentJsGhcOptions verbosity lbi bi clbi odir filename =
510510
, ghcOptPackageDBs = withPackageDB lbi
511511
, ghcOptPackages = toNubListR $ mkGhcOptPackages (promisedPkgs lbi) clbi
512512
, ghcOptObjDir = toFlag odir
513-
, ghcOptExtra = hcOptions GHC bi
513+
, ghcOptExtra = jspOptions bi <> hcOptions GHC bi
514514
}
515515

516516
componentGhcOptions

doc/buildinfo-fields-reference.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ cmm-sources
256256
.. math::
257257
\mathrm{commalist}\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}\mathop{\mathord{``}\mathtt{\text{,}}\mathord{"}}]^c}}^+_{} \right\}
258258
259+
jsp-options
260+
* Monoidal field
261+
* Documentation of :pkg-field:`library:jsp-options`
262+
263+
.. math::
264+
{\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}]^c}}^+_{} \right\}}^\ast_{\bullet}
265+
259266
cpp-options
260267
* Monoidal field
261268
* Documentation of :pkg-field:`library:cpp-options`

doc/cabal-commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,7 @@ A list of all warnings with their constructor:
14051405
- ``option-with-rtsopts``: unnecessary ``-with-rtsopts``.
14061406
- ``option-opt-c``: unnecessary ``-O[n]`` in C code.
14071407
- ``cpp-options``: unportable ``-cpp-options`` flag.
1408+
- ``jsp-options``: unportable ``-jsp-options`` flag.
14081409
- ``misplaced-c-opt``: C-like options in wrong cabal field.
14091410
- ``relative-path-outside``: relative path outside of source tree.
14101411
- ``absolute-path``: absolute path where not allowed.

doc/cabal-package-description-file.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,13 @@ system-dependent values for these fields.
19921992
arguments are compiler-dependent, this field is more useful with the
19931993
setup described in the section on `system-dependent parameters`_.
19941994

1995+
.. pkg-field:: jsp-options: token list
1996+
1997+
Command-line arguments for pre-processing Haskell code. Applies to
1998+
Haskell source and other pre-processed Haskell source like .js.
1999+
Does not apply to C code, that's what cc-options is for.
2000+
Flags here will be passed as ``-optJSP`` flags to GHC.
2001+
19952002
.. pkg-field:: cpp-options: token list
19962003

19972004
Command-line arguments for pre-processing Haskell code. Applies to

editors/vim/syntax/cabal.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ syn keyword cabalFieldName contained
6565
\ cmm-options
6666
\ cmm-sources
6767
\ copyright
68+
\ jsp-options
6869
\ cpp-options
6970
\ cxx-options
7071
\ cxx-sources

0 commit comments

Comments
 (0)