Skip to content

Commit

Permalink
Add alex to build-tool-depends remove separate code gen (#8980)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
andreabedini authored Aug 10, 2023
1 parent 51da23d commit 0ab5571
Show file tree
Hide file tree
Showing 10 changed files with 557 additions and 333 deletions.
2 changes: 2 additions & 0 deletions Cabal-syntax/Cabal-syntax.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ library
if impl(ghc >= 8.0) && impl(ghc < 8.8)
ghc-options: -Wnoncanonical-monadfail-instances

build-tool-depends: alex:alex

exposed-modules:
Distribution.Backpack
Distribution.CabalSpecVersion
Expand Down
14 changes: 2 additions & 12 deletions templates/Lexer.x → Cabal-syntax/src/Distribution/Fields/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ module Distribution.Fields.Lexer
,bol_section, in_section, in_field_layout, in_field_braces
,mkLexState) where

-- [Note: bootstrapping parsec parser]
--
-- We manually produce the `Lexer.hs` file from `boot/Lexer.x` (make lexer)
-- because bootstrapping cabal-install would be otherwise tricky.
-- Alex is (atm) tricky package to build, cabal-install has some magic
-- to move bundled generated files in place, so rather we don't depend
-- on it before we can build it ourselves.
-- Therefore there is one thing less to worry in bootstrap.sh, which is a win.
--
-- See also https://github.com/haskell/cabal/issues/4633
--

import Prelude ()
import qualified Prelude as Prelude
import Distribution.Compat.Prelude
Expand All @@ -53,6 +41,8 @@ import qualified Data.Text.Encoding.Error as T
}
-- Various character classes

%encoding "latin1"

$space = \ -- single space char
$ctlchar = [\x0-\x1f \x7f]
$printable = \x0-\xff # $ctlchar -- so no \n \r
Expand Down
13 changes: 0 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ style-modified: ## Run the code styler on modified files
@git ls-files --modified Cabal Cabal-syntax cabal-install \
| grep '.hs$$' | xargs -P $(PROCS) -I {} fourmolu -q -i {}

# source generation: Lexer

LEXER_HS:=Cabal-syntax/src/Distribution/Fields/Lexer.hs

lexer : $(LEXER_HS)

$(LEXER_HS) : templates/Lexer.x
alex --latin1 --ghc -o $@ $^
@rm -f Lexer.tmp
echo '{- FOURMOLU_DISABLE -}' >> Lexer.tmp
cat -s $@ >> Lexer.tmp
mv Lexer.tmp $@

# source generation: SPDX

SPDX_LICENSE_HS:=Cabal-syntax/src/Distribution/SPDX/LicenseId.hs
Expand Down
7 changes: 5 additions & 2 deletions bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class PackageSource(Enum):
('revision', Optional[int]),
('cabal_sha256', Optional[SHA256Hash]),
('flags', List[str]),
('component', Optional[str])
])

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

sdist_dir = resolve_dep(dep)

install_sdist(dist_dir, sdist_dir, ghc, dep.flags)
install_sdist(dist_dir, sdist_dir, ghc, dep.flags, dep.component)

def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[str]):
def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[str], component):
prefix = PSEUDOSTORE.resolve()
flags_option = ' '.join(flags)
setup_dist_dir = dist_dir / 'setup'
Expand All @@ -205,10 +206,12 @@ def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[st
f'--package-db={PKG_DB.resolve()}',
f'--prefix={prefix}',
f'--bindir={BINDIR.resolve()}',
f'--extra-prog-path={BINDIR.resolve()}',
f'--with-compiler={ghc.ghc_path}',
f'--with-hc-pkg={ghc.ghc_pkg_path}',
f'--with-hsc2hs={ghc.hsc2hs_path}',
f'--flags={flags_option}',
f'{component or ""}'
]

def check_call(args: List[str]) -> None:
Expand Down
3 changes: 0 additions & 3 deletions bootstrap/cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@

packages: .
optimization: False

allow-newer:
cabal-install-parsers:Cabal-syntax
Loading

0 comments on commit 0ab5571

Please sign in to comment.