graphql-engine/scripts/make/build.mk
Samir Talwar 07328fd9fc server: Automate generation and verification of Cabal files from hpack.
We currently use `hpack` to generate the Cabal files from _package.yaml_
files for the two small libraries in _server/lib_. While this is more
convenient, we also check the Cabal files into the repository to avoid
needing an extra step upon pulling changes.

In order to ensure that the Cabal files do not get out of sync with the
hpack files, this introduces a few improvements:

1.  Makefile targets to automatically generate the Cabal files without
    needing to know the correct incantation. These targets are a
    dependency of all build targets, so you can simply run
    `make build-all` and it will work.
2.  An extra comment at the top of all generated Cabal files that
    explains how to regenerate it.
3.  A `lint-hpack` Makefile target that verifies that the Cabal files
    are up-to-date.
4.  A CI job that runs `make lint-hpack`, to stop inconsistencies
    getting merged into trunk.

Most of these changes are ported from #4794.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5217
GitOrigin-RevId: d3dfbe19ec00528368d357b6d0215a7ba4062f68
2022-07-29 16:22:12 +00:00

62 lines
2.2 KiB
Makefile

# Enable secondary expansion.
.SECONDEXPANSION:
PACKAGE_YAML_FILES = $(wildcard server/lib/*/package.yaml)
GENERATED_CABAL_FILES = $(foreach package_file,$(PACKAGE_YAML_FILES),$(wildcard $(dir $(package_file))*.cabal))
.PHONY: build-all
## build-all: build all haskell packages, or "have i broken anything?"
build-all: build build-tests build-integration-tests build-pro build-pro-tests build-multitenant build-multitenant-integration-tests
.PHONY: build
## build: build non-pro graphql executable
build: $(GENERATED_CABAL_FILES)
cabal build graphql-engine
.PHONY: build-tests
## build-tests: build non-pro graphql executable tests
build-tests: $(GENERATED_CABAL_FILES)
cabal build graphql-engine-tests
.PHONY: build-integration-tests
## build-integration-tests: build hspec integration tests
build-integration-tests: $(GENERATED_CABAL_FILES)
cabal build tests-hspec
.PHONY: build-pro
## build-pro: build pro graphql executable
build-pro: $(GENERATED_CABAL_FILES)
cabal build graphql-engine-pro
.PHONY: build-pro-tests
## build-pro-tests: build pro graphql executable tests
build-pro-tests: $(GENERATED_CABAL_FILES)
cabal build graphql-engine-pro-test
.PHONY: build-multitenant
## build-multitenant: build multitenant graphql executable
build-multitenant: $(GENERATED_CABAL_FILES)
cabal build graphql-engine-multitenant
.PHONY: build-multitenant-integration-tests
## build-multitenant-integration-tests: build multitenant integration tests
build-multitenant-integration-tests: $(GENERATED_CABAL_FILES)
cabal build multitenant-integration-test
# This makes use of Make's static pattern rules. Effectively, it is generating
# multiple rules, of the form:
#
# path/to/foo/foo.cabal: path/to/foo/package.yaml
# hpack ...
# path/to/bar/bar.cabal: path/to/bar/package.yaml
# hpack ...
#
# In order to call `dir`, it uses secondary expansion.
#
# See the documentation for more information:
# https://www.gnu.org/software/make/manual/html_node/Static-Pattern.html
# https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
$(GENERATED_CABAL_FILES): %.cabal: $$(dir %)/package.yaml
./scripts/hpack.sh $@
@ touch $@ # Required because `hpack` will not change the modified timestamp if the file is up-to-date.