Skip to content

Add alex to build-tool-depends remove separate code gen #8980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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