From 4f2fbc519ed94ebf5af802bb3ebfc9161023abdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Go=C5=9Blinowski?= Date: Sun, 12 Jan 2025 15:35:05 +0100 Subject: [PATCH] Add JsOptions test, use 3.14 as min required cabal version --- .../PackageDescription/FieldGrammar.hs | 1 + .../PackageTests/JS/JsOptions/cabal.project | 1 + .../PackageTests/JS/JsOptions/demo/Main.hs | 6 ++++++ .../PackageTests/JS/JsOptions/js.test.hs | 9 +++++++++ .../PackageTests/JS/JsOptions/jsbits/lib.js | 9 +++++++++ .../PackageTests/JS/JsOptions/jsoptions.cabal | 19 +++++++++++++++++++ .../PackageTests/JS/JsOptions/other-arch.out | 14 ++++++++++++++ .../JS/JsOptions/other-arch.test.hs | 8 ++++++++ .../PackageTests/JS/JsOptions/src/Lib.hs | 9 +++++++++ doc/buildinfo-fields-reference.rst | 8 ++++++++ editors/vim/syntax/cabal.vim | 1 + 11 files changed, 85 insertions(+) create mode 100644 cabal-testsuite/PackageTests/JS/JsOptions/cabal.project create mode 100644 cabal-testsuite/PackageTests/JS/JsOptions/demo/Main.hs create mode 100644 cabal-testsuite/PackageTests/JS/JsOptions/js.test.hs create mode 100644 cabal-testsuite/PackageTests/JS/JsOptions/jsbits/lib.js create mode 100644 cabal-testsuite/PackageTests/JS/JsOptions/jsoptions.cabal create mode 100644 cabal-testsuite/PackageTests/JS/JsOptions/other-arch.out create mode 100644 cabal-testsuite/PackageTests/JS/JsOptions/other-arch.test.hs create mode 100644 cabal-testsuite/PackageTests/JS/JsOptions/src/Lib.hs diff --git a/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs b/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs index 433c410fadc..4c2932f0394 100644 --- a/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs +++ b/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs @@ -622,6 +622,7 @@ buildInfoFieldGrammar = <*> monoidalFieldAla "cxx-options" (alaList' NoCommaFSep Token') L.cxxOptions ^^^ availableSince CabalSpecV2_2 [] <*> monoidalFieldAla "js-options" (alaList' NoCommaFSep Token') L.jsOptions + ^^^ availableSince CabalSpecV3_14 [] <*> monoidalFieldAla "ld-options" (alaList' NoCommaFSep Token') L.ldOptions <*> monoidalFieldAla "hsc2hs-options" (alaList' NoCommaFSep Token') L.hsc2hsOptions ^^^ availableSince CabalSpecV3_6 [] diff --git a/cabal-testsuite/PackageTests/JS/JsOptions/cabal.project b/cabal-testsuite/PackageTests/JS/JsOptions/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsOptions/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/JS/JsOptions/demo/Main.hs b/cabal-testsuite/PackageTests/JS/JsOptions/demo/Main.hs new file mode 100644 index 00000000000..19e67f001f8 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsOptions/demo/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Lib + +main :: IO () +main = foo diff --git a/cabal-testsuite/PackageTests/JS/JsOptions/js.test.hs b/cabal-testsuite/PackageTests/JS/JsOptions/js.test.hs new file mode 100644 index 00000000000..c7df6e8e986 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsOptions/js.test.hs @@ -0,0 +1,9 @@ +import Test.Cabal.Prelude + +main = do + skipUnlessJavaScript + skipIfWindows "" + setupAndCabalTest $ do + skipUnlessGhcVersion ">= 9.12" + res <- cabal' "v2-run" ["demo"] + assertOutputContains "Hello definition!" res diff --git a/cabal-testsuite/PackageTests/JS/JsOptions/jsbits/lib.js b/cabal-testsuite/PackageTests/JS/JsOptions/jsbits/lib.js new file mode 100644 index 00000000000..b3b8beb78fb --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsOptions/jsbits/lib.js @@ -0,0 +1,9 @@ +//#OPTIONS: CPP + +function foo() { +#ifdef PRINT_DEF + console.log("Hello definition!"); +#else + console.log("Hello!"); +#endif +} diff --git a/cabal-testsuite/PackageTests/JS/JsOptions/jsoptions.cabal b/cabal-testsuite/PackageTests/JS/JsOptions/jsoptions.cabal new file mode 100644 index 00000000000..00d6b3e9089 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsOptions/jsoptions.cabal @@ -0,0 +1,19 @@ +cabal-version: 3.14 +name: jsoptions +version: 0 +build-type: Simple + +library + default-language: Haskell2010 + exposed-modules: Lib + build-depends: base + + if impl(javascript) + js-sources: jsbits/lib.js + js-options: -optJSP-DPRINT_DEF + +executable demo + default-language: Haskell2010 + main-is: Main.hs + hs-source-dirs: demo + build-depends: base, jsoptions diff --git a/cabal-testsuite/PackageTests/JS/JsOptions/other-arch.out b/cabal-testsuite/PackageTests/JS/JsOptions/other-arch.out new file mode 100644 index 00000000000..eeec21715d5 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsOptions/other-arch.out @@ -0,0 +1,14 @@ +# cabal v2-run +Configuration is affected by the following files: +- cabal.project +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - jsoptions-exe-0 (lib) (first run) + - jsoptions-exe-0 (exe:demo) (first run) +Configuring library for jsoptions-exe-0... +Preprocessing library for jsoptions-exe-0... +Building library for jsoptions-exe-0... +Configuring executable 'demo' for jsoptions-exe-0... +Preprocessing executable 'demo' for jsoptions-exe-0... +Building executable 'demo' for jsoptions-exe-0... diff --git a/cabal-testsuite/PackageTests/JS/JsOptions/other-arch.test.hs b/cabal-testsuite/PackageTests/JS/JsOptions/other-arch.test.hs new file mode 100644 index 00000000000..0659304d12b --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsOptions/other-arch.test.hs @@ -0,0 +1,8 @@ +import Test.Cabal.Prelude + +main = do + skipIfJavaScript + cabalTest $ do + -- Ensure the field `js-options` does not raise issues + res <- cabal' "v2-run" ["demo"] + assertOutputContains "foo_fallback" res diff --git a/cabal-testsuite/PackageTests/JS/JsOptions/src/Lib.hs b/cabal-testsuite/PackageTests/JS/JsOptions/src/Lib.hs new file mode 100644 index 00000000000..a61f3098927 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsOptions/src/Lib.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE CPP #-} +module Lib where + +#if defined(javascript_HOST_ARCH) +foreign import javascript foo :: IO () +#else +foo :: IO () +foo = putStrLn "foo_fallback" +#endif \ No newline at end of file diff --git a/doc/buildinfo-fields-reference.rst b/doc/buildinfo-fields-reference.rst index a289292945a..27fefbb8030 100644 --- a/doc/buildinfo-fields-reference.rst +++ b/doc/buildinfo-fields-reference.rst @@ -268,6 +268,14 @@ cxx-options .. math:: {\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}]^c}}^+_{} \right\}}^\ast_{\bullet} +js-options + * Monoidal field + * Available since ``cabal-version: 3.14``. + * Documentation of :pkg-field:`library:js-options` + + .. math:: + {\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}]^c}}^+_{} \right\}}^\ast_{\bullet} + cxx-sources * Monoidal field * Available since ``cabal-version: 2.2``. diff --git a/editors/vim/syntax/cabal.vim b/editors/vim/syntax/cabal.vim index 2e578307a7e..349f244178e 100644 --- a/editors/vim/syntax/cabal.vim +++ b/editors/vim/syntax/cabal.vim @@ -67,6 +67,7 @@ syn keyword cabalFieldName contained \ copyright \ cpp-options \ cxx-options + \ js-options \ cxx-sources \ data-dir \ data-files