From ca5d19f475fe58521452273faa5e995a6b49e5bb Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 14 Jul 2023 19:28:29 -0400 Subject: [PATCH 1/8] Render short option with arg. (#9043) --- Cabal/src/Distribution/GetOpt.hs | 53 +++++++--- Cabal/src/Distribution/Simple/Command.hs | 30 +++--- Cabal/src/Distribution/Simple/Setup/Common.hs | 4 +- Cabal/src/Distribution/Simple/Setup/Config.hs | 4 +- .../src/Distribution/Client/CmdOutdated.hs | 2 +- .../src/Distribution/Client/Setup.hs | 6 +- changelog.d/issue-8785 | 17 ++++ doc/cabal-commands.rst | 62 ++++++------ doc/cabal-project.rst | 69 ++++++------- doc/setup-commands.rst | 97 ++++++++++--------- 10 files changed, 200 insertions(+), 144 deletions(-) create mode 100644 changelog.d/issue-8785 diff --git a/Cabal/src/Distribution/GetOpt.hs b/Cabal/src/Distribution/GetOpt.hs index 3a02fede464..7e31fa165f4 100644 --- a/Cabal/src/Distribution/GetOpt.hs +++ b/Cabal/src/Distribution/GetOpt.hs @@ -1,7 +1,8 @@ {-# LANGUAGE NamedFieldPuns #-} ------------------------------------------------------------------------------ {-# LANGUAGE TupleSections #-} +----------------------------------------------------------------------------- + -- | -- Module : Distribution.GetOpt -- Copyright : (c) Sven Panne 2002-2005 @@ -67,12 +68,12 @@ data ArgDescr a | -- | option requires argument ReqArg (String -> Either String a) String | -- | optional argument - OptArg (Maybe String -> Either String a) String + OptArg String (Maybe String -> Either String a) String instance Functor ArgDescr where fmap f (NoArg a) = NoArg (f a) fmap f (ReqArg g s) = ReqArg (fmap f . g) s - fmap f (OptArg g s) = OptArg (fmap f . g) s + fmap f (OptArg dv g s) = OptArg dv (fmap f . g) s data OptKind a -- kind of cmd line arg (internal use only): = Opt a -- an option @@ -130,17 +131,41 @@ zipDefault _ bd (a : as) [] = (a, bd) : map (,bd) as zipDefault ad _ [] (b : bs) = (ad, b) : map (ad,) bs zipDefault ad bd (a : as) (b : bs) = (a, b) : zipDefault ad bd as bs +-- | Pretty printing of short options. +-- * With required arguments can be given as: +-- @-w PATH or -wPATH (but not -w=PATH)@ +-- This is dislayed as: +-- @-w PATH or -wPATH@ +-- * With optional but default arguments can be given as: +-- @-j or -jNUM (but not -j=NUM or -j NUM)@ +-- This is dislayed as: +-- @-j[NUM]@ fmtShort :: ArgDescr a -> Char -> String fmtShort (NoArg _) so = "-" ++ [so] -fmtShort (ReqArg _ _) so = "-" ++ [so] -fmtShort (OptArg _ _) so = "-" ++ [so] - --- unlike upstream GetOpt we omit the arg name for short options - +fmtShort (ReqArg _ ad) so = + let opt = "-" ++ [so] + in opt ++ " " ++ ad ++ " or " ++ opt ++ ad +fmtShort (OptArg _ _ ad) so = + let opt = "-" ++ [so] + in opt ++ "[" ++ ad ++ "]" + +-- | Pretty printing of long options. +-- * With required arguments can be given as: +-- @--with-compiler=PATH (but not --with-compiler PATH)@ +-- This is dislayed as: +-- @--with-compiler=PATH@ +-- * With optional but default arguments can be given as: +-- @--jobs or --jobs=NUM (but not --jobs NUM)@ +-- This is dislayed as: +-- @--jobs[=NUM]@ fmtLong :: ArgDescr a -> String -> String fmtLong (NoArg _) lo = "--" ++ lo -fmtLong (ReqArg _ ad) lo = "--" ++ lo ++ "=" ++ ad -fmtLong (OptArg _ ad) lo = "--" ++ lo ++ "[=" ++ ad ++ "]" +fmtLong (ReqArg _ ad) lo = + let opt = "--" ++ lo + in opt ++ "=" ++ ad +fmtLong (OptArg _ _ ad) lo = + let opt = "--" ++ lo + in opt ++ "[=" ++ ad ++ "]" wrapText :: Int -> String -> [String] wrapText width = map unwords . wrap 0 [] . words @@ -230,8 +255,8 @@ longOpt ls rs optDescr = long ads arg rs long [ReqArg _ d] [] [] = (errReq d optStr, []) long [ReqArg f _] [] (r : rest) = (fromRes (f r), rest) long [ReqArg f _] ('=' : xs) rest = (fromRes (f xs), rest) - long [OptArg f _] [] rest = (fromRes (f Nothing), rest) - long [OptArg f _] ('=' : xs) rest = (fromRes (f (Just xs)), rest) + long [OptArg _ f _] [] rest = (fromRes (f Nothing), rest) + long [OptArg _ f _] ('=' : xs) rest = (fromRes (f (Just xs)), rest) long _ _ rest = (UnreqOpt ("--" ++ ls), rest) -- handle short option @@ -249,8 +274,8 @@ shortOpt y ys rs optDescr = short ads ys rs short (ReqArg _ d : _) [] [] = (errReq d optStr, []) short (ReqArg f _ : _) [] (r : rest) = (fromRes (f r), rest) short (ReqArg f _ : _) xs rest = (fromRes (f xs), rest) - short (OptArg f _ : _) [] rest = (fromRes (f Nothing), rest) - short (OptArg f _ : _) xs rest = (fromRes (f (Just xs)), rest) + short (OptArg _ f _ : _) [] rest = (fromRes (f Nothing), rest) + short (OptArg _ f _ : _) xs rest = (fromRes (f (Just xs)), rest) short [] [] rest = (UnreqOpt optStr, rest) short [] xs rest = (UnreqOpt (optStr ++ xs), rest) diff --git a/Cabal/src/Distribution/Simple/Command.hs b/Cabal/src/Distribution/Simple/Command.hs index f4ba63f991c..f55a510c8bd 100644 --- a/Cabal/src/Distribution/Simple/Command.hs +++ b/Cabal/src/Distribution/Simple/Command.hs @@ -74,6 +74,7 @@ module Distribution.Simple.Command , reqArg' , optArg , optArg' + , optArgDef' , noArg , boolOpt , boolOpt' @@ -138,7 +139,7 @@ data OptDescr a OptFlags ArgPlaceHolder (ReadE (a -> a)) - (a -> a) + (String, a -> a) (a -> [Maybe String]) | ChoiceOpt [(Description, OptFlags, a -> a, a -> Bool)] | BoolOpt @@ -231,16 +232,16 @@ optArg :: Monoid b => ArgPlaceHolder -> ReadE b - -> b + -> (String, b) -> (b -> [Maybe String]) -> MkOptDescr (a -> b) (b -> a -> a) a -optArg ad mkflag def showflag sf lf d get set = +optArg ad mkflag (dv, mkDef) showflag sf lf d get set = OptArg d (sf, lf) ad (fmap (\a b -> set (get b `mappend` a) b) mkflag) - (\b -> set (get b `mappend` def) b) + (dv, \b -> set (get b `mappend` mkDef) b) (showflag . get) -- | (String -> a) variant of "reqArg" @@ -261,9 +262,16 @@ optArg' -> (b -> [Maybe String]) -> MkOptDescr (a -> b) (b -> a -> a) a optArg' ad mkflag showflag = - optArg ad (succeedReadE (mkflag . Just)) def showflag - where - def = mkflag Nothing + optArg ad (succeedReadE (mkflag . Just)) ("", mkflag Nothing) showflag + +optArgDef' + :: Monoid b + => ArgPlaceHolder + -> (String, Maybe String -> b) + -> (b -> [Maybe String]) + -> MkOptDescr (a -> b) (b -> a -> a) a +optArgDef' ad (dv, mkflag) showflag = + optArg ad (succeedReadE (mkflag . Just)) (dv, mkflag Nothing) showflag noArg :: Eq b => b -> MkOptDescr (a -> b) (b -> a -> a) a noArg flag sf lf d = choiceOpt [(flag, (sf, lf), d)] sf lf d @@ -339,8 +347,8 @@ viewAsGetOpt (OptionField _n aa) = concatMap optDescrToGetOpt aa where optDescrToGetOpt (ReqArg d (cs, ss) arg_desc set _) = [GetOpt.Option cs ss (GetOpt.ReqArg (runReadE set) arg_desc) d] - optDescrToGetOpt (OptArg d (cs, ss) arg_desc set def _) = - [GetOpt.Option cs ss (GetOpt.OptArg set' arg_desc) d] + optDescrToGetOpt (OptArg d (cs, ss) arg_desc set (dv, def) _) = + [GetOpt.Option cs ss (GetOpt.OptArg dv set' arg_desc) d] where set' Nothing = Right def set' (Just txt) = runReadE set txt @@ -374,13 +382,13 @@ liftOptDescr get' set' (ChoiceOpt opts) = [ (d, ff, liftSet get' set' set, (get . get')) | (d, ff, set, get) <- opts ] -liftOptDescr get' set' (OptArg d ff ad set def get) = +liftOptDescr get' set' (OptArg d ff ad set (dv, mkDef) get) = OptArg d ff ad (liftSet get' set' `fmap` set) - (liftSet get' set' def) + (dv, liftSet get' set' mkDef) (get . get') liftOptDescr get' set' (ReqArg d ff ad set get) = ReqArg d ff ad (liftSet get' set' `fmap` set) (get . get') diff --git a/Cabal/src/Distribution/Simple/Setup/Common.hs b/Cabal/src/Distribution/Simple/Setup/Common.hs index 32068b619a5..0589838f617 100644 --- a/Cabal/src/Distribution/Simple/Setup/Common.hs +++ b/Cabal/src/Distribution/Simple/Setup/Common.hs @@ -282,7 +282,7 @@ optionVerbosity get set = ( optArg "n" (fmap Flag flagToVerbosity) - (Flag verbose) -- default Value if no n is given + (show verbose, Flag verbose) -- default Value if no n is given (fmap (Just . showForCabal) . flagToList) ) @@ -300,7 +300,7 @@ optionNumJobs get set = ( optArg "NUM" (fmap Flag numJobsParser) - (Flag Nothing) + ("$ncpus", Flag Nothing) (map (Just . maybe "$ncpus" show) . flagToList) ) where diff --git a/Cabal/src/Distribution/Simple/Setup/Config.hs b/Cabal/src/Distribution/Simple/Setup/Config.hs index a109a7502b9..05fd07f33ca 100644 --- a/Cabal/src/Distribution/Simple/Setup/Config.hs +++ b/Cabal/src/Distribution/Simple/Setup/Config.hs @@ -541,9 +541,9 @@ configureOptions showOrParseArgs = "optimization" configOptimization (\v flags -> flags{configOptimization = v}) - [ optArg' + [ optArgDef' "n" - (Flag . flagToOptimisationLevel) + (show NoOptimisation, Flag . flagToOptimisationLevel) ( \f -> case f of Flag NoOptimisation -> [] Flag NormalOptimisation -> [Nothing] diff --git a/cabal-install/src/Distribution/Client/CmdOutdated.hs b/cabal-install/src/Distribution/Client/CmdOutdated.hs index 7f143b9ec3b..57c6fc96082 100644 --- a/cabal-install/src/Distribution/Client/CmdOutdated.hs +++ b/cabal-install/src/Distribution/Client/CmdOutdated.hs @@ -281,7 +281,7 @@ outdatedOptions _showOrParseArgs = ( optArg "PKGS" ignoreMajorVersionBumpsParser - (Just IgnoreMajorVersionBumpsAll) + ("", Just IgnoreMajorVersionBumpsAll) ignoreMajorVersionBumpsPrinter ) ] diff --git a/cabal-install/src/Distribution/Client/Setup.hs b/cabal-install/src/Distribution/Client/Setup.hs index 460decd55cd..4cd7b207f79 100644 --- a/cabal-install/src/Distribution/Client/Setup.hs +++ b/cabal-install/src/Distribution/Client/Setup.hs @@ -934,7 +934,7 @@ configureExOptions _showOrParseArgs src = ( optArg "DEPS" (parsecToReadEErr unexpectMsgString relaxDepsParser) - (Just RelaxDepsAll) + (show RelaxDepsAll, Just RelaxDepsAll) relaxDepsPrinter ) , option @@ -946,7 +946,7 @@ configureExOptions _showOrParseArgs src = ( optArg "DEPS" (parsecToReadEErr unexpectMsgString relaxDepsParser) - (Just RelaxDepsAll) + (show RelaxDepsAll, Just RelaxDepsAll) relaxDepsPrinter ) , option @@ -1766,7 +1766,7 @@ getCommand = (const "invalid source-repository") (fmap (toFlag . Just) parsec) ) - (Flag Nothing) + ("", Flag Nothing) (map (fmap show) . flagToList) ) , option diff --git a/changelog.d/issue-8785 b/changelog.d/issue-8785 new file mode 100644 index 00000000000..47238ed20b6 --- /dev/null +++ b/changelog.d/issue-8785 @@ -0,0 +1,17 @@ +synopsis: Also render short options with arguments +packages: cabal-install +prs: #9043 +issues: #8785 + +description: { + +Show how arguments are used with both short and long forms of options: + +```diff +< -v, --verbose[=n] Control verbosity (n is 0--3, default +> -v[n], --verbose[=n] Control verbosity (n is 0--3, default +< -w, --with-compiler=PATH give the path to a particular compiler +> -w PATH or -wPATH, --with-compiler=PATH +``` + +} diff --git a/doc/cabal-commands.rst b/doc/cabal-commands.rst index c26b7a654cb..1c0776602ed 100644 --- a/doc/cabal-commands.rst +++ b/doc/cabal-commands.rst @@ -85,7 +85,7 @@ Arguments and flags common to some or all commands are: users to peg themselves to stable package collections. -.. option:: --allow-newer[=pkgs], --allow-older[=pkgs] +.. option:: --allow-newer[=DEPS], --allow-older[=DEPS] Selectively relax upper or lower bounds in dependencies without editing the package description respectively. @@ -150,7 +150,7 @@ Arguments and flags common to some or all commands are: 'allow-newer' selectively is also supported in the config file (``allow-newer: foo, bar, baz:base``). -.. option:: --preference=preference +.. option:: --preference=CONSTRAINT Specify a soft constraint on versions of a package. The solver will attempt to satisfy these preferences on a "best-effort" basis. @@ -275,11 +275,11 @@ cabal preferences. It is very useful when you are e.g. first configuring - ``cabal user-config update`` updates the user's config file with additional lines. - .. option:: -a, --augment=CONFIGLINE + .. option:: -a CONFIGLINE or -aCONFIGLINE, --augment=CONFIGLINE Pass additional configuration lines to be incorporated in the config file. e.g. - ``cabal user-config update --augment "offline: True"``. + ``cabal user-config update --augment="offline: True"``. Note how ``--augment`` syntax follows ``cabal user-config diff`` output. @@ -325,7 +325,7 @@ cabal list Append the given package database to the list of used package databases. See `cabal info`_ for a thorough explanation. -.. option:: -w, --with-compiler=PATH +.. option:: -w PATH or -wPATH, --with-compiler=PATH Path to specific compiler. @@ -406,7 +406,7 @@ folder. By default the latest version of the package is downloaded, you can ask for a spefic one by adding version numbers (``cabal get random-1.0.0.1``). -.. option:: -s, --source-repository[=head|this|...]] +.. option:: -s[[head|this|...]], --source-repository[=[head|this|...]] Clone the package's source repository (Darcs, Git, etc.) instead of downloading the tarball. Only works if the package specifies @@ -522,7 +522,7 @@ description file or freeze file. ``cabal outdated`` supports the following flags: -.. option:: --v1-freeze-file +.. option:: --freeze-file Read dependency version bounds from the freeze file. @@ -538,7 +538,7 @@ description file or freeze file. description file. ``--new-freeze-file`` is an alias for this flag that can be used with pre-2.4 ``cabal``. -.. option:: --project-file PROJECTFILE +.. option:: --project-file=FILE :since: 2.4 @@ -560,11 +560,11 @@ description file or freeze file. Don't print any output. Implies ``-v0`` and ``--exit-code``. -.. option:: --ignore PACKAGENAMES +.. option:: --ignore=PKGS Don't warn about outdated dependency version bounds for the packages in this list. -.. option:: --minor [PACKAGENAMES] +.. option:: --minor[PKGS] Ignore major version bumps for these packages. @@ -845,7 +845,7 @@ Examples: Configuration flags can be specified on the command line and these extend the project configuration from the 'cabal.project', 'cabal.project.local' and other files. -.. option:: --repl-options +.. option:: --repl-options=FLAG To avoid ``ghci``-specific flags from triggering unneeded global rebuilds, these flags are stripped from the internal configuration. As a result, @@ -857,7 +857,7 @@ configuration from the 'cabal.project', 'cabal.project.local' and other files. Disables the loading of target modules at startup. -.. option:: -b, --build-depends +.. option:: -b DEPENDENCIES or -bDEPENDENCIES, --build-depends=DEPENDENCIES A way to experiment with libraries without needing to download them manually or to install them globally. @@ -867,7 +867,7 @@ configuration from the 'cabal.project', 'cabal.project.local' and other files. :: - $ cabal repl --build-depends "vector >= 0.12 && < 0.13" + $ cabal repl --build-depends="vector >= 0.12 && < 0.13" Both of these commands do the same thing as the above, but only expose ``base``, ``vector``, and the ``vector`` package's transitive dependencies even if the user @@ -875,8 +875,8 @@ configuration from the 'cabal.project', 'cabal.project.local' and other files. :: - $ cabal repl --ignore-project --build-depends "vector >= 0.12 && < 0.13" - $ cabal repl --project='' --build-depends "vector >= 0.12 && < 0.13" + $ cabal repl --ignore-project --build-depends="vector >= 0.12 && < 0.13" + $ cabal repl --project='' --build-depends="vector >= 0.12 && < 0.13" This command would add ``vector``, but not (for example) ``primitive``, because it only includes the packages specified on the command line (and ``base``, which @@ -884,7 +884,7 @@ configuration from the 'cabal.project', 'cabal.project.local' and other files. :: - $ cabal repl --build-depends vector --no-transitive-deps + $ cabal repl --build-depends=vector --no-transitive-deps ``cabal repl`` can open scripts by passing the path to the script as the target. @@ -914,9 +914,9 @@ See ``cabal run`` for more information on scripts. cabal run ^^^^^^^^^ -``cabal run [TARGET [ARGS]]`` runs the executable specified by the -target, which can be a component, a package or can be left blank, as -long as it can uniquely identify an executable within the project. +``cabal run [TARGET] [FLAGS] [-- EXECUTABLE_FLAGS]`` runs the executable +specified by the target, which can be a component, a package or can be left +blank, as long as it can uniquely identify an executable within the project. Tests and benchmarks are also treated as executables. See `the build section <#cabal-build>`__ for the target syntax. @@ -1006,7 +1006,7 @@ For more information see :cfg-field:`verbose` cabal bench ^^^^^^^^^^^ -``cabal bench [TARGETS] [OPTIONS]`` runs the specified benchmarks +``cabal bench [TARGETS] [FLAGS]`` runs the specified benchmarks (all the benchmarks in the current package by default), first ensuring they are up to date. @@ -1016,7 +1016,7 @@ they are up to date. cabal test ^^^^^^^^^^ -``cabal test [TARGETS] [OPTIONS]`` runs the specified test suites +``cabal test [TARGETS] [FLAGS]`` runs the specified test suites (all the test suites in the current package by default), first ensuring they are up to date. @@ -1047,9 +1047,9 @@ tricky GHC options, etc.). Run ``cabal check`` in the folder where your ``.cabal`` package file is. -.. option:: -v, --verbose[=n] +.. option:: -v[n], --verbose[=n] - Set verbosity level (0–3, default is 1). + Control verbosity (n is 0--3, default verbosity level is 1). Issues are classified as ``Warning``\s and ``Error``\s. The latter correspond to Hackage requirements for uploaded packages: if no error is reported, @@ -1059,7 +1059,7 @@ exits with ``1`` and Hackage will refuse the package. cabal sdist ^^^^^^^^^^^ -``cabal sdist [FLAGS] [TARGETS]`` takes the crucial files needed to build ``TARGETS`` +``cabal sdist [FLAGS] [PACKAGES]`` takes the crucial files needed to build ``PACKAGES`` and puts them into an archive format ready for upload to Hackage. These archives are stable and two archives of the same format built from the same source will hash to the same value. @@ -1072,7 +1072,7 @@ and two archives of the same format built from the same source will hash to the Output is to ``stdout`` by default. The file paths are relative to the project's root directory. -.. option:: -o, --output-directory +.. option:: -o PATH or -oPATH, --output-directory=PATH Sets the output dir, if a non-default one is desired. The default is ``dist-newstyle/sdist/``. ``--output-directory -`` will send output to ``stdout`` @@ -1109,22 +1109,22 @@ to Hackage. documentation for a published package (and not a candidate), add ``--publish``. -.. option:: -u, --username +.. option:: -u USERNAME or -uUSERNAME, --username=USERNAME Your Hackage username. -.. option:: -p, --password +.. option:: -p PASSWORD or -pPASSWORD, --password=PASSWORD Your Hackage password. -.. option:: -P, --password-command +.. option:: -P COMMAND or -PCOMMAND, --password-command=COMMAND Command to get your Hackage password. Arguments with whitespace must be quoted (double-quotes only). For example: :: - --password-command 'sh -c "grep hackage ~/secrets | cut -d : -f 2"' + --password-command='sh -c "grep hackage ~/secrets | cut -d : -f 2"' Or in the config file: @@ -1138,10 +1138,10 @@ cabal report ``cabal report [FLAGS]`` uploads build reports to Hackage. -.. option:: -u, --username +.. option:: -u USERNAME or -uUSERNAME, --username=USERNAME Your Hackage username. -.. option:: -p, --password +.. option:: -p PASSWORD or -pPASSWORD, --password=PASSWORD Your Hackage password. diff --git a/doc/cabal-project.rst b/doc/cabal-project.rst index 2700a8bd6b8..3c6f9f63e69 100644 --- a/doc/cabal-project.rst +++ b/doc/cabal-project.rst @@ -243,7 +243,7 @@ package, and thus apply globally: .. cfg-field:: verbose: nat - --verbose=n, -vn + -v[n], --verbose[=n] :synopsis: Build verbosity level. :default: 1 @@ -255,7 +255,7 @@ package, and thus apply globally: form ``-v2`` is also supported. .. cfg-field:: jobs: nat or $ncpus - --jobs=n, -jn, --jobs=$ncpus + -j[NUM], --jobs[=NUM], --jobs=$ncpus :synopsis: Number of builds running in parallel. :default: 1 @@ -320,7 +320,7 @@ package, and thus apply globally: This option can only be specified from the command line. -.. option:: --ignore-project +.. option:: -z, --ignore-project Ignores the local ``cabal.project`` file and uses the default configuration with the local ``foo.cabal`` file. Note that @@ -411,7 +411,8 @@ Solver configuration options The following settings control the behavior of the dependency solver: -.. cfg-field:: constraints: constraints list (comma separated) +.. cfg-field:: constraints: CONSTRAINT (comma separated list) + -c CONSTRAINT or -cCONSTRAINT, --constraint=CONSTRAINT --constraint="pkg >= 2.0", -c "pkg >= 2.0" :synopsis: Extra dependencies constraints. @@ -438,7 +439,8 @@ The following settings control the behavior of the dependency solver: :option:`runhaskell Setup.hs configure --constraint` command line option. -.. cfg-field:: preferences: preference (comma separated) +.. cfg-field:: preferences: CONSTRAINT (comma separated list) + --preference=CONSTRAINT --preference="pkg >= 2.0" :synopsis: Preferred dependency versions. @@ -717,6 +719,7 @@ scripts that require a version of the Cabal library older than when the feature was added. .. cfg-field:: flags: list of +flagname or -flagname (space separated) + -f FLAGS or -fFLAGS, --flags=FLAGS --flags="+foo -bar", -ffoo, -f-bar :synopsis: Enable or disable package flags. @@ -746,8 +749,8 @@ feature was added. ``haskell-tor`` is the package you want this flag to apply to, try ``--constraint="haskell-tor +hans"`` instead. -.. cfg-field:: with-compiler: executable - --with-compiler=executable +.. cfg-field:: with-compiler: PATH + -w PATH or -wPATH, --with-compiler=PATH :synopsis: Path to compiler executable. Specify the path to a particular compiler to be used. If not an @@ -777,9 +780,9 @@ feature was added. ``--with-compiler=ghc-7.8``; there is also a short version ``-w ghc-7.8``. -.. cfg-field:: with-hc-pkg: executable - --with-hc-pkg=executable - :synopsis: Specifies package tool. +.. cfg-field:: with-hc-pkg: PATH + --with-hc-pkg=PATH + :synopsis: Path to package tool. Specify the path to the package tool, e.g., ``ghc-pkg``. This package tool must be compatible with the compiler specified by @@ -791,7 +794,7 @@ feature was added. ``--with-hc-pkg=ghc-pkg-7.8``. .. cfg-field:: optimization: nat - --enable-optimization + -O[n], --enable-optimization[=n] --disable-optimization :synopsis: Build with optimization. @@ -823,8 +826,8 @@ feature was added. equivalent to ``-O``). There are also long-form variants ``--enable-optimization`` and ``--disable-optimization``. -.. cfg-field:: configure-options: args (space separated) - --configure-option=arg +.. cfg-field:: configure-options: OPT (space separated list) + --configure-option=OPT :synopsis: Options to pass to configure script. A list of extra arguments to pass to the external ``./configure`` @@ -881,7 +884,7 @@ feature was added. ``--disable-benchmarks``. .. _cmdoption-extra-prog-path: -.. cfg-field:: extra-prog-path: paths (newline or comma separated) +.. cfg-field:: extra-prog-path: PATH (newline or comma separated list) --extra-prog-path=PATH :synopsis: Add directories to program search path. :since: 1.18 @@ -901,11 +904,11 @@ feature was added. .. cfg-field:: run-tests: boolean --run-tests - :synopsis: Run package test suite upon installation. + :synopsis: Run package test suite during installation. :default: ``False`` - Run the package test suite upon installation. This is useful for + Run the package test suite during installation. This is useful for saying "When this package is installed, check that the test suite passes, terminating the rest of the build if it is broken." @@ -923,7 +926,7 @@ Object code options ^^^^^^^^^^^^^^^^^^^ .. cfg-field:: debug-info: integer - --enable-debug-info= + --enable-debug-info[=n] --disable-debug-info :synopsis: Build with debug info enabled. :since: 1.22 @@ -1020,8 +1023,8 @@ Object code options Executable options ^^^^^^^^^^^^^^^^^^ -.. cfg-field:: program-prefix: prefix - --program-prefix=prefix +.. cfg-field:: program-prefix: PREFIX + --program-prefix=PREFIX :synopsis: Prepend prefix to program names. :strike:`Prepend *prefix* to installed program names.` (Currently @@ -1034,8 +1037,8 @@ Executable options The command line variant of this flag is ``--program-prefix=foo-``. -.. cfg-field:: program-suffix: suffix - --program-suffix=suffix +.. cfg-field:: program-suffix: SUFFIX + --program-suffix=SUFFIX :synopsis: Append refix to program names. :strike:`Append *suffix* to installed program names.` (Currently @@ -1412,9 +1415,9 @@ running ``setup haddock``. Generate an index for interactive documentation navigation. This is equivalent to running ``haddock`` with the ``--quickjump`` flag. -.. cfg-field:: haddock-html-location: templated path - --haddock-html-location=TEMPLATE - :synopsis: Haddock HTML templates location. +.. cfg-field:: haddock-html-location: URL (templated path) + --haddock-html-location=URL + :synopsis: Location of HTML documentation for prerequisite packages. Specify a template for the location of HTML documentation for prerequisite packages. The substitutions are applied to the template @@ -1477,7 +1480,7 @@ running ``setup haddock``. Run haddock on all components. -.. cfg-field:: haddock-css: path +.. cfg-field:: haddock-css: PATH --haddock-css=PATH :synopsis: Location of Haddock CSS file. @@ -1494,7 +1497,7 @@ running ``setup haddock``. Haddock documentation link to it. This is equivalent to running ``haddock`` with the ``--hyperlinked-source`` flag. -.. cfg-field:: haddock-hscolour-css: path +.. cfg-field:: haddock-hscolour-css: PATH --haddock-hscolour-css=PATH :synopsis: Location of CSS file for HsColour @@ -1514,8 +1517,8 @@ running ``setup haddock``. There is no command line variant of this flag. -.. cfg-field:: haddock-output-dir: path - --haddock-output-dir=PATH +.. cfg-field:: haddock-output-dir: DIR + --haddock-output-dir=DIR :synopsis: Generate haddock documentation into this directory. Generate haddock documentation into this directory instead of the default @@ -1536,7 +1539,7 @@ Advanced global configuration options ------------------------------------- .. cfg-field:: write-ghc-environment-files: always, never, or ghc8.4.4+ - --write-ghc-environment-files=policy + --write-ghc-environment-files=always\|never\|ghc8.4.4+ :synopsis: Whether a ``.ghc.environment`` should be created after a successful build. :default: ``never`` @@ -1655,8 +1658,8 @@ Advanced solver options Most users generally won't need these. -.. cfg-field:: solver: modular - --solver=modular +.. cfg-field:: solver: SOLVER + --solver=SOLVER :synopsis: Which solver to use. This field is reserved to allow the specification of alternative @@ -1763,8 +1766,8 @@ Most users generally won't need these. The command line variant of this field is ``--(no-)allow-boot-library-installs``. -.. cfg-field:: cabal-lib-version: version - --cabal-lib-version=version +.. cfg-field:: cabal-lib-version: VERSION + --cabal-lib-version=VERSION :synopsis: Version of Cabal library used to build package. This field selects the version of the Cabal library which should be diff --git a/doc/setup-commands.rst b/doc/setup-commands.rst index 24016c2c267..0d326e73830 100644 --- a/doc/setup-commands.rst +++ b/doc/setup-commands.rst @@ -166,14 +166,17 @@ Programs used for building The following options govern the programs used to process the source files of a package: -.. option:: --ghc or -g, --jhc, --lhc, --uhc +.. option:: -g, --ghc + --ghcjs + --uhc + --haskell-suite Specify which Haskell implementation to use to build the package. At most one of these flags may be given. If none is given, the implementation under which the setup script was compiled or interpreted is used. -.. option:: --with-compiler=path or -w *path* +.. option:: -w PATH or -wPATH, --with-compiler=PATH Specify the path to a particular compiler. If given, this must match the implementation selected above. The default is to search for the @@ -184,14 +187,14 @@ files of a package: ``runhaskell Setup.hs configure -v`` to ensure that it finds the right package tool (or use :option:`--with-hc-pkg` explicitly). -.. option:: --with-hc-pkg=path +.. option:: --with-hc-pkg=PATH Specify the path to the package tool, e.g. ``ghc-pkg``. The package tool must be compatible with the compiler specified by :option:`--with-compiler`. If this option is omitted, the default value is determined from the compiler selected. -.. option:: --with-prog=path +.. option:: --with-PROG=PATH Specify the path to the program *prog*. Any program known to Cabal can be used in place of *prog*. It can either be a fully path or the @@ -201,7 +204,7 @@ files of a package: programs is not enumerated in this user guide. Rather, run ``cabal install --help`` to view the list. -.. option:: --prog-options=options +.. option:: --PROG-options=OPTS Specify additional options to the program *prog*. Any program known to Cabal can be used in place of *prog*. For example: @@ -210,19 +213,19 @@ files of a package: embedded spaced need to be quoted, for example ``--foo-options='--bar="C:\Program File\Bar"'``. As an alternative that takes only one option at a time but avoids the need to quote, - use :option:`--prog-option` instead. + use :option:`--PROG-option` instead. -.. option:: --prog-option=option +.. option:: --PROG-option=OPT Specify a single additional option to the program *prog*. For passing an option that contains embedded spaces, such as a file name - with embedded spaces, using this rather than :option:`--prog-options` + with embedded spaces, using this rather than :option:`--PROG-options` means you do not need an additional level of quoting. Of course if you are using a command shell you may still need to quote, for example ``--foo-options="--bar=C:\Program File\Bar"``. -All of the options passed with either :option:`--prog-options` -or :option:`--prog-option` are passed in the order they were +All of the options passed with either :option:`--PROG-options` +or :option:`--PROG-option` are passed in the order they were specified on the configure command line. Installation paths @@ -231,7 +234,7 @@ Installation paths The following options govern the location of installed files from a package: -.. option:: --prefix=dir +.. option:: --prefix=DIR The root of the installation. For example for a global install you might use ``/usr/local`` on a Unix system, or ``C:\Program Files`` @@ -242,7 +245,7 @@ package: variables: ``$pkgid``, ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --bindir=dir +.. option:: --bindir=DIR Executables that the user might invoke are installed here. @@ -250,7 +253,7 @@ package: variables: ``$prefix``, ``$pkgid``, ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --libdir=dir +.. option:: --libdir=DIR Object-code libraries are installed here. @@ -259,7 +262,7 @@ package: ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --dynlibdir=dir +.. option:: --dynlibdir=DIR Dynamic libraries are installed here. @@ -271,7 +274,7 @@ package: ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --libexecdir=dir +.. option:: --libexecdir=DIR Executables that are not expected to be invoked directly by the user are installed here. @@ -281,7 +284,7 @@ package: ``$pkgid``, ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --datadir=dir +.. option:: --datadir=DIR Architecture-independent data files are installed here. @@ -290,7 +293,7 @@ package: ``$pkgid``, ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --sysconfdir=dir +.. option:: --sysconfdir=DIR Installation directory for the configuration files. @@ -302,7 +305,7 @@ package: In addition the simple build system supports the following installation path options: -.. option:: --libsubdir=dir +.. option:: --libsubdir=DIR A subdirectory of *libdir* in which libraries are actually installed. For example, in the simple build system on Unix, the default *libdir* is @@ -316,7 +319,7 @@ path options: ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --libexecsubdir=dir +.. option:: --libexecsubdir=DIR A subdirectory of *libexecdir* in which private executables are installed. For example, in the simple build system on Unix, the default @@ -328,7 +331,7 @@ path options: ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --datasubdir=dir +.. option:: --datasubdir=DIR A subdirectory of *datadir* in which data files are actually installed. @@ -337,7 +340,7 @@ path options: ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --docdir=dir +.. option:: --docdir=DIR Documentation files are installed relative to this directory. @@ -346,7 +349,7 @@ path options: ``$datasubdir``, ``$pkgid``, ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --htmldir=dir +.. option:: --htmldir=DIR HTML documentation files are installed relative to this directory. @@ -355,7 +358,7 @@ path options: ``$datasubdir``, ``$docdir``, ``$pkgid``, ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --program-prefix=prefix +.. option:: --program-prefix=PREFIX Prepend *prefix* to installed program names. @@ -363,7 +366,7 @@ path options: ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` -.. option:: --program-suffix=suffix +.. option:: --program-suffix=SUFFIX Append *suffix* to installed program names. The most obvious use for this is to append the program's version number to make it possible @@ -585,7 +588,7 @@ Miscellaneous options packages in the user's package database will be ignored. Typically the final installation step will require administrative privileges. -.. option:: --package-db=db +.. option:: --package-db=DB Allows package dependencies to be satisfied from this additional package database *db* in addition to the global package database. @@ -603,7 +606,7 @@ Miscellaneous options To reset the stack, use ``--package-db=clear``. -.. option:: --ipid=ipid +.. option:: --ipid=IPID Specifies the *installed package identifier* of the package to be built; this identifier is passed on to GHC and serves as the basis @@ -613,12 +616,12 @@ Miscellaneous options internal library ``foo`` from package ``p-0.1-abcd`` will get the identifier ``p-0.1-abcd-foo``. -.. option:: --cid=cid +.. option:: --cid=CID Specifies the *component identifier* of the component being built; this is only valid if you are configuring a single component. -.. option:: --enable-optimization[=n] or -O [n] +.. option:: -O[n], --enable-optimization[=n] (default) Build with optimization flags (if available). This is appropriate for production use, taking more time to build faster @@ -659,7 +662,7 @@ Miscellaneous options (default) Do not enable profiling in generated libraries and executables. -.. option:: --enable-library-profiling or -p +.. option:: -p, --enable-library-profiling As with :option:`--enable-profiling` above, but it applies only for libraries. So this generates an additional profiling instance of the @@ -674,7 +677,7 @@ Miscellaneous options (default) Do not generate an additional profiling version of the library. -.. option:: --profiling-detail[=level] +.. option:: --profiling-detail=level Some compilers that support profiling, notably GHC, can allocate costs to different parts of the program and there are different @@ -711,7 +714,7 @@ Miscellaneous options This flag is new in Cabal-1.24. Prior versions used the equivalent of ``none`` above. -.. option:: --library-profiling-detail[=level] +.. option:: --library-profiling-detail=level As with :option:`--profiling-detail` above, but it applies only for libraries. @@ -828,7 +831,7 @@ Miscellaneous options (see the section on :ref:`system-dependent parameters`). There can be several of these options. -.. option:: --extra-include-dirs[=dir] +.. option:: --extra-include-dirs=PATH An extra directory to search for C header files. You can use this flag multiple times to get a list of directories. @@ -843,12 +846,12 @@ Miscellaneous options and for libraries it is also saved in the package registration information and used when compiling modules that use the library. -.. option:: --extra-lib-dirs[=dir] +.. option:: --extra-lib-dirs=PATH An extra directory to search for system libraries files. You can use this flag multiple times to get a list of directories. -.. option:: --extra-framework-dirs[=dir] +.. option:: --extra-framework-dirs=PATH An extra directory to search for frameworks (OS X only). You can use this flag multiple times to get a list of directories. @@ -863,14 +866,14 @@ Miscellaneous options and for libraries it is also saved in the package registration information and used when compiling modules that use the library. -.. option:: --dependency[=pkgname=ipid] +.. option:: --dependency[=pkgname=IPID] Specify that a particular dependency should used for a particular package name. In particular, it declares that any reference to *pkgname* in a :pkg-field:`build-depends` should be resolved to *ipid*. -.. option:: --promised-dependency[=pkgname=ipid] +.. option:: --promised-dependency[=pkgname=IPID] Very much like ``--dependency`` but the package doesn't need to already be installed. This is useful when attempting to start multiple component @@ -889,7 +892,7 @@ Miscellaneous options :option:`--dependency` flags. -.. option:: --constraint=constraint +.. option:: -c CONSTRAINT or -cCONSTRAINT, --constraint=CONSTRAINT Restrict solutions involving a package to given version bounds, flag settings, and other properties. @@ -999,7 +1002,7 @@ This command takes the following options: .. program:: runhaskell Setup.hs build -.. option:: --prog-options=options, --prog-option=option +.. option:: --PROG-options=OPTS, --PROG-option=OPT These are mostly the same as the `options configure step <#setup-configure>`__. Unlike the options specified at the @@ -1277,12 +1280,12 @@ the package. .. program:: runhaskell Setup.hs test -.. option:: --builddir=dir +.. option:: --builddir=DIR The directory where Cabal puts generated build files (default: ``dist``). Test logs will be located in the ``test`` subdirectory. -.. option:: --human-log=path +.. option:: --test-log=TEMPLATE The template used to name human-readable test logs; the path is relative to ``dist/test``. By default, logs are named according to @@ -1291,14 +1294,14 @@ the package. variables allowed are: ``$pkgid``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag``, ``$test-suite``, and ``$result``. -.. option:: --machine-log=path +.. option:: --test-machine-log=TEMPLATE The path to the machine-readable log, relative to ``dist/test``. The default template is ``$pkgid.log``. Template variables allowed are: ``$pkgid``, ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag`` and ``$result``. -.. option:: --show-details=filter +.. option:: --test-show-details=FILTER Determines if the results of individual test cases are shown on the terminal. May be ``always`` (always show), ``never`` (never show), @@ -1311,17 +1314,17 @@ the package. frameworks. (On the other hand, ``streaming`` creates a log but looses coloring.) -.. option:: --test-options=options +.. option:: --test-options=TEMPLATES Give extra options to the test executables. -.. option:: --test-option=option +.. option:: --test-option=TEMPLATE Give an extra option to the test executables. There is no need to quote options containing spaces because a single option is assumed, so options will not be split on spaces. -.. option:: --test-wrapper=path +.. option:: --test-wrapper=FILE The wrapper script/application used to setup and tear down the test execution context. The text executable path and test arguments are @@ -1339,11 +1342,11 @@ on the command line after ``bench``. When supplied, Cabal will run only the named benchmarks, otherwise, Cabal will run all benchmarks in the package. -.. option:: --benchmark-options=options +.. option:: --benchmark-options=TEMPLATES Give extra options to the benchmark executables. -.. option:: --benchmark-option=option +.. option:: --benchmark-option=TEMPLATE Give an extra option to the benchmark executables. There is no need to quote options containing spaces because a single option is assumed, From cac39cfb522c5da09194a85488ced016ef49d845 Mon Sep 17 00:00:00 2001 From: Artem Pelenitsyn Date: Wed, 12 Jul 2023 21:42:28 -0400 Subject: [PATCH 2/8] Mergify: rebase as Mikolaj (fix #8462) --- .github/mergify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/mergify.yml b/.github/mergify.yml index 7969fe95c25..c88a5080c7c 100644 --- a/.github/mergify.yml +++ b/.github/mergify.yml @@ -70,4 +70,4 @@ pull_request_rules: queue_rules: - name: default - conditions: [] + update_bot_account: Mikolaj From a17f56cf370503baa6616c2fd7d5f95e40eb85fe Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Tue, 11 Jul 2023 06:24:28 -0400 Subject: [PATCH 3/8] Follow hlint suggestion: redundant list comprehension --- .hlint.yaml | 1 - Cabal/src/Distribution/Simple/PreProcess.hs | 4 ++-- Cabal/src/Distribution/Simple/Program/GHC.hs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.hlint.yaml b/.hlint.yaml index 54771486d1b..65b1c7492be 100644 --- a/.hlint.yaml +++ b/.hlint.yaml @@ -22,7 +22,6 @@ - ignore: {name: "Redundant guard"} # 2 hints - ignore: {name: "Redundant if"} # 1 hint - ignore: {name: "Redundant lambda"} # 22 hints -- ignore: {name: "Redundant list comprehension"} # 3 hints - ignore: {name: "Redundant map"} # 1 hint - ignore: {name: "Redundant multi-way if"} # 1 hint - ignore: {name: "Redundant return"} # 4 hints diff --git a/Cabal/src/Distribution/Simple/PreProcess.hs b/Cabal/src/Distribution/Simple/PreProcess.hs index 03b13ae5a79..2578b2c5129 100644 --- a/Cabal/src/Distribution/Simple/PreProcess.hs +++ b/Cabal/src/Distribution/Simple/PreProcess.hs @@ -648,7 +648,7 @@ ppHsc2hs bi lbi clbi = | pkg <- pkgs , opt <- ["-I" ++ opt | opt <- Installed.includeDirs pkg] - ++ [opt | opt <- Installed.ccOptions pkg] + ++ Installed.ccOptions pkg ] ++ [ "--lflag=" ++ opt | pkg <- pkgs @@ -662,7 +662,7 @@ ppHsc2hs bi lbi clbi = then Installed.extraLibrariesStatic pkg else Installed.extraLibraries pkg ] - ++ [opt | opt <- Installed.ldOptions pkg] + ++ Installed.ldOptions pkg ] ++ preccldFlags ++ hsc2hsOptions bi diff --git a/Cabal/src/Distribution/Simple/Program/GHC.hs b/Cabal/src/Distribution/Simple/Program/GHC.hs index 5e786e2e8e2..4b821f5680c 100644 --- a/Cabal/src/Distribution/Simple/Program/GHC.hs +++ b/Cabal/src/Distribution/Simple/Program/GHC.hs @@ -769,7 +769,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts [ ["-optl-Wl,-rpath," ++ dir] | dir <- flags ghcOptRPaths ] - , [modDefFile | modDefFile <- flags ghcOptLinkModDefFiles] + , flags ghcOptLinkModDefFiles , ------------- -- Packages From 5f630eb0aa3e4872e9eb870349cf50b4360930b5 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Tue, 11 Jul 2023 07:49:15 -0400 Subject: [PATCH 4/8] Follow hlint suggestion: move brackets to avoid $ --- .hlint.yaml | 1 - Cabal/src/Distribution/Compat/ResponseFile.hs | 2 +- Cabal/src/Distribution/Compat/Time.hs | 2 +- Cabal/src/Distribution/ReadE.hs | 2 +- Cabal/src/Distribution/Simple/Build.hs | 2 +- Cabal/src/Distribution/Simple/Haddock.hs | 17 +++++++---------- Cabal/src/Distribution/Utils/Json.hs | 2 +- .../src/Distribution/Solver/Modular/Linking.hs | 6 +++--- .../src/Distribution/Solver/Modular/Message.hs | 2 +- cabal-install/src/Distribution/Client/CmdRun.hs | 13 +++++++------ .../src/Distribution/Client/GenBounds.hs | 2 +- .../src/Distribution/Client/Install.hs | 2 +- cabal-install/src/Distribution/Client/List.hs | 12 ++++-------- .../Distribution/Client/ProjectPlanOutput.hs | 3 ++- .../src/Distribution/Client/ProjectPlanning.hs | 4 ++-- cabal-install/src/Distribution/Client/Utils.hs | 2 +- generics-sop-lens.hs | 4 ++-- 17 files changed, 36 insertions(+), 42 deletions(-) diff --git a/.hlint.yaml b/.hlint.yaml index 65b1c7492be..49c81e1f075 100644 --- a/.hlint.yaml +++ b/.hlint.yaml @@ -12,7 +12,6 @@ - ignore: {name: "Missing NOINLINE pragma"} # 1 hint - ignore: {name: "Monoid law, left identity"} # 3 hints - ignore: {name: "Monoid law, right identity"} # 3 hints -- ignore: {name: "Move brackets to avoid $"} # 25 hints - ignore: {name: "Move guards forward"} # 4 hints - ignore: {name: "Redundant $"} # 125 hints - ignore: {name: "Redundant $!"} # 4 hints diff --git a/Cabal/src/Distribution/Compat/ResponseFile.hs b/Cabal/src/Distribution/Compat/ResponseFile.hs index fb9d3309637..c03207fed55 100644 --- a/Cabal/src/Distribution/Compat/ResponseFile.hs +++ b/Cabal/src/Distribution/Compat/ResponseFile.hs @@ -76,7 +76,7 @@ expandResponse = go recursionLimit "." | otherwise = const $ hPutStrLn stderr "Error: response file recursion limit exceeded." >> exitFailure expand :: Int -> FilePath -> String -> IO [String] - expand n dir arg@('@' : f) = readRecursively n (dir f) `catchIOError` (const $ print "?" >> return [arg]) + expand n dir arg@('@' : f) = readRecursively n (dir f) `catchIOError` const (print "?" >> return [arg]) expand _n _dir x = return [x] readRecursively :: Int -> FilePath -> IO [String] diff --git a/Cabal/src/Distribution/Compat/Time.hs b/Cabal/src/Distribution/Compat/Time.hs index 168c2d919b4..9727690bf16 100644 --- a/Cabal/src/Distribution/Compat/Time.hs +++ b/Cabal/src/Distribution/Compat/Time.hs @@ -155,7 +155,7 @@ posixSecondsToModTime s = posixTimeToModTime :: POSIXTime -> ModTime posixTimeToModTime p = ModTime $ - (ceiling $ p * 1e7) -- 100 ns precision + ceiling (p * 1e7) -- 100 ns precision + (secToUnixEpoch * windowsTick) -- | Return age of given file in days. diff --git a/Cabal/src/Distribution/ReadE.hs b/Cabal/src/Distribution/ReadE.hs index 072dee99044..d7a64b8d079 100644 --- a/Cabal/src/Distribution/ReadE.hs +++ b/Cabal/src/Distribution/ReadE.hs @@ -55,7 +55,7 @@ runParsecFromString p txt = parsecToReadE :: (String -> ErrorMsg) -> ParsecParser a -> ReadE a parsecToReadE err p = ReadE $ \txt -> - (const $ err txt) `Bi.first` runParsecFromString p txt + const (err txt) `Bi.first` runParsecFromString p txt parsecToReadEErr :: (Parsec.ParseError -> ErrorMsg) -> ParsecParser a -> ReadE a parsecToReadEErr err p = diff --git a/Cabal/src/Distribution/Simple/Build.hs b/Cabal/src/Distribution/Simple/Build.hs index c2e421045bf..25a0af6db3e 100644 --- a/Cabal/src/Distribution/Simple/Build.hs +++ b/Cabal/src/Distribution/Simple/Build.hs @@ -857,7 +857,7 @@ testSuiteLibV09AsLibAndExe { hsSourceDirs = [unsafeMakeSymbolicPath testDir] , targetBuildDepends = testLibDep - : (targetBuildDepends $ testBuildInfo test) + : targetBuildDepends (testBuildInfo test) } } -- \| The stub executable needs a new 'ComponentLocalBuildInfo' diff --git a/Cabal/src/Distribution/Simple/Haddock.hs b/Cabal/src/Distribution/Simple/Haddock.hs index 8e90f6f6dd3..04e96130836 100644 --- a/Cabal/src/Distribution/Simple/Haddock.hs +++ b/Cabal/src/Distribution/Simple/Haddock.hs @@ -395,7 +395,7 @@ haddock pkg_descr lbi suffixes flags' = do return $ PackageIndex.insert ipi index CFLib flib -> - ( when (flag haddockForeignLibs) $ do + when (flag haddockForeignLibs) (do withTempDirectoryEx verbosity tmpFileOpts (buildDir lbi') "tmp" $ \tmp -> do smsg @@ -409,12 +409,11 @@ haddock pkg_descr lbi suffixes flags' = do version flib let libArgs' = commonArgs `mappend` flibArgs - runHaddock verbosity tmpFileOpts comp platform haddockProg True libArgs' - ) + runHaddock verbosity tmpFileOpts comp platform haddockProg True libArgs') >> return index - CExe _ -> (when (flag haddockExecutables) $ smsg >> doExe component) >> return index - CTest _ -> (when (flag haddockTestSuites) $ smsg >> doExe component) >> return index - CBench _ -> (when (flag haddockBenchmarks) $ smsg >> doExe component) >> return index + CExe _ -> when (flag haddockExecutables) (smsg >> doExe component) >> return index + CTest _ -> when (flag haddockTestSuites) (smsg >> doExe component) >> return index + CBench _ -> when (flag haddockBenchmarks) (smsg >> doExe component) >> return index for_ (extraDocFiles pkg_descr) $ \fpath -> do files <- matchDirFileGlob verbosity (specVersion pkg_descr) "." fpath @@ -937,8 +936,7 @@ renderPureArgs version comp platform args = renderInterface :: (FilePath, Maybe FilePath, Maybe FilePath, Visibility) -> String renderInterface (i, html, hypsrc, visibility) = "--read-interface=" - ++ ( intercalate "," $ - concat + ++ intercalate "," (concat [ [fromMaybe "" html] , -- only render hypsrc path if html path -- is given and hyperlinked-source is @@ -962,8 +960,7 @@ renderPureArgs version comp platform args = ] else [] , [i] - ] - ) + ]) bool a b c = if c then a else b isVersion major minor = version >= mkVersion [major, minor] diff --git a/Cabal/src/Distribution/Utils/Json.hs b/Cabal/src/Distribution/Utils/Json.hs index 873e60631ac..4f8bea52cbe 100644 --- a/Cabal/src/Distribution/Utils/Json.hs +++ b/Cabal/src/Distribution/Utils/Json.hs @@ -39,7 +39,7 @@ renderJson json = toLazyByteString (go json) go (JsonObject attrs) = surround "{" "}" $ mconcat $ intersperse "," $ map render attrs where - render (k, v) = (surround "\"" "\"" $ stringUtf8 (escape k)) <> ":" <> go v + render (k, v) = surround "\"" "\"" (stringUtf8 (escape k)) <> ":" <> go v go (JsonString s) = surround "\"" "\"" $ stringUtf8 (escape s) surround :: Builder -> Builder -> Builder -> Builder diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Linking.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Linking.hs index eb3c98a8aca..3e4e2de3ee6 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Linking.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Linking.hs @@ -85,11 +85,11 @@ validateLinking index = (`runReader` initVS) . go go :: Tree d c -> Validate (Tree d c) go (PChoice qpn rdm gr cs) = - PChoice qpn rdm gr <$> (W.traverseWithKey (goP qpn) $ fmap go cs) + PChoice qpn rdm gr <$> W.traverseWithKey (goP qpn) (fmap go cs) go (FChoice qfn rdm gr t m d cs) = - FChoice qfn rdm gr t m d <$> (W.traverseWithKey (goF qfn) $ fmap go cs) + FChoice qfn rdm gr t m d <$> W.traverseWithKey (goF qfn) (fmap go cs) go (SChoice qsn rdm gr t cs) = - SChoice qsn rdm gr t <$> (W.traverseWithKey (goS qsn) $ fmap go cs) + SChoice qsn rdm gr t <$> W.traverseWithKey (goS qsn) (fmap go cs) -- For the other nodes we just recurse go (GoalChoice rdm cs) = GoalChoice rdm <$> T.traverse go cs diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs index eade1c3a1a0..d802079d04c 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs @@ -66,7 +66,7 @@ showMessages = go 0 go !l (Step (Next (Goal (P _ ) gr)) (Step (TryP qpn' i) ms@(Step Enter (Step (Next _) _)))) = (atLevel l $ "trying: " ++ showQPNPOpt qpn' i ++ showGR gr) (go l ms) go !l (Step (Next (Goal (P qpn) gr)) (Step (Failure _c UnknownPackage) ms)) = - (atLevel l $ "unknown package: " ++ showQPN qpn ++ showGR gr) $ go l ms + atLevel l ("unknown package: " ++ showQPN qpn ++ showGR gr) $ go l ms -- standard display go !l (Step Enter ms) = go (l+1) ms go !l (Step Leave ms) = go (l-1) ms diff --git a/cabal-install/src/Distribution/Client/CmdRun.hs b/cabal-install/src/Distribution/Client/CmdRun.hs index cf9338e82d3..8d259324225 100644 --- a/cabal-install/src/Distribution/Client/CmdRun.hs +++ b/cabal-install/src/Distribution/Client/CmdRun.hs @@ -514,12 +514,13 @@ renderRunProblem (TargetProblemMatchesMultiple targetSelector targets) = ++ " which includes \n" ++ unlines ( (\(label, xs) -> "- " ++ label ++ ": " ++ renderListPretty xs) - <$> ( zip ["executables", "test-suites", "benchmarks"] $ - filter (not . null) . map removeDuplicates $ - map (componentNameRaw . availableTargetComponentName) - <$> (flip filterTargetsKind $ targets) - <$> [ExeKind, TestKind, BenchKind] - ) + <$> zip + ["executables", "test-suites", "benchmarks"] + ( filter (not . null) . map removeDuplicates $ + map (componentNameRaw . availableTargetComponentName) + <$> (flip filterTargetsKind $ targets) + <$> [ExeKind, TestKind, BenchKind] + ) ) where removeDuplicates = catMaybes . map safeHead . group . sort diff --git a/cabal-install/src/Distribution/Client/GenBounds.hs b/cabal-install/src/Distribution/Client/GenBounds.hs index e3584ab8cd4..ab69bb55efb 100644 --- a/cabal-install/src/Distribution/Client/GenBounds.hs +++ b/cabal-install/src/Distribution/Client/GenBounds.hs @@ -104,7 +104,7 @@ pvpize v = showBounds :: Package pkg => Int -> pkg -> String showBounds padTo p = unwords $ - (padAfter padTo $ unPackageName $ packageName p) + padAfter padTo (unPackageName $ packageName p) : -- TODO: use normaliseVersionRange map showInterval (asVersionIntervals $ pvpize $ packageVersion p) diff --git a/cabal-install/src/Distribution/Client/Install.hs b/cabal-install/src/Distribution/Client/Install.hs index 93ad8e5ae2e..a7eed14fbba 100644 --- a/cabal-install/src/Distribution/Client/Install.hs +++ b/cabal-install/src/Distribution/Client/Install.hs @@ -1790,7 +1790,7 @@ installLocalTarballPackage distDirExists <- doesDirectoryExist distDirPath when ( distDirExists - && (not $ distDirPath `equalFilePath` distDirPathNew) + && not (distDirPath `equalFilePath` distDirPathNew) ) $ do -- NB: we need to handle the case when 'distDirPathNew' is a diff --git a/cabal-install/src/Distribution/Client/List.hs b/cabal-install/src/Distribution/Client/List.hs index ef9285bf39d..55f5f34c893 100644 --- a/cabal-install/src/Distribution/Client/List.hs +++ b/cabal-install/src/Distribution/Client/List.hs @@ -431,8 +431,7 @@ showPackageSummaryInfo pkginfo = renderStyle (style{lineLength = 80, ribbonsPerLine = 1}) $ char '*' <+> pretty (pkgName pkginfo) - $+$ ( nest 4 $ - vcat + $+$ nest 4 (vcat [ maybeShowST (synopsis pkginfo) "Synopsis:" reflowParagraphs , text "Default available version:" <+> case selectedSourcePkg pkginfo of @@ -450,8 +449,7 @@ showPackageSummaryInfo pkginfo = versions , maybeShowST (homepage pkginfo) "Homepage:" text , text "License: " <+> either pretty pretty (license pkginfo) - ] - ) + ]) $+$ text "" where maybeShowST l s f @@ -466,8 +464,7 @@ showPackageDetailedInfo pkginfo = <<>> maybe Disp.empty (\v -> char '-' Disp.<> pretty v) (selectedVersion pkginfo) <+> text (replicate (16 - length (prettyShow (pkgName pkginfo))) ' ') <<>> parens pkgkind - $+$ ( nest 4 $ - vcat + $+$ nest 4 (vcat [ entryST "Synopsis" synopsis hideIfNull reflowParagraphs , entry "Versions available" @@ -501,8 +498,7 @@ showPackageDetailedInfo pkginfo = , if not (hasLib pkginfo) then mempty else text "Modules:" $+$ nest 4 (vcat (map pretty . sort . modules $ pkginfo)) - ] - ) + ]) $+$ text "" where entry fname field cond format = case cond (field pkginfo) of diff --git a/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs b/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs index 57aa77af891..018ea89552e 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs @@ -193,7 +193,8 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig = let components = J.object $ [ comp2str c - J..= ( J.object $ + J..= J.object + ( [ "depends" J..= map (jdisplay . confInstId) (map fst ldeps) , "exe-depends" J..= map (jdisplay . confInstId) edeps ] diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index a67a66a0e53..28066513dee 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -414,7 +414,7 @@ rebuildProjectConfig let fetchCompiler = do -- have to create the cache directory before configuring the compiler liftIO $ createDirectoryIfMissingVerbose verbosity True distProjectCacheDirectory - (compiler, Platform arch os, _) <- configureCompiler verbosity distDirLayout ((fst $ PD.ignoreConditions projectConfigSkeleton) <> cliConfig) + (compiler, Platform arch os, _) <- configureCompiler verbosity distDirLayout (fst (PD.ignoreConditions projectConfigSkeleton) <> cliConfig) pure (os, arch, compilerInfo compiler) projectConfig <- instantiateProjectConfigSkeletonFetchingCompiler fetchCompiler mempty projectConfigSkeleton @@ -4545,7 +4545,7 @@ packageHashInputs Set.fromList ( map confInstId - ( (map fst $ compLibDependencies comp) + ( map fst (compLibDependencies comp) ++ compExeDependencies comp ) ) diff --git a/cabal-install/src/Distribution/Client/Utils.hs b/cabal-install/src/Distribution/Client/Utils.hs index f7a51bf8c49..6a744fca3be 100644 --- a/cabal-install/src/Distribution/Client/Utils.hs +++ b/cabal-install/src/Distribution/Client/Utils.hs @@ -229,7 +229,7 @@ logDirChange _ Nothing m = m logDirChange l (Just d) m = do l $ "cabal: Entering directory '" ++ d ++ "'\n" m - `Exception.finally` (l $ "cabal: Leaving directory '" ++ d ++ "'\n") + `Exception.finally` l ("cabal: Leaving directory '" ++ d ++ "'\n") -- The number of processors is not going to change during the duration of the -- program, so unsafePerformIO is safe here. diff --git a/generics-sop-lens.hs b/generics-sop-lens.hs index 457c4dabae9..3c3b484b720 100644 --- a/generics-sop-lens.hs +++ b/generics-sop-lens.hs @@ -64,13 +64,13 @@ genericClassyLenses p = case gdatatypeInfo p of , " " ++ dn' ++ " :: Lens' a " ++ dn , "" ]] ++ - (hcollapse $ hcmap (Proxy :: Proxy Typeable) deriveCls fis) ++ + hcollapse (hcmap (Proxy :: Proxy Typeable) deriveCls fis) ++ [[ "" , "instance Has" ++ dn ++ " " ++ dn ++ " where" , " " ++ dn' ++ " = id" , " {-# INLINE " ++ dn' ++ " #-}" ]] ++ - (hcollapse $ hcmap (Proxy :: Proxy Typeable) deriveInst fis) + hcollapse (hcmap (Proxy :: Proxy Typeable) deriveInst fis) where dn' = case dn of [] -> [] From 6eed6f5d0a85a8c813497cbb51d53a6d8c1bfbdb Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Tue, 11 Jul 2023 08:06:01 -0400 Subject: [PATCH 5/8] Satisfy fourmolu. --- Cabal/src/Distribution/Simple/Haddock.hs | 86 +++++++++++++----------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/Cabal/src/Distribution/Simple/Haddock.hs b/Cabal/src/Distribution/Simple/Haddock.hs index 04e96130836..774d3646017 100644 --- a/Cabal/src/Distribution/Simple/Haddock.hs +++ b/Cabal/src/Distribution/Simple/Haddock.hs @@ -395,21 +395,24 @@ haddock pkg_descr lbi suffixes flags' = do return $ PackageIndex.insert ipi index CFLib flib -> - when (flag haddockForeignLibs) (do - withTempDirectoryEx verbosity tmpFileOpts (buildDir lbi') "tmp" $ - \tmp -> do - smsg - flibArgs <- - fromForeignLib - verbosity - tmp - lbi' - clbi - htmlTemplate - version - flib - let libArgs' = commonArgs `mappend` flibArgs - runHaddock verbosity tmpFileOpts comp platform haddockProg True libArgs') + when + (flag haddockForeignLibs) + ( do + withTempDirectoryEx verbosity tmpFileOpts (buildDir lbi') "tmp" $ + \tmp -> do + smsg + flibArgs <- + fromForeignLib + verbosity + tmp + lbi' + clbi + htmlTemplate + version + flib + let libArgs' = commonArgs `mappend` flibArgs + runHaddock verbosity tmpFileOpts comp platform haddockProg True libArgs' + ) >> return index CExe _ -> when (flag haddockExecutables) (smsg >> doExe component) >> return index CTest _ -> when (flag haddockTestSuites) (smsg >> doExe component) >> return index @@ -936,31 +939,34 @@ renderPureArgs version comp platform args = renderInterface :: (FilePath, Maybe FilePath, Maybe FilePath, Visibility) -> String renderInterface (i, html, hypsrc, visibility) = "--read-interface=" - ++ intercalate "," (concat - [ [fromMaybe "" html] - , -- only render hypsrc path if html path - -- is given and hyperlinked-source is - -- enabled - - [ case (html, hypsrc) of - (Nothing, _) -> "" - (_, Nothing) -> "" - (_, Just x) - | isVersion 2 17 - , fromFlagOrDefault False . argLinkedSource $ args -> - x - | otherwise -> - "" - ] - , if haddockSupportsVisibility - then - [ case visibility of - Visible -> "visible" - Hidden -> "hidden" - ] - else [] - , [i] - ]) + ++ intercalate + "," + ( concat + [ [fromMaybe "" html] + , -- only render hypsrc path if html path + -- is given and hyperlinked-source is + -- enabled + + [ case (html, hypsrc) of + (Nothing, _) -> "" + (_, Nothing) -> "" + (_, Just x) + | isVersion 2 17 + , fromFlagOrDefault False . argLinkedSource $ args -> + x + | otherwise -> + "" + ] + , if haddockSupportsVisibility + then + [ case visibility of + Visible -> "visible" + Hidden -> "hidden" + ] + else [] + , [i] + ] + ) bool a b c = if c then a else b isVersion major minor = version >= mkVersion [major, minor] From 3350a6c8a40eeef6e9997b542741d643477e463f Mon Sep 17 00:00:00 2001 From: Josh Meredith Date: Sun, 16 Jul 2023 13:59:38 +1000 Subject: [PATCH 6/8] Support asm/cmm/js sources in executable components (#8639) (#9061) * WIP support asm/cmm/js sources in executable components (#8639) * Factorise extra src code for lib/exe and add extra exe src tests * Add extra sources to linking step * lint * lint * Don't build js sources for executables on non-js hosts * Fix cabal.out for CmmSourcesExe test and lint * Update changelog * Slight changes --- Cabal/src/Distribution/Simple/GHC.hs | 405 ++++++------------ .../PackageTests/CmmSourcesExe/cabal.out | 8 + .../PackageTests/CmmSourcesExe/cabal.project | 1 + .../PackageTests/CmmSourcesExe/cabal.test.hs | 6 + .../CmmSourcesExe/cbits/HeapPrim.cmm | 6 + .../CmmSourcesExe/cmmexperiment.cabal | 23 + .../PackageTests/CmmSourcesExe/demo/Main.hs | 2 + .../PackageTests/CmmSourcesExe/setup.out | 5 + .../PackageTests/CmmSourcesExe/setup.test.hs | 7 + .../PackageTests/CmmSourcesExe/src/Demo.hs | 37 ++ .../JS/JsSourcesExe/cabal.project | 1 + .../PackageTests/JS/JsSourcesExe/demo/Main.hs | 6 + .../JS/JsSourcesExe/js-arch.test.hs | 9 + .../JS/JsSourcesExe/jsbits/lib.js | 3 + .../JS/JsSourcesExe/jssources-exe.cabal | 20 + .../JS/JsSourcesExe/other-arch.out | 12 + .../JS/JsSourcesExe/other-arch.test.hs | 7 + .../PackageTests/JS/JsSourcesExe/src/Lib.hs | 4 + .../PackageTests/JS/JsSourcesExe/srcJS/Lib.hs | 3 + changelog.d/issue-8639 | 12 + 20 files changed, 305 insertions(+), 272 deletions(-) create mode 100644 cabal-testsuite/PackageTests/CmmSourcesExe/cabal.out create mode 100644 cabal-testsuite/PackageTests/CmmSourcesExe/cabal.project create mode 100644 cabal-testsuite/PackageTests/CmmSourcesExe/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/CmmSourcesExe/cbits/HeapPrim.cmm create mode 100644 cabal-testsuite/PackageTests/CmmSourcesExe/cmmexperiment.cabal create mode 100644 cabal-testsuite/PackageTests/CmmSourcesExe/demo/Main.hs create mode 100644 cabal-testsuite/PackageTests/CmmSourcesExe/setup.out create mode 100644 cabal-testsuite/PackageTests/CmmSourcesExe/setup.test.hs create mode 100644 cabal-testsuite/PackageTests/CmmSourcesExe/src/Demo.hs create mode 100644 cabal-testsuite/PackageTests/JS/JsSourcesExe/cabal.project create mode 100644 cabal-testsuite/PackageTests/JS/JsSourcesExe/demo/Main.hs create mode 100644 cabal-testsuite/PackageTests/JS/JsSourcesExe/js-arch.test.hs create mode 100644 cabal-testsuite/PackageTests/JS/JsSourcesExe/jsbits/lib.js create mode 100644 cabal-testsuite/PackageTests/JS/JsSourcesExe/jssources-exe.cabal create mode 100644 cabal-testsuite/PackageTests/JS/JsSourcesExe/other-arch.out create mode 100644 cabal-testsuite/PackageTests/JS/JsSourcesExe/other-arch.test.hs create mode 100644 cabal-testsuite/PackageTests/JS/JsSourcesExe/src/Lib.hs create mode 100644 cabal-testsuite/PackageTests/JS/JsSourcesExe/srcJS/Lib.hs create mode 100644 changelog.d/issue-8639 diff --git a/Cabal/src/Distribution/Simple/GHC.hs b/Cabal/src/Distribution/Simple/GHC.hs index f01d096e48c..656a258ca02 100644 --- a/Cabal/src/Distribution/Simple/GHC.hs +++ b/Cabal/src/Distribution/Simple/GHC.hs @@ -808,213 +808,72 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do else do vanilla; shared whenProfLib (runGhcProg profOpts) + let + buildExtraSources mkSrcOpts wantDyn = traverse_ $ buildExtraSource mkSrcOpts wantDyn + buildExtraSource mkSrcOpts wantDyn filename = do + let baseSrcOpts = + mkSrcOpts + verbosity + implInfo + lbi + libBi + clbi + relLibTargetDir + filename + vanillaSrcOpts + -- Dynamic GHC requires C sources to be built + -- with -fPIC for REPL to work. See #2207. + | isGhcDynamic && wantDyn = baseSrcOpts{ghcOptFPic = toFlag True} + | otherwise = baseSrcOpts + runGhcProgIfNeeded opts = do + needsRecomp <- checkNeedsRecompilation filename opts + when needsRecomp $ runGhcProg opts + profSrcOpts = + vanillaSrcOpts + `mappend` mempty + { ghcOptProfilingMode = toFlag True + , ghcOptObjSuffix = toFlag "p_o" + } + sharedSrcOpts = + vanillaSrcOpts + `mappend` mempty + { ghcOptFPic = toFlag True + , ghcOptDynLinkMode = toFlag GhcDynamicOnly + , ghcOptObjSuffix = toFlag "dyn_o" + } + odir = fromFlag (ghcOptObjDir vanillaSrcOpts) + + createDirectoryIfMissingVerbose verbosity True odir + runGhcProgIfNeeded vanillaSrcOpts + unless (forRepl || not wantDyn) $ + whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedSrcOpts) + unless forRepl $ + whenProfLib (runGhcProgIfNeeded profSrcOpts) + -- Build any C++ sources separately. unless (not has_code || null (cxxSources libBi)) $ do info verbosity "Building C++ Sources..." - sequence_ - [ do - let baseCxxOpts = - Internal.componentCxxGhcOptions - verbosity - implInfo - lbi - libBi - clbi - relLibTargetDir - filename - vanillaCxxOpts = - if isGhcDynamic - then baseCxxOpts{ghcOptFPic = toFlag True} - else baseCxxOpts - profCxxOpts = - vanillaCxxOpts - `mappend` mempty - { ghcOptProfilingMode = toFlag True - , ghcOptObjSuffix = toFlag "p_o" - } - sharedCxxOpts = - vanillaCxxOpts - `mappend` mempty - { ghcOptFPic = toFlag True - , ghcOptDynLinkMode = toFlag GhcDynamicOnly - , ghcOptObjSuffix = toFlag "dyn_o" - } - odir = fromFlag (ghcOptObjDir vanillaCxxOpts) - createDirectoryIfMissingVerbose verbosity True odir - let runGhcProgIfNeeded cxxOpts = do - needsRecomp <- checkNeedsRecompilation filename cxxOpts - when needsRecomp $ runGhcProg cxxOpts - runGhcProgIfNeeded vanillaCxxOpts - unless forRepl $ - whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedCxxOpts) - unless forRepl $ whenProfLib (runGhcProgIfNeeded profCxxOpts) - | filename <- cxxSources libBi - ] + buildExtraSources Internal.componentCxxGhcOptions True (cxxSources libBi) -- build any C sources unless (not has_code || null (cSources libBi)) $ do info verbosity "Building C Sources..." - sequence_ - [ do - let baseCcOpts = - Internal.componentCcGhcOptions - verbosity - implInfo - lbi - libBi - clbi - relLibTargetDir - filename - vanillaCcOpts = - if isGhcDynamic - then -- Dynamic GHC requires C sources to be built - -- with -fPIC for REPL to work. See #2207. - baseCcOpts{ghcOptFPic = toFlag True} - else baseCcOpts - profCcOpts = - vanillaCcOpts - `mappend` mempty - { ghcOptProfilingMode = toFlag True - , ghcOptObjSuffix = toFlag "p_o" - } - sharedCcOpts = - vanillaCcOpts - `mappend` mempty - { ghcOptFPic = toFlag True - , ghcOptDynLinkMode = toFlag GhcDynamicOnly - , ghcOptObjSuffix = toFlag "dyn_o" - } - odir = fromFlag (ghcOptObjDir vanillaCcOpts) - createDirectoryIfMissingVerbose verbosity True odir - let runGhcProgIfNeeded ccOpts = do - needsRecomp <- checkNeedsRecompilation filename ccOpts - when needsRecomp $ runGhcProg ccOpts - runGhcProgIfNeeded vanillaCcOpts - unless forRepl $ - whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedCcOpts) - unless forRepl $ whenProfLib (runGhcProgIfNeeded profCcOpts) - | filename <- cSources libBi - ] + buildExtraSources Internal.componentCcGhcOptions True (cSources libBi) -- build any JS sources unless (not has_code || not hasJsSupport || null (jsSources libBi)) $ do info verbosity "Building JS Sources..." - sequence_ - [ do - let vanillaJsOpts = - Internal.componentJsGhcOptions - verbosity - implInfo - lbi - libBi - clbi - relLibTargetDir - filename - profJsOpts = - vanillaJsOpts - `mappend` mempty - { ghcOptProfilingMode = toFlag True - , ghcOptObjSuffix = toFlag "p_o" - } - odir = fromFlag (ghcOptObjDir vanillaJsOpts) - createDirectoryIfMissingVerbose verbosity True odir - let runGhcProgIfNeeded jsOpts = do - needsRecomp <- checkNeedsRecompilation filename jsOpts - when needsRecomp $ runGhcProg jsOpts - runGhcProgIfNeeded vanillaJsOpts - unless forRepl $ whenProfLib (runGhcProgIfNeeded profJsOpts) - | filename <- jsSources libBi - ] + buildExtraSources Internal.componentJsGhcOptions False (jsSources libBi) -- build any ASM sources unless (not has_code || null (asmSources libBi)) $ do info verbosity "Building Assembler Sources..." - sequence_ - [ do - let baseAsmOpts = - Internal.componentAsmGhcOptions - verbosity - implInfo - lbi - libBi - clbi - relLibTargetDir - filename - vanillaAsmOpts = - if isGhcDynamic - then -- Dynamic GHC requires objects to be built - -- with -fPIC for REPL to work. See #2207. - baseAsmOpts{ghcOptFPic = toFlag True} - else baseAsmOpts - profAsmOpts = - vanillaAsmOpts - `mappend` mempty - { ghcOptProfilingMode = toFlag True - , ghcOptObjSuffix = toFlag "p_o" - } - sharedAsmOpts = - vanillaAsmOpts - `mappend` mempty - { ghcOptFPic = toFlag True - , ghcOptDynLinkMode = toFlag GhcDynamicOnly - , ghcOptObjSuffix = toFlag "dyn_o" - } - odir = fromFlag (ghcOptObjDir vanillaAsmOpts) - createDirectoryIfMissingVerbose verbosity True odir - let runGhcProgIfNeeded asmOpts = do - needsRecomp <- checkNeedsRecompilation filename asmOpts - when needsRecomp $ runGhcProg asmOpts - runGhcProgIfNeeded vanillaAsmOpts - unless forRepl $ - whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedAsmOpts) - unless forRepl $ whenProfLib (runGhcProgIfNeeded profAsmOpts) - | filename <- asmSources libBi - ] + buildExtraSources Internal.componentAsmGhcOptions True (asmSources libBi) -- build any Cmm sources unless (not has_code || null (cmmSources libBi)) $ do info verbosity "Building C-- Sources..." - sequence_ - [ do - let baseCmmOpts = - Internal.componentCmmGhcOptions - verbosity - implInfo - lbi - libBi - clbi - relLibTargetDir - filename - vanillaCmmOpts = - if isGhcDynamic - then -- Dynamic GHC requires C sources to be built - -- with -fPIC for REPL to work. See #2207. - baseCmmOpts{ghcOptFPic = toFlag True} - else baseCmmOpts - profCmmOpts = - vanillaCmmOpts - `mappend` mempty - { ghcOptProfilingMode = toFlag True - , ghcOptObjSuffix = toFlag "p_o" - } - sharedCmmOpts = - vanillaCmmOpts - `mappend` mempty - { ghcOptFPic = toFlag True - , ghcOptDynLinkMode = toFlag GhcDynamicOnly - , ghcOptObjSuffix = toFlag "dyn_o" - } - odir = fromFlag (ghcOptObjDir vanillaCmmOpts) - createDirectoryIfMissingVerbose verbosity True odir - let runGhcProgIfNeeded cmmOpts = do - needsRecomp <- checkNeedsRecompilation filename cmmOpts - when needsRecomp $ runGhcProg cmmOpts - runGhcProgIfNeeded vanillaCmmOpts - unless forRepl $ - whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedCmmOpts) - unless forRepl $ whenProfLib (runGhcProgIfNeeded profCmmOpts) - | filename <- cmmSources libBi - ] + buildExtraSources Internal.componentCmmGhcOptions True (cmmSources libBi) -- TODO: problem here is we need the .c files built first, so we can load them -- with ghci, but .c files can depend on .h files generated by ghc by ffi @@ -1550,6 +1409,9 @@ decodeMainIsArg arg data BuildSources = BuildSources { cSourcesFiles :: [FilePath] , cxxSourceFiles :: [FilePath] + , jsSourceFiles :: [FilePath] + , asmSourceFiles :: [FilePath] + , cmmSourceFiles :: [FilePath] , inputSourceFiles :: [FilePath] , inputSourceModules :: [ModuleName] } @@ -1600,6 +1462,9 @@ gbuildSources verbosity pkgId specVer tmpDir bm = BuildSources { cSourcesFiles = cSources bnfo , cxxSourceFiles = cxxSources bnfo + , jsSourceFiles = jsSources bnfo + , asmSourceFiles = asmSources bnfo + , cmmSourceFiles = cmmSources bnfo , inputSourceFiles = [main] , inputSourceModules = filter (/= mainModName) $ @@ -1610,6 +1475,9 @@ gbuildSources verbosity pkgId specVer tmpDir bm = BuildSources { cSourcesFiles = cSources bnfo , cxxSourceFiles = cxxSources bnfo + , jsSourceFiles = jsSources bnfo + , asmSourceFiles = asmSources bnfo + , cmmSourceFiles = cmmSources bnfo , inputSourceFiles = [main] , inputSourceModules = exeModules exe } @@ -1624,6 +1492,9 @@ gbuildSources verbosity pkgId specVer tmpDir bm = BuildSources { cSourcesFiles = csf , cxxSourceFiles = cxxsf + , jsSourceFiles = jsSources bnfo + , asmSourceFiles = asmSources bnfo + , cmmSourceFiles = cmmSources bnfo , inputSourceFiles = [] , inputSourceModules = exeModules exe } @@ -1633,6 +1504,9 @@ gbuildSources verbosity pkgId specVer tmpDir bm = BuildSources { cSourcesFiles = cSources bnfo , cxxSourceFiles = cxxSources bnfo + , jsSourceFiles = jsSources bnfo + , asmSourceFiles = asmSources bnfo + , cmmSourceFiles = cmmSources bnfo , inputSourceFiles = [] , inputSourceModules = foreignLibModules flib } @@ -1700,14 +1574,22 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do let cSrcs = cSourcesFiles buildSources cxxSrcs = cxxSourceFiles buildSources + jsSrcs = jsSourceFiles buildSources + asmSrcs = asmSourceFiles buildSources + cmmSrcs = cmmSourceFiles buildSources inputFiles = inputSourceFiles buildSources inputModules = inputSourceModules buildSources isGhcDynamic = isDynamic comp dynamicTooSupported = supportsDynamicToo comp cLikeObjs = map (`replaceExtension` objExtension) cSrcs cxxObjs = map (`replaceExtension` objExtension) cxxSrcs + jsObjs = if hasJsSupport then map (`replaceExtension` objExtension) jsSrcs else [] + asmObjs = map (`replaceExtension` objExtension) asmSrcs + cmmObjs = map (`replaceExtension` objExtension) cmmSrcs needDynamic = gbuildNeedDynamic lbi bm needProfiling = withProfExe lbi + Platform hostArch _ = hostPlatform lbi + hasJsSupport = hostArch == JavaScript -- build executables baseOpts = @@ -1794,14 +1676,14 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do PD.extraFrameworkDirs bnfo , ghcOptInputFiles = toNubListR - [tmpDir x | x <- cLikeObjs ++ cxxObjs] + [tmpDir x | x <- cLikeObjs ++ cxxObjs ++ jsObjs ++ cmmObjs ++ asmObjs] } dynLinkerOpts = mempty { ghcOptRPaths = rpaths , ghcOptInputFiles = toNubListR - [tmpDir x | x <- cLikeObjs ++ cxxObjs] + [tmpDir x | x <- cLikeObjs ++ cxxObjs ++ cmmObjs ++ asmObjs] } replOpts = baseOpts @@ -1876,95 +1758,74 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do , ghcOptNumJobs = numJobs } + let + buildExtraSources mkSrcOpts wantDyn = traverse_ $ buildExtraSource mkSrcOpts wantDyn + buildExtraSource mkSrcOpts wantDyn filename = do + let baseSrcOpts = + mkSrcOpts + verbosity + implInfo + lbi + bnfo + clbi + tmpDir + filename + vanillaSrcOpts = + if isGhcDynamic && wantDyn + then -- Dynamic GHC requires C/C++ sources to be built + -- with -fPIC for REPL to work. See #2207. + baseSrcOpts{ghcOptFPic = toFlag True} + else baseSrcOpts + profSrcOpts = + vanillaSrcOpts + `mappend` mempty + { ghcOptProfilingMode = toFlag True + } + sharedSrcOpts = + vanillaSrcOpts + `mappend` mempty + { ghcOptFPic = toFlag True + , ghcOptDynLinkMode = toFlag GhcDynamicOnly + } + opts + | needProfiling = profSrcOpts + | needDynamic && wantDyn = sharedSrcOpts + | otherwise = vanillaSrcOpts + -- TODO: Placing all Haskell, C, & C++ objects in a single directory + -- Has the potential for file collisions. In general we would + -- consider this a user error. However, we should strive to + -- add a warning if this occurs. + odir = fromFlag (ghcOptObjDir opts) + + createDirectoryIfMissingVerbose verbosity True odir + needsRecomp <- checkNeedsRecompilation filename opts + when needsRecomp $ + runGhcProg opts + -- build any C++ sources unless (null cxxSrcs) $ do info verbosity "Building C++ Sources..." - sequence_ - [ do - let baseCxxOpts = - Internal.componentCxxGhcOptions - verbosity - implInfo - lbi - bnfo - clbi - tmpDir - filename - vanillaCxxOpts = - if isGhcDynamic - then -- Dynamic GHC requires C++ sources to be built - -- with -fPIC for REPL to work. See #2207. - baseCxxOpts{ghcOptFPic = toFlag True} - else baseCxxOpts - profCxxOpts = - vanillaCxxOpts - `mappend` mempty - { ghcOptProfilingMode = toFlag True - } - sharedCxxOpts = - vanillaCxxOpts - `mappend` mempty - { ghcOptFPic = toFlag True - , ghcOptDynLinkMode = toFlag GhcDynamicOnly - } - opts - | needProfiling = profCxxOpts - | needDynamic = sharedCxxOpts - | otherwise = vanillaCxxOpts - -- TODO: Placing all Haskell, C, & C++ objects in a single directory - -- Has the potential for file collisions. In general we would - -- consider this a user error. However, we should strive to - -- add a warning if this occurs. - odir = fromFlag (ghcOptObjDir opts) - createDirectoryIfMissingVerbose verbosity True odir - needsRecomp <- checkNeedsRecompilation filename opts - when needsRecomp $ - runGhcProg opts - | filename <- cxxSrcs - ] + buildExtraSources Internal.componentCxxGhcOptions True cxxSrcs -- build any C sources unless (null cSrcs) $ do info verbosity "Building C Sources..." - sequence_ - [ do - let baseCcOpts = - Internal.componentCcGhcOptions - verbosity - implInfo - lbi - bnfo - clbi - tmpDir - filename - vanillaCcOpts = - if isGhcDynamic - then -- Dynamic GHC requires C sources to be built - -- with -fPIC for REPL to work. See #2207. - baseCcOpts{ghcOptFPic = toFlag True} - else baseCcOpts - profCcOpts = - vanillaCcOpts - `mappend` mempty - { ghcOptProfilingMode = toFlag True - } - sharedCcOpts = - vanillaCcOpts - `mappend` mempty - { ghcOptFPic = toFlag True - , ghcOptDynLinkMode = toFlag GhcDynamicOnly - } - opts - | needProfiling = profCcOpts - | needDynamic = sharedCcOpts - | otherwise = vanillaCcOpts - odir = fromFlag (ghcOptObjDir opts) - createDirectoryIfMissingVerbose verbosity True odir - needsRecomp <- checkNeedsRecompilation filename opts - when needsRecomp $ - runGhcProg opts - | filename <- cSrcs - ] + buildExtraSources Internal.componentCcGhcOptions True cSrcs + + -- build any JS sources + unless (not hasJsSupport || null jsSrcs) $ do + info verbosity "Building JS Sources..." + buildExtraSources Internal.componentJsGhcOptions False jsSrcs + + -- build any ASM sources + unless (null asmSrcs) $ do + info verbosity "Building Assembler Sources..." + buildExtraSources Internal.componentAsmGhcOptions True asmSrcs + + -- build any Cmm sources + unless (null cmmSrcs) $ do + info verbosity "Building C-- Sources..." + buildExtraSources Internal.componentCmmGhcOptions True cmmSrcs -- TODO: problem here is we need the .c files built first, so we can load them -- with ghci, but .c files can depend on .h files generated by ghc by ffi diff --git a/cabal-testsuite/PackageTests/CmmSourcesExe/cabal.out b/cabal-testsuite/PackageTests/CmmSourcesExe/cabal.out new file mode 100644 index 00000000000..77b94906515 --- /dev/null +++ b/cabal-testsuite/PackageTests/CmmSourcesExe/cabal.out @@ -0,0 +1,8 @@ +# cabal v2-run +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - cmmexperiment-0 (exe:demo) (first run) +Configuring executable 'demo' for cmmexperiment-0... +Preprocessing executable 'demo' for cmmexperiment-0... +Building executable 'demo' for cmmexperiment-0... diff --git a/cabal-testsuite/PackageTests/CmmSourcesExe/cabal.project b/cabal-testsuite/PackageTests/CmmSourcesExe/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/CmmSourcesExe/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/CmmSourcesExe/cabal.test.hs b/cabal-testsuite/PackageTests/CmmSourcesExe/cabal.test.hs new file mode 100644 index 00000000000..0fa879eaedb --- /dev/null +++ b/cabal-testsuite/PackageTests/CmmSourcesExe/cabal.test.hs @@ -0,0 +1,6 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + res <- cabal' "v2-run" ["demo"] + assertOutputContains "= Post common block elimination =" res + assertOutputContains "In Box we have 0x" res diff --git a/cabal-testsuite/PackageTests/CmmSourcesExe/cbits/HeapPrim.cmm b/cabal-testsuite/PackageTests/CmmSourcesExe/cbits/HeapPrim.cmm new file mode 100644 index 00000000000..d4319291052 --- /dev/null +++ b/cabal-testsuite/PackageTests/CmmSourcesExe/cbits/HeapPrim.cmm @@ -0,0 +1,6 @@ +#include "Cmm.h" + +aToMyWordzh (P_ clos) +{ + return (clos); +} diff --git a/cabal-testsuite/PackageTests/CmmSourcesExe/cmmexperiment.cabal b/cabal-testsuite/PackageTests/CmmSourcesExe/cmmexperiment.cabal new file mode 100644 index 00000000000..b26391e6e84 --- /dev/null +++ b/cabal-testsuite/PackageTests/CmmSourcesExe/cmmexperiment.cabal @@ -0,0 +1,23 @@ +cabal-version: 3.0 +name: cmmexperiment +version: 0 +build-type: Simple + +-- This code is extracted form ghc-heap +-- Copyright (c) 2012-2013, Joachim Breitner +-- (and probably -2020 GHC Team) +-- Under BSD-3-Clause + +executable demo + default-language: Haskell2010 + main-is: Main.hs + hs-source-dirs: demo, src + build-depends: base + other-modules: Demo + cmm-sources: cbits/HeapPrim.cmm + if impl(ghc >=8.2) + cmm-options: -ddump-cmm-verbose + else + cmm-options: -ddump-cmm + + diff --git a/cabal-testsuite/PackageTests/CmmSourcesExe/demo/Main.hs b/cabal-testsuite/PackageTests/CmmSourcesExe/demo/Main.hs new file mode 100644 index 00000000000..e220ffc4c7c --- /dev/null +++ b/cabal-testsuite/PackageTests/CmmSourcesExe/demo/Main.hs @@ -0,0 +1,2 @@ +module Main (module Demo) where +import Demo (main) diff --git a/cabal-testsuite/PackageTests/CmmSourcesExe/setup.out b/cabal-testsuite/PackageTests/CmmSourcesExe/setup.out new file mode 100644 index 00000000000..c336268eaee --- /dev/null +++ b/cabal-testsuite/PackageTests/CmmSourcesExe/setup.out @@ -0,0 +1,5 @@ +# Setup configure +Configuring cmmexperiment-0... +# Setup build +Preprocessing executable 'demo' for cmmexperiment-0... +Building executable 'demo' for cmmexperiment-0... diff --git a/cabal-testsuite/PackageTests/CmmSourcesExe/setup.test.hs b/cabal-testsuite/PackageTests/CmmSourcesExe/setup.test.hs new file mode 100644 index 00000000000..7bf57f2628f --- /dev/null +++ b/cabal-testsuite/PackageTests/CmmSourcesExe/setup.test.hs @@ -0,0 +1,7 @@ +import Test.Cabal.Prelude + +main = setupTest $ do + skipUnlessGhcVersion ">= 7.8" + setup "configure" [] + res <- setup' "build" [] + assertOutputContains "= Post common block elimination =" res diff --git a/cabal-testsuite/PackageTests/CmmSourcesExe/src/Demo.hs b/cabal-testsuite/PackageTests/CmmSourcesExe/src/Demo.hs new file mode 100644 index 00000000000..ad44a3b650e --- /dev/null +++ b/cabal-testsuite/PackageTests/CmmSourcesExe/src/Demo.hs @@ -0,0 +1,37 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE GHCForeignImportPrim #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnliftedFFITypes #-} +module Demo (main) where + +#include "MachDeps.h" + +import Data.Bits +import GHC.Exts +import Numeric (showHex) + +foreign import prim "aToMyWordzh" aToWord# :: Any -> Word# + +tAG_MASK :: Int +tAG_MASK = (1 `shift` TAG_BITS) - 1 + +data Box = Box Any + +instance Show Box where + showsPrec _ (Box a) rs = + -- unsafePerformIO (print "↓" >> pClosure a) `seq` + pad_out (showHex addr "") ++ (if tag>0 then "/" ++ show tag else "") ++ rs + where + ptr = W# (aToWord# a) + tag = ptr .&. fromIntegral tAG_MASK -- ((1 `shiftL` TAG_BITS) -1) + addr = ptr - tag + pad_out ls = '0':'x':ls + +asBox :: a -> Box +asBox x = Box (unsafeCoerce# x) + +main :: IO () +main = do + let box = asBox "foobar" + putStrLn $ "In Box we have " ++ show box diff --git a/cabal-testsuite/PackageTests/JS/JsSourcesExe/cabal.project b/cabal-testsuite/PackageTests/JS/JsSourcesExe/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSourcesExe/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/JS/JsSourcesExe/demo/Main.hs b/cabal-testsuite/PackageTests/JS/JsSourcesExe/demo/Main.hs new file mode 100644 index 00000000000..19e67f001f8 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSourcesExe/demo/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Lib + +main :: IO () +main = foo diff --git a/cabal-testsuite/PackageTests/JS/JsSourcesExe/js-arch.test.hs b/cabal-testsuite/PackageTests/JS/JsSourcesExe/js-arch.test.hs new file mode 100644 index 00000000000..1fed749bdb8 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSourcesExe/js-arch.test.hs @@ -0,0 +1,9 @@ +import Test.Cabal.Prelude + +main = setupAndCabalTest $ do + skipUnlessGhcVersion ">= 9.6" + skipUnlessJavaScript + skipIfWindows + + res <- cabal' "v2-run" ["demo"] + assertOutputContains "Hello JS!" res diff --git a/cabal-testsuite/PackageTests/JS/JsSourcesExe/jsbits/lib.js b/cabal-testsuite/PackageTests/JS/JsSourcesExe/jsbits/lib.js new file mode 100644 index 00000000000..125643b9a41 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSourcesExe/jsbits/lib.js @@ -0,0 +1,3 @@ +function foo() { + console.log("Hello JS!"); +} diff --git a/cabal-testsuite/PackageTests/JS/JsSourcesExe/jssources-exe.cabal b/cabal-testsuite/PackageTests/JS/JsSourcesExe/jssources-exe.cabal new file mode 100644 index 00000000000..3e19513ac9b --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSourcesExe/jssources-exe.cabal @@ -0,0 +1,20 @@ +cabal-version: 3.0 +name: jssources-exe +version: 0 +build-type: Simple + +library + default-language: Haskell2010 + if arch(JavaScript) + hs-source-dirs: srcJS + else + hs-source-dirs: src + exposed-modules: Lib + build-depends: base + +executable demo + default-language: Haskell2010 + main-is: Main.hs + hs-source-dirs: demo + js-sources: jsbits/lib.js + build-depends: base, jssources-exe diff --git a/cabal-testsuite/PackageTests/JS/JsSourcesExe/other-arch.out b/cabal-testsuite/PackageTests/JS/JsSourcesExe/other-arch.out new file mode 100644 index 00000000000..96e1bbadcf9 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSourcesExe/other-arch.out @@ -0,0 +1,12 @@ +# cabal v2-run +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - jssources-exe-0 (lib) (first run) + - jssources-exe-0 (exe:demo) (first run) +Configuring library for jssources-exe-0... +Preprocessing library for jssources-exe-0... +Building library for jssources-exe-0... +Configuring executable 'demo' for jssources-exe-0... +Preprocessing executable 'demo' for jssources-exe-0... +Building executable 'demo' for jssources-exe-0... diff --git a/cabal-testsuite/PackageTests/JS/JsSourcesExe/other-arch.test.hs b/cabal-testsuite/PackageTests/JS/JsSourcesExe/other-arch.test.hs new file mode 100644 index 00000000000..187a9cf73bd --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSourcesExe/other-arch.test.hs @@ -0,0 +1,7 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + skipIfJavaScript + -- Ensure the field `js-sources` does not raise issues + res <- cabal' "v2-run" ["demo"] + assertOutputContains "Hello Not JS!" res diff --git a/cabal-testsuite/PackageTests/JS/JsSourcesExe/src/Lib.hs b/cabal-testsuite/PackageTests/JS/JsSourcesExe/src/Lib.hs new file mode 100644 index 00000000000..7937e6f34ed --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSourcesExe/src/Lib.hs @@ -0,0 +1,4 @@ +module Lib where + +foo :: IO () +foo = putStrLn "Hello Not JS!" diff --git a/cabal-testsuite/PackageTests/JS/JsSourcesExe/srcJS/Lib.hs b/cabal-testsuite/PackageTests/JS/JsSourcesExe/srcJS/Lib.hs new file mode 100644 index 00000000000..af628af03ec --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSourcesExe/srcJS/Lib.hs @@ -0,0 +1,3 @@ +module Lib where + +foreign import javascript foo :: IO () diff --git a/changelog.d/issue-8639 b/changelog.d/issue-8639 new file mode 100644 index 00000000000..18d8606c690 --- /dev/null +++ b/changelog.d/issue-8639 @@ -0,0 +1,12 @@ +synopsis: Add support for asm, cmm, and js sources in executable components +packages: Cabal +prs: #9061 +issues: #8639 +significance: significant + +description: { + +Executable components now support the inclusion of asm, cmm, and js source files in a cabal file using the same syntax as is used for these sources in library components, similar to how c and c++ sources are supported in both types of components. This syntax was already parsed in cabal files, but was silently ignored in the build step, so no changes to syntax are made. + +} + From d4d17d015783902385596a3774ee3844ac1eb499 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Wed, 12 Jul 2023 07:52:36 -0500 Subject: [PATCH 7/8] Use case insensitive match on ETag headers Fixes #9113. --- cabal-install/src/Distribution/Client/HttpUtils.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cabal-install/src/Distribution/Client/HttpUtils.hs b/cabal-install/src/Distribution/Client/HttpUtils.hs index 3d27882097b..8cf9bce7203 100644 --- a/cabal-install/src/Distribution/Client/HttpUtils.hs +++ b/cabal-install/src/Distribution/Client/HttpUtils.hs @@ -125,6 +125,7 @@ import qualified Data.ByteString.Base16 as Base16 import qualified Data.ByteString.Char8 as BS8 import qualified Data.ByteString.Lazy as LBS import qualified Data.ByteString.Lazy.Char8 as LBS8 +import qualified Data.Char as Char import qualified Distribution.Compat.CharParsing as P ------------------------------------------------------------------------------ @@ -626,7 +627,8 @@ curlTransport prog = listToMaybe $ reverse [ etag - | ["ETag:", etag] <- map words (lines headers) + | [name, etag] <- map words (lines headers) + , isETag name ] in case codeerr of Just (i, err) -> return (i, err, mb_etag) @@ -776,7 +778,8 @@ wgetTransport prog = mb_etag = listToMaybe [ etag - | ["ETag:", etag] <- map words (reverse (lines resp)) + | [name, etag] <- map words (reverse (lines resp)) + , isETag name ] in case parsedCode of Just i -> return (i, mb_etag) @@ -1146,3 +1149,6 @@ genBoundary :: IO String genBoundary = do i <- randomRIO (0x10000000000000, 0xFFFFFFFFFFFFFF) :: IO Integer return $ showHex i "" + +isETag :: String -> Bool +isETag name = fmap Char.toLower name == "etag:" From 2564b547e9eb4f823c07310eee2459a4ddd476f2 Mon Sep 17 00:00:00 2001 From: Artem Pelenitsyn Date: Sat, 15 Jul 2023 22:06:55 -0400 Subject: [PATCH 8/8] Fix fourmolu --- cabal-install/src/Distribution/Client/List.hs | 112 +++++++++--------- .../Distribution/Client/ProjectPlanOutput.hs | 11 +- 2 files changed, 64 insertions(+), 59 deletions(-) diff --git a/cabal-install/src/Distribution/Client/List.hs b/cabal-install/src/Distribution/Client/List.hs index 55f5f34c893..dc3723913e9 100644 --- a/cabal-install/src/Distribution/Client/List.hs +++ b/cabal-install/src/Distribution/Client/List.hs @@ -431,25 +431,28 @@ showPackageSummaryInfo pkginfo = renderStyle (style{lineLength = 80, ribbonsPerLine = 1}) $ char '*' <+> pretty (pkgName pkginfo) - $+$ nest 4 (vcat - [ maybeShowST (synopsis pkginfo) "Synopsis:" reflowParagraphs - , text "Default available version:" - <+> case selectedSourcePkg pkginfo of - Nothing -> text "[ Not available from any configured repository ]" - Just pkg -> pretty (packageVersion pkg) - , text "Installed versions:" - <+> case installedVersions pkginfo of - [] - | hasLib pkginfo -> text "[ Not installed ]" - | otherwise -> text "[ Unknown ]" - versions -> - dispTopVersions - 4 - (preferredVersions pkginfo) - versions - , maybeShowST (homepage pkginfo) "Homepage:" text - , text "License: " <+> either pretty pretty (license pkginfo) - ]) + $+$ nest + 4 + ( vcat + [ maybeShowST (synopsis pkginfo) "Synopsis:" reflowParagraphs + , text "Default available version:" + <+> case selectedSourcePkg pkginfo of + Nothing -> text "[ Not available from any configured repository ]" + Just pkg -> pretty (packageVersion pkg) + , text "Installed versions:" + <+> case installedVersions pkginfo of + [] + | hasLib pkginfo -> text "[ Not installed ]" + | otherwise -> text "[ Unknown ]" + versions -> + dispTopVersions + 4 + (preferredVersions pkginfo) + versions + , maybeShowST (homepage pkginfo) "Homepage:" text + , text "License: " <+> either pretty pretty (license pkginfo) + ] + ) $+$ text "" where maybeShowST l s f @@ -464,41 +467,44 @@ showPackageDetailedInfo pkginfo = <<>> maybe Disp.empty (\v -> char '-' Disp.<> pretty v) (selectedVersion pkginfo) <+> text (replicate (16 - length (prettyShow (pkgName pkginfo))) ' ') <<>> parens pkgkind - $+$ nest 4 (vcat - [ entryST "Synopsis" synopsis hideIfNull reflowParagraphs - , entry - "Versions available" - sourceVersions - (altText null "[ Not available from server ]") - (dispTopVersions 9 (preferredVersions pkginfo)) - , entry - "Versions installed" - installedVersions - ( altText - null - ( if hasLib pkginfo - then "[ Not installed ]" - else "[ Unknown ]" - ) + $+$ nest + 4 + ( vcat + [ entryST "Synopsis" synopsis hideIfNull reflowParagraphs + , entry + "Versions available" + sourceVersions + (altText null "[ Not available from server ]") + (dispTopVersions 9 (preferredVersions pkginfo)) + , entry + "Versions installed" + installedVersions + ( altText + null + ( if hasLib pkginfo + then "[ Not installed ]" + else "[ Unknown ]" ) - (dispTopVersions 4 (preferredVersions pkginfo)) - , entryST "Homepage" homepage orNotSpecified text - , entryST "Bug reports" bugReports orNotSpecified text - , entryST "Description" description hideIfNull reflowParagraphs - , entryST "Category" category hideIfNull text - , entry "License" license alwaysShow (either pretty pretty) - , entryST "Author" author hideIfNull reflowLines - , entryST "Maintainer" maintainer hideIfNull reflowLines - , entry "Source repo" sourceRepo orNotSpecified text - , entry "Executables" executables hideIfNull (commaSep pretty) - , entry "Flags" flags hideIfNull (commaSep dispFlag) - , entry "Dependencies" dependencies hideIfNull (commaSep dispExtDep) - , entry "Documentation" haddockHtml showIfInstalled text - , entry "Cached" haveTarball alwaysShow dispYesNo - , if not (hasLib pkginfo) - then mempty - else text "Modules:" $+$ nest 4 (vcat (map pretty . sort . modules $ pkginfo)) - ]) + ) + (dispTopVersions 4 (preferredVersions pkginfo)) + , entryST "Homepage" homepage orNotSpecified text + , entryST "Bug reports" bugReports orNotSpecified text + , entryST "Description" description hideIfNull reflowParagraphs + , entryST "Category" category hideIfNull text + , entry "License" license alwaysShow (either pretty pretty) + , entryST "Author" author hideIfNull reflowLines + , entryST "Maintainer" maintainer hideIfNull reflowLines + , entry "Source repo" sourceRepo orNotSpecified text + , entry "Executables" executables hideIfNull (commaSep pretty) + , entry "Flags" flags hideIfNull (commaSep dispFlag) + , entry "Dependencies" dependencies hideIfNull (commaSep dispExtDep) + , entry "Documentation" haddockHtml showIfInstalled text + , entry "Cached" haveTarball alwaysShow dispYesNo + , if not (hasLib pkginfo) + then mempty + else text "Modules:" $+$ nest 4 (vcat (map pretty . sort . modules $ pkginfo)) + ] + ) $+$ text "" where entry fname field cond format = case cond (field pkginfo) of diff --git a/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs b/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs index 018ea89552e..0e4fb108a19 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanOutput.hs @@ -194,12 +194,11 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig = J.object $ [ comp2str c J..= J.object - ( - [ "depends" J..= map (jdisplay . confInstId) (map fst ldeps) - , "exe-depends" J..= map (jdisplay . confInstId) edeps - ] - ++ bin_file c - ) + ( [ "depends" J..= map (jdisplay . confInstId) (map fst ldeps) + , "exe-depends" J..= map (jdisplay . confInstId) edeps + ] + ++ bin_file c + ) | (c, (ldeps, edeps)) <- ComponentDeps.toList $ ComponentDeps.zip