Skip to content

Commit

Permalink
nhm-tool: use cradle bios in generated hie.yaml
Browse files Browse the repository at this point in the history
the bios shell script returns an error message with advice to run make env if
GHC environment file (technically, a symbolic link to this file) is missing,
the new approach was implemented in examples/labeledMediaRouting and
haskell/ngx-export-distribution/test
  • Loading branch information
lyokha committed May 1, 2024
1 parent 2d16af6 commit 11530ab
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 23 deletions.
11 changes: 8 additions & 3 deletions examples/labeledMediaRouting/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ GHC := ghc
CABAL := cabal
GHCVER := $(shell $(GHC) --numeric-version)
GHCENV := .ghc.environment.$(MACHINE)-$(KERNEL)-$(GHCVER)
GHCENVLNK := .ghc.environment.lnk
DEPLIBS := $(MACHINE)-$(KERNEL)-ghc-$(GHCVER)
BUILDDIR := dist-nhm
SETUPCONFIG := $(BUILDDIR)/setup-config
Expand All @@ -34,7 +35,7 @@ SETUPCONFIG := $(BUILDDIR)/setup-config

all: env $(DISTR)

env: $(GHCENV) $(TESTDIR)/$(GHCENV) $(TESTDIR)/LabeledMediaRouter.hs
env: $(GHCENVLNK) $(TESTDIR)/$(GHCENV) $(TESTDIR)/LabeledMediaRouter.hs

config: $(SETUPCONFIG)

Expand All @@ -54,13 +55,17 @@ $(GHCENV): cabal.project $(PKGNAME).cabal
fi; \
$(NHMTOOL) deps $(PKGNAME) -d "$(BUILDDIR)" >> $(GHCENV)

$(GHCENVLNK): $(GHCENV)
ln -sf $(GHCENV) $(GHCENVLNK)
(cd test; ln -sf ../$(GHCENV) $(GHCENVLNK))

$(TESTDIR)/$(GHCENV): $(GHCENV)
cp -u $(GHCENV) $(TESTDIR)

$(TESTDIR)/LabeledMediaRouter.hs:
(cd $(TESTDIR); ln -s ../lmr.hs LabeledMediaRouter.hs)

$(SETUPCONFIG): $(GHCENV)
$(SETUPCONFIG): $(GHCENVLNK)
if test "$(NHMTOOL)" = nhm-tool && ! command -v nhm-tool >/dev/null; \
then \
PATH=$$(dirname $$($(CABAL) list-bin $(PKGDISTR) \
Expand Down Expand Up @@ -102,6 +107,6 @@ clean:

clean-all: clean
rm -rf $(BUILDDIR)
rm -f $(GHCENV) $(DISTR) $(BENCH)
rm -f $(GHCENV) $(GHCENVLNK) test/$(GHCENVLNK) $(DISTR) $(BENCH)
rm -f $(TESTDIR)/$(GHCENV) $(TESTDIR)/LabeledMediaRouter.hs

12 changes: 10 additions & 2 deletions examples/labeledMediaRouting/hie.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
cradle:
direct:
arguments: ["-Wall", "-O2"]
bios:
shell: |
if [ -L .ghc.environment.lnk ]
then
echo -e "\x2dWall\n\x2dO2" > $HIE_BIOS_OUTPUT
else
echo -n "Ghc environment file wasn't found, "`
`"run \"make env\" and restart language server." >&2
exit 1
fi
13 changes: 11 additions & 2 deletions examples/labeledMediaRouting/test/hie.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
cradle:
direct:
arguments: ["-Wall", "-O2", "LabeledMediaRouter.hs"]
bios:
shell: |
if [ -L .ghc.environment.lnk ]
then
echo -e "\x2dWall\n\x2dO2\nLabeledMediaRouter.hs" > \
$HIE_BIOS_OUTPUT
else
echo -n "Ghc environment file wasn't found, "`
`"run \"make env\" and restart language server." >&2
exit 1
fi
6 changes: 6 additions & 0 deletions haskell/ngx-export-distribution/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 0.5.4.2

- *nhm-tool*: use cradle *bios* in generated *hie.yaml*. The bios shell script
returns an error message with advice to run *make env* if GHC environment
file (technically, a symbolic link to this file) is missing.

### 0.5.4.1

- *nhm-tool*: add a new target *make config* in generated *Makefile*: this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ngx-export-distribution
version: 0.5.4.1
version: 0.5.4.2
synopsis: Build custom libraries for Nginx Haskell module
description: Build custom libraries for
<https://github.com/lyokha/nginx-haskell-module Nginx Haskell module>.
Expand Down
29 changes: 23 additions & 6 deletions haskell/ngx-export-distribution/nhm-tool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ makefile InitData {..} = T.concat
\CABAL := cabal\n\
\GHCVER := $(shell $(GHC) --numeric-version)\n\
\GHCENV := .ghc.environment.$(MACHINE)-$(KERNEL)-$(GHCVER)\n\
\GHCENVLNK := ", ghcEnvLnk, "\n\
\DEPLIBS := $(MACHINE)-$(KERNEL)-ghc-$(GHCVER)\n\
\BUILDDIR := dist-nhm\n\
\SETUPCONFIG := $(BUILDDIR)/setup-config\n\
Expand All @@ -529,7 +530,7 @@ makefile InitData {..} = T.concat
\\n\
\all: $(DISTR)\n\
\\n\
\env: $(GHCENV)\n\
\env: $(GHCENVLNK)\n\
\\n\
\config: $(SETUPCONFIG)\n\
\\n\
Expand All @@ -541,7 +542,10 @@ makefile InitData {..} = T.concat
updatePath,
"\t$(NHMTOOL) deps $(PKGNAME) -d \"$(BUILDDIR)\" >> $(GHCENV)\n\
\\n\
\$(SETUPCONFIG): $(GHCENV)\n",
\$(GHCENVLNK): $(GHCENV)\n\
\\tln -sf $(GHCENV) $(GHCENVLNK)\n\
\\n\
\$(SETUPCONFIG): $(GHCENVLNK)\n",
updatePath,
"\trunhaskell --ghc-arg=-package=base \\\n\
\\t --ghc-arg=-package=$(PKGDISTR) Setup.hs configure \\\n\
Expand Down Expand Up @@ -572,7 +576,7 @@ makefile InitData {..} = T.concat
\\n\
\clean-all: clean\n\
\\trm -rf $(BUILDDIR)\n\
\\trm -f $(GHCENV) $(DISTR)\n"
\\trm -f $(GHCENV) $(GHCENVLNK) $(DISTR)\n"
]
where updatePath =
"\tif test \"$(NHMTOOL)\" = nhm-tool && ! command -v nhm-tool \
Expand All @@ -596,8 +600,21 @@ projectHs InitData {..} = T.concat
hieYaml :: InitData -> Text
hieYaml InitData {..} = T.concat
["cradle:\n\
\ direct:\n\
\ arguments: ["
,T.pack $ intercalate ", " $ map show initDataGhcOptions, "]\n"
\ bios:\n\
\ shell: |\n\
\ if [ -L ", ghcEnvLnk, " ]\n\
\ then\n\
\ echo -e \""
,T.replace "-" "\\x2d" $ T.pack $ intercalate "\\n" initDataGhcOptions
,"\" > $HIE_BIOS_OUTPUT\n\
\ else\n\
\ echo -n \"Ghc environment file wasn't found, \"`\n\
\ `\"run \\\"make env\\\" and restart \
\language server.\" >&2\n\
\ exit 1\n\
\ fi"
]

ghcEnvLnk :: Text
ghcEnvLnk = ".ghc.environment.lnk"

15 changes: 8 additions & 7 deletions haskell/ngx-export-distribution/test/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Build and install dependencies in local GHC environment with v2-install,
# then build the library and create a tarball with all dependent libraries

NAME := ngx_distribution_test
PKGNAME := $(subst _,-,$(NAME))
PKGVER := 0.1.0.0
Expand All @@ -26,6 +23,7 @@ GHC := ghc
CABAL := cabal
GHCVER := $(shell $(GHC) --numeric-version)
GHCENV := .ghc.environment.$(MACHINE)-$(KERNEL)-$(GHCVER)
GHCENVLNK := .ghc.environment.lnk
DEPLIBS := $(MACHINE)-$(KERNEL)-ghc-$(GHCVER)
BUILDDIR := dist-nhm
SETUPCONFIG := $(BUILDDIR)/setup-config
Expand All @@ -37,7 +35,7 @@ INPLACE := $(shell grep -q '^packages:.*\.\./$(PKGDISTR)' \

all: $(DISTR)

env: $(GHCENV)
env: $(GHCENVLNK)

config: $(SETUPCONFIG)

Expand All @@ -57,7 +55,10 @@ endif
fi; \
$(NHMTOOL) deps $(PKGNAME) -d "$(BUILDDIR)" >> $(GHCENV)

$(SETUPCONFIG): $(GHCENV)
$(GHCENVLNK): $(GHCENV)
ln -sf $(GHCENV) $(GHCENVLNK)

$(SETUPCONFIG): $(GHCENVLNK)
if test "$(NHMTOOL)" = nhm-tool && ! command -v nhm-tool >/dev/null; \
then \
PATH=$$(dirname $$($(CABAL) list-bin $(PKGDISTR) \
Expand All @@ -83,7 +84,7 @@ $(DISTR): $(SETUPCONFIG) $(SRC)
runhaskell --ghc-arg=-package=base \
--ghc-arg=-package=$(PKGDISTR) Setup.hs build \
--builddir="$(BUILDDIR)" \
--ghc-options="$(SRC) -o $(LIB) -threaded"
--ghc-options="$(SRC) -o $(LIB) $(LINKRTS)"

install: $(DISTR)
install -d $(PREFIX)
Expand All @@ -96,5 +97,5 @@ clean:

clean-all: clean
rm -rf $(BUILDDIR)
rm -f $(GHCENV) $(DISTR)
rm -f $(GHCENV) $(GHCENVLNK) $(DISTR)

12 changes: 10 additions & 2 deletions haskell/ngx-export-distribution/test/hie.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
cradle:
direct:
arguments: ["-Wall", "-O2"]
bios:
shell: |
if [ -L .ghc.environment.lnk ]
then
echo -e "\x2dWall\n\x2dO2" > $HIE_BIOS_OUTPUT
else
echo -n "Ghc environment file wasn't found, "`
`"run \"make env\" and restart language server." >&2
exit 1
fi
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ library

ghc-options: -Wall -O2 -no-keep-hi-files -no-keep-o-files

if impl(ghc >= 9.0.1)
ghc-options: -threaded

0 comments on commit 11530ab

Please sign in to comment.