Skip to content

Commit 0ab5571

Browse files
authored
Add alex to build-tool-depends remove separate code gen (#8980)
* Add alex to build-tool-depends and remove separate code gen - Pass latin-1 encoding is passed as input pragma - Cabal hard-codes -g for alex so we don't need to worry about --ghc - Rework bootstrap, adding per-component building - Update bootstrap plans * [bootstrap] warn the user if cabal config is not found * [bootstrap] regenerate bootstrap plans once more * [bootstrap] regenerate bootstrap files after #9139
1 parent 51da23d commit 0ab5571

File tree

10 files changed

+557
-333
lines changed

10 files changed

+557
-333
lines changed

Cabal-syntax/Cabal-syntax.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ library
5858
if impl(ghc >= 8.0) && impl(ghc < 8.8)
5959
ghc-options: -Wnoncanonical-monadfail-instances
6060

61+
build-tool-depends: alex:alex
62+
6163
exposed-modules:
6264
Distribution.Backpack
6365
Distribution.CabalSpecVersion

templates/Lexer.x renamed to Cabal-syntax/src/Distribution/Fields/Lexer.x

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ module Distribution.Fields.Lexer
1919
,bol_section, in_section, in_field_layout, in_field_braces
2020
,mkLexState) where
2121

22-
-- [Note: bootstrapping parsec parser]
23-
--
24-
-- We manually produce the `Lexer.hs` file from `boot/Lexer.x` (make lexer)
25-
-- because bootstrapping cabal-install would be otherwise tricky.
26-
-- Alex is (atm) tricky package to build, cabal-install has some magic
27-
-- to move bundled generated files in place, so rather we don't depend
28-
-- on it before we can build it ourselves.
29-
-- Therefore there is one thing less to worry in bootstrap.sh, which is a win.
30-
--
31-
-- See also https://github.com/haskell/cabal/issues/4633
32-
--
33-
3422
import Prelude ()
3523
import qualified Prelude as Prelude
3624
import Distribution.Compat.Prelude
@@ -53,6 +41,8 @@ import qualified Data.Text.Encoding.Error as T
5341
}
5442
-- Various character classes
5543

44+
%encoding "latin1"
45+
5646
$space = \ -- single space char
5747
$ctlchar = [\x0-\x1f \x7f]
5848
$printable = \x0-\xff # $ctlchar -- so no \n \r

Makefile

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,6 @@ style-modified: ## Run the code styler on modified files
2525
@git ls-files --modified Cabal Cabal-syntax cabal-install \
2626
| grep '.hs$$' | xargs -P $(PROCS) -I {} fourmolu -q -i {}
2727

28-
# source generation: Lexer
29-
30-
LEXER_HS:=Cabal-syntax/src/Distribution/Fields/Lexer.hs
31-
32-
lexer : $(LEXER_HS)
33-
34-
$(LEXER_HS) : templates/Lexer.x
35-
alex --latin1 --ghc -o $@ $^
36-
@rm -f Lexer.tmp
37-
echo '{- FOURMOLU_DISABLE -}' >> Lexer.tmp
38-
cat -s $@ >> Lexer.tmp
39-
mv Lexer.tmp $@
40-
4128
# source generation: SPDX
4229

4330
SPDX_LICENSE_HS:=Cabal-syntax/src/Distribution/SPDX/LicenseId.hs

bootstrap/bootstrap.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class PackageSource(Enum):
6464
('revision', Optional[int]),
6565
('cabal_sha256', Optional[SHA256Hash]),
6666
('flags', List[str]),
67+
('component', Optional[str])
6768
])
6869

6970
BootstrapInfo = NamedTuple('BootstrapInfo', [
@@ -189,9 +190,9 @@ def install_dep(dep: BootstrapDep, ghc: Compiler) -> None:
189190

190191
sdist_dir = resolve_dep(dep)
191192

192-
install_sdist(dist_dir, sdist_dir, ghc, dep.flags)
193+
install_sdist(dist_dir, sdist_dir, ghc, dep.flags, dep.component)
193194

194-
def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[str]):
195+
def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[str], component):
195196
prefix = PSEUDOSTORE.resolve()
196197
flags_option = ' '.join(flags)
197198
setup_dist_dir = dist_dir / 'setup'
@@ -205,10 +206,12 @@ def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[st
205206
f'--package-db={PKG_DB.resolve()}',
206207
f'--prefix={prefix}',
207208
f'--bindir={BINDIR.resolve()}',
209+
f'--extra-prog-path={BINDIR.resolve()}',
208210
f'--with-compiler={ghc.ghc_path}',
209211
f'--with-hc-pkg={ghc.ghc_pkg_path}',
210212
f'--with-hsc2hs={ghc.hsc2hs_path}',
211213
f'--flags={flags_option}',
214+
f'{component or ""}'
212215
]
213216

214217
def check_call(args: List[str]) -> None:

bootstrap/cabal.project

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@
33

44
packages: .
55
optimization: False
6-
7-
allow-newer:
8-
cabal-install-parsers:Cabal-syntax

0 commit comments

Comments
 (0)