Skip to content

Commit

Permalink
Move purescript-cst to a bazel rule
Browse files Browse the repository at this point in the history
We want to work around an issue with packages not at the top-level.

It looks as though there's some issue in the newer versions of
`rules_haskell` for Haskell packages that aren't at the top-level. This
comment gives an overview of the problem:
tweag/rules_haskell#1392 (comment).
To paraphrase, Haskell packages in a sub-directory don't really work
with `stack ls dependencies json` at the moment.

Since we want to update `rules_haskell` to a newer version, we need to
address this. We can make this change now without updating the version
so that the version bump of `rules_haskell` has a smaller diff.

In all likelihood, this issue will be fixed at some point. Haskell
packages in a sub-directory are fairly common. Until that day, we follow
most of the workaround laid out in that GitHub issue: pull in the
package as a `bazel` `http_archive` rule, point `stack_snapshot` to the
package as a `vendored_package`.

The part we do a bit differently is not stripping down to the
sub-directory. Instead, we treat the whole archive as one thing and
locate the files based on where they live from the top-level. We take
this approach primarily because we're going to pull in both
`purescript-ast` and `purescript-cst`.

Since the commit we're using doesn't have a
`lib/purescript-cst/purescript-cst.cabal` file, we have to patch it to
add that.
  • Loading branch information
joneshf authored and Zelenya committed Feb 26, 2021
1 parent 901e53f commit 6e9a1f1
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 2 deletions.
34 changes: 33 additions & 1 deletion WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ http_archive(
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz",
],
)

http_archive(
name = "purescript_cst",
build_file = "//third_party/purescript-cst:purescript-cst.BUILD",
patch_args = [
"-p1",
],
patches = [
"//third_party/purescript-cst:purescript-cst-cabal-file.patch",
],
strip_prefix = "purescript-81909a9585b00bc99cc47c7959fbc5ae2e1ff285/lib/purescript-cst",
sha256 = "f2d685b754d93328fd2d175af0748f6f3bce7335c5d14157427876df38b566c3",
urls = [
"https://github.com/joneshf/purescript/archive/81909a9585b00bc99cc47c7959fbc5ae2e1ff285.zip",
],
)

# Dependencies

load(
Expand Down Expand Up @@ -137,14 +154,29 @@ stack_snapshot(
local_snapshot = "//:snapshot.yaml",
name = "stackage",
packages = [
# our dependencies
"componentm",
"optparse-applicative",
"pathwalk",
"purescript-cst",
"rio",
# `purescript-cst` dependencies
# These have to be here so the `//third_party/purescript:purescript-cst` package can pick them up.
# If we ever can get rid of the `//third_party/purescript:purescript-cst` package,
# we can remove these dependencies
"array",
"base",
"containers",
"dlist",
"purescript-ast",
"scientific",
"semigroups",
"text",
],
tools = [
"@alex",
"@happy",
],
vendored_packages = {
"purescript-cst": "@purescript_cst//:purescript-cst",
},
)
1 change: 0 additions & 1 deletion snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ packages:
commit: 81909a9585b00bc99cc47c7959fbc5ae2e1ff285
subdirs:
- lib/purescript-ast
- lib/purescript-cst
resolver: lts-13.26
Empty file.
110 changes: 110 additions & 0 deletions third_party/purescript-cst/purescript-cst-cabal-file.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
diff --git a/purescript-cst.cabal b/purescript-cst.cabal
new file mode 100644
index 00000000..dbb1ed9b
--- /dev/null
+++ b/purescript-cst.cabal
@@ -0,0 +1,104 @@
+cabal-version: 1.12
+
+-- This file has been generated from package.yaml by hpack version 0.31.1.
+--
+-- see: https://github.com/sol/hpack
+--
+-- hash: ff73e382fe3eaea97d6533a6b3512e14ec9eae7888720be48ae9f929e59cd733
+
+name: purescript-cst
+version: 0.13.6
+synopsis: PureScript Programming Language Concrete Syntax Tree
+description: The surface syntax of the PureScript Programming Language.
+category: Language
+stability: experimental
+homepage: http://www.purescript.org/
+bug-reports: https://github.com/purescript/purescript/issues
+author: Phil Freeman <paf31@cantab.net>
+maintainer: Gary Burgess <gary.burgess@gmail.com>, Hardy Jones <jones3.hardy@gmail.com>, Harry Garrood <harry@garrood.me>, Christoph Hegemann <christoph.hegemann1337@gmail.com>, Liam Goodacre <goodacre.liam@gmail.com>, Nathan Faubion <nathan@n-son.com>
+
+copyright: (c) 2013-17 Phil Freeman, (c) 2014-19 Gary Burgess, (c) other contributors (see CONTRIBUTORS.md)
+license: BSD3
+license-file: LICENSE
+build-type: Simple
+extra-source-files:
+ tests/purs/layout/AdoIn.purs
+ tests/purs/layout/CaseGuards.purs
+ tests/purs/layout/CaseWhere.purs
+ tests/purs/layout/ClassHead.purs
+ tests/purs/layout/Commas.purs
+ tests/purs/layout/Delimiter.purs
+ tests/purs/layout/DoLet.purs
+ tests/purs/layout/DoOperator.purs
+ tests/purs/layout/DoWhere.purs
+ tests/purs/layout/IfThenElseDo.purs
+ tests/purs/layout/InstanceChainElse.purs
+ tests/purs/layout/LetGuards.purs
+ README.md
+
+source-repository head
+ type: git
+ location: https://github.com/purescript/purescript
+
+library
+ exposed-modules:
+ Language.PureScript.CST.Convert
+ Language.PureScript.CST.Errors
+ Language.PureScript.CST.Layout
+ Language.PureScript.CST.Lexer
+ Language.PureScript.CST.Monad
+ Language.PureScript.CST.Parser
+ Language.PureScript.CST.Positions
+ Language.PureScript.CST.Print
+ Language.PureScript.CST.Traversals
+ Language.PureScript.CST.Traversals.Type
+ Language.PureScript.CST.Types
+ Language.PureScript.CST.Utils
+ other-modules:
+ Paths_purescript_cst
+ hs-source-dirs:
+ src
+ default-extensions: ConstraintKinds DataKinds DeriveFunctor DeriveFoldable DeriveTraversable DeriveGeneric DerivingStrategies EmptyDataDecls FlexibleContexts KindSignatures LambdaCase MultiParamTypeClasses NoImplicitPrelude PatternGuards PatternSynonyms RankNTypes RecordWildCards OverloadedStrings ScopedTypeVariables TupleSections ViewPatterns
+ ghc-options: -Wall -O2
+ build-tools:
+ happy ==1.19.9
+ build-depends:
+ array
+ , base >=4.11 && <4.13
+ , containers
+ , dlist
+ , purescript-ast
+ , scientific >=0.3.4.9 && <0.4
+ , semigroups >=0.16.2 && <0.19
+ , text
+ default-language: Haskell2010
+
+test-suite tests
+ type: exitcode-stdio-1.0
+ main-is: Main.hs
+ other-modules:
+ TestCst
+ Paths_purescript_cst
+ hs-source-dirs:
+ tests
+ default-extensions: NoImplicitPrelude LambdaCase OverloadedStrings
+ ghc-options: -Wall
+ build-tools:
+ happy ==1.19.9
+ build-depends:
+ array
+ , base >=4.11 && <4.13
+ , base-compat >=0.6.0
+ , bytestring
+ , containers
+ , dlist
+ , filepath
+ , purescript-ast
+ , purescript-cst
+ , scientific >=0.3.4.9 && <0.4
+ , semigroups >=0.16.2 && <0.19
+ , tasty
+ , tasty-golden
+ , tasty-quickcheck
+ , text
+ default-language: Haskell2010
24 changes: 24 additions & 0 deletions third_party/purescript-cst/purescript-cst.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load(
"@rules_haskell//haskell:cabal.bzl",
"haskell_cabal_library",
)

load(
"@stackage//:packages.bzl",
"packages",
)

haskell_cabal_library(
name = "purescript-cst",
deps = packages["purescript-cst"].deps,
srcs = glob([
"**",
]),
tools = [
"@happy//:happy",
],
version = packages["purescript-cst"].version,
visibility = [
"//visibility:public",
],
)

0 comments on commit 6e9a1f1

Please sign in to comment.