Skip to content

Commit 599e858

Browse files
committed
Add user-guide documentation for 'build-info'
1 parent 6ce4db8 commit 599e858

File tree

4 files changed

+162
-3
lines changed

4 files changed

+162
-3
lines changed

doc/cabal-project.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,26 @@ Advanced global configuration options
14321432
the ``-package-env -`` option that allows ignoring the package
14331433
environment files).
14341434

1435+
.. cfg-field:: build-info: True, False
1436+
--enable-build-info
1437+
--disable-build-info
1438+
:synopsis: Whether build information for each individual component should be
1439+
written in a machine readable format.
1440+
1441+
:default: ``False``
1442+
1443+
Enable generation of build information for Cabal components. Contains very detailed information
1444+
on how to build an individual component, such as compiler version, modules of a component and
1445+
how to compile the component.
1446+
1447+
The output format is in json, and the exact location can be discovered from ``plan.json``.
1448+
Note, that this field in ``plan.json`` can be ``null``, if and only if ``build-type: Custom`` is
1449+
set, and the ``Cabal`` version is too old (i.e. ``< 3.7``).
1450+
1451+
.. note::
1452+
The format and fields of the generated build information is currently experimental,
1453+
in the future we might add or remove fields, depending on the needs of other tooling.
1454+
14351455

14361456
.. cfg-field:: http-transport: curl, wget, powershell, or plain-http
14371457
--http-transport=transport
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"type": "object",
4+
"properties": {
5+
"cabal-version": {
6+
"type": "string"
7+
},
8+
"compiler": {
9+
"type": "object",
10+
"properties": {
11+
"flavour": {
12+
"type": "string"
13+
},
14+
"compiler-id": {
15+
"type": "string"
16+
},
17+
"path": {
18+
"type": "string"
19+
}
20+
},
21+
"required": ["flavour", "compiler-id", "path"]
22+
},
23+
"components": {
24+
"type": "array",
25+
"items": {
26+
"type": "object",
27+
"properties": {
28+
"type": {
29+
"type": "string"
30+
},
31+
"name": {
32+
"type": "string"
33+
},
34+
"unit-id": {
35+
"type": "string"
36+
},
37+
"compiler-args": {
38+
"type": "array",
39+
"items": {
40+
"type": "string"
41+
}
42+
},
43+
"modules": {
44+
"type": "array",
45+
"items": {
46+
"type": "string"
47+
}
48+
},
49+
"src-files": {
50+
"type": "array",
51+
"items": {
52+
"type": "string"
53+
}
54+
},
55+
"hs-src-dirs": {
56+
"type": "array",
57+
"items": {
58+
"type": "string"
59+
}
60+
},
61+
"src-dir": {
62+
"type": "string"
63+
},
64+
"cabal-file": {
65+
"type": "string"
66+
}
67+
},
68+
"required": [
69+
"type",
70+
"name",
71+
"unit-id",
72+
"compiler-args",
73+
"modules",
74+
"src-files",
75+
"hs-src-dirs",
76+
"src-dir",
77+
"cabal-file"
78+
]
79+
}
80+
}
81+
},
82+
"required": ["cabal-version", "compiler", "components"]
83+
}

doc/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
sphinx == 3.1.*
22
sphinx_rtd_theme
3+
sphinx-jsonschema == 1.16.*

doc/setup-commands.rst

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ performs the actual building, while the last both copies the build
3232
results to some permanent place and registers the package with GHC.
3333

3434
.. note ::
35-
35+
3636
Global installing of packages is not recommended.
3737
The :ref:`nix-style-builds` is the preferred way of building and installing
3838
packages.
@@ -1034,6 +1034,61 @@ Miscellaneous options
10341034
Specify a soft constraint on versions of a package. The solver will
10351035
attempt to satisfy these preferences on a "best-effort" basis.
10361036

1037+
.. option:: --enable-build-info
1038+
1039+
Generate accurate build information for build components.
1040+
1041+
Information contains meta information, such as component type, compiler type, and
1042+
Cabal library version used during the build, but also fine grained information,
1043+
such as dependencies, what modules are part of the component, etc...
1044+
1045+
On build, a file ``build-info.json`` (in the ``json`` format) will be written to
1046+
the root of the build directory.
1047+
1048+
.. note::
1049+
The format and fields of the generated build information is currently
1050+
experimental. In the future we might add or remove fields, depending
1051+
on the needs of other tooling.
1052+
1053+
:: example
1054+
{
1055+
"cabal-version": "<cabal version>",
1056+
"compiler": {
1057+
"flavour": "<compiler name>",
1058+
"compiler-id": "<compiler id>",
1059+
"path": "<absolute path of the compiler>"
1060+
},
1061+
"components": [
1062+
{
1063+
"type": "<component type, e.g. lib | bench | exe | flib | test>",
1064+
"name": "<component name>",
1065+
"unit-id": "<unitid>",
1066+
"compiler-args": [
1067+
"<compiler args necessary for compilation>"
1068+
],
1069+
"modules": [
1070+
"<modules in this component>"
1071+
],
1072+
"src-files": [
1073+
"<source files relative to hs-src-dirs>"
1074+
],
1075+
"hs-src-dirs": [
1076+
"<source directories of this component>"
1077+
],
1078+
"src-dir": "<root directory of this component>",
1079+
"cabal-file": "<cabal file location>"
1080+
}
1081+
]
1082+
}
1083+
1084+
.. jsonschema:: ./json-schemas/build-info.schema.json
1085+
1086+
.. option:: --disable-build-info
1087+
1088+
(default) Do not generate detailed build information for built components.
1089+
1090+
Already generated `build-info.json` files will be removed since they would be stale otherwise.
1091+
10371092
.. option:: --disable-response-files
10381093

10391094
Enable workaround for older versions of programs such as ``ar`` or
@@ -1132,7 +1187,7 @@ This command takes the following options:
11321187
.. option:: --hscolour-css=path
11331188

11341189
The argument *path* denotes a CSS file, which is passed to HsColour_ as in
1135-
1190+
11361191
::
11371192

11381193
$ runhaskell Setup.hs hscolour --css=*path*
@@ -1358,7 +1413,7 @@ the package.
13581413
results in real time).
13591414

13601415
.. option:: --test-options=options
1361-
1416+
13621417
Give extra options to the test executables.
13631418

13641419
.. option:: --test-option=option

0 commit comments

Comments
 (0)