Skip to content

Commit c7cf8e2

Browse files
committed
Musical chairs, part 1: add warnings and aliases
1 parent fb67b25 commit c7cf8e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+413
-156
lines changed

Cabal/Distribution/Simple/Setup.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ module Distribution.Simple.Setup (
6060
buildOptions, haddockOptions, installDirsOptions,
6161
programDbOptions, programDbPaths',
6262
programConfigurationOptions, programConfigurationPaths',
63+
programFlagsDescription,
6364
splitArgs,
6465

6566
defaultDistPref, optionDistPref,

Cabal/doc/nix-local-build-overview.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ Nix-style Local Builds
22
======================
33

44
Nix-style local builds are a new build system implementation inspired by Nix.
5-
The Nix-style local build system is commonly called "new-build" for short after the ``cabal new-*`` family of commands that control it.
6-
However those names are only temporary until Nix-style local builds becomes the default.
5+
The Nix-style local build system is commonly called "new-build" for short
6+
after the ``cabal new-*`` family of commands that control it. However, those
7+
names are only temporary until Nix-style local builds become the default.
8+
This is expected to happen soon. For those who do not wish to use the new
9+
functionality, the classic project style will not be removed immediately,
10+
but these legacy commands will require the usage of the ``v1-`` prefix as of
11+
Cabal 3.0 and will be removed in a future release.
712

813
Nix-style local builds combine the best of non-sandboxed and sandboxed Cabal:
914

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE FlexibleInstances #-}
3+
{-# LANGUAGE RecordWildCards #-}
4+
{-# LANGUAGE ViewPatterns #-}
5+
module Distribution.Client.CmdLegacy (legacyCmd) where
6+
7+
import Prelude ()
8+
import Distribution.Client.Compat.Prelude
9+
10+
import qualified Distribution.Client.Setup as Client
11+
import qualified Distribution.Simple.Setup as Setup
12+
import Distribution.Simple.Command
13+
import Distribution.Simple.Utils
14+
( warn )
15+
import Distribution.Verbosity
16+
( Verbosity, normal )
17+
18+
import qualified Data.Text as T
19+
20+
-- Duplicated code (it's identical to Main.regularCmd), but makes things cleaner
21+
-- and lets me keep how this happens a dirty little secret.
22+
makeCmd :: CommandUI flags -> (flags -> [String] -> action) -> CommandSpec action
23+
makeCmd ui action = CommandSpec ui ((flip commandAddAction) action) NormalCommand
24+
25+
deprecationNote :: String -> String
26+
deprecationNote cmd =
27+
"The " ++ cmd ++ " command is a part of the legacy v1 style of cabal usage.\n\n" ++
28+
29+
"Please switch to using either the new project style or the legacy v1-" ++ cmd ++ "\n" ++
30+
"alias as new-style projects will become the default in the next version of\n" ++
31+
"cabal-install. Please file a bug if you cannot replicate a working v1- use\n" ++
32+
"case with the new-style commands.\n"
33+
34+
legacyNote :: String -> String
35+
legacyNote cmd =
36+
"The v1-" ++ cmd ++ " command is a part of the legacy v1 style of cabal usage.\n\n" ++
37+
38+
"It is a legacy feature and will be removed in a future release of cabal-install.\n" ++
39+
"Please file a bug if you cannot replicate a working v1- use case with the new-style\n" ++
40+
"commands.\n"
41+
42+
--
43+
44+
class HasVerbosity a where
45+
verbosity :: a -> Verbosity
46+
47+
instance HasVerbosity (Setup.Flag Verbosity) where
48+
verbosity = Setup.fromFlagOrDefault normal
49+
50+
instance (HasVerbosity a) => HasVerbosity (a, b) where
51+
verbosity (a, _) = verbosity a
52+
53+
instance (HasVerbosity b) => HasVerbosity (a, b, c) where
54+
verbosity (_ , b, _) = verbosity b
55+
56+
instance (HasVerbosity a) => HasVerbosity (a, b, c, d) where
57+
verbosity (a, _, _, _) = verbosity a
58+
59+
instance HasVerbosity Setup.BuildFlags where
60+
verbosity = verbosity . Setup.buildVerbosity
61+
62+
instance HasVerbosity Setup.ConfigFlags where
63+
verbosity = verbosity . Setup.configVerbosity
64+
65+
instance HasVerbosity Setup.ReplFlags where
66+
verbosity = verbosity . Setup.replVerbosity
67+
68+
instance HasVerbosity Client.FreezeFlags where
69+
verbosity = verbosity . Client.freezeVerbosity
70+
71+
instance HasVerbosity Setup.HaddockFlags where
72+
verbosity = verbosity . Setup.haddockVerbosity
73+
74+
instance HasVerbosity Client.ExecFlags where
75+
verbosity = verbosity . Client.execVerbosity
76+
77+
instance HasVerbosity Client.UpdateFlags where
78+
verbosity = verbosity . Client.updateVerbosity
79+
80+
instance HasVerbosity Setup.CleanFlags where
81+
verbosity = verbosity . Setup.cleanVerbosity
82+
83+
--
84+
85+
legacyCmd :: (HasVerbosity flags) => CommandUI flags -> (flags -> [String] -> globals -> IO action) -> [CommandSpec (globals -> IO action)]
86+
legacyCmd origUi@CommandUI{..} action = [makeCmd legUi action, makeCmd depUi depAction]
87+
where
88+
legacyMsg = T.unpack . T.replace "v1-" "" . T.pack
89+
90+
depNote = deprecationNote commandName
91+
legNote = legacyNote commandName
92+
93+
depAction flags extra globals = warn (verbosity flags) (depNote ++ "\n") >> action flags extra globals
94+
95+
legUi = origUi
96+
{ commandName = "v1-" ++ commandName
97+
, commandNotes = Just $ \pname -> case commandNotes of
98+
Just notes -> notes pname ++ "\n" ++ legNote
99+
Nothing -> legNote
100+
}
101+
102+
depUi = origUi
103+
{ commandName = legacyMsg commandName
104+
, commandUsage = legacyMsg . commandUsage
105+
, commandDescription = (legacyMsg .) <$> commandDescription
106+
, commandNotes = Just $ \pname -> case commandNotes of
107+
Just notes -> legacyMsg (notes pname) ++ "\n" ++ depNote
108+
Nothing -> depNote
109+
}

0 commit comments

Comments
 (0)