Skip to content

Commit 79a4dd8

Browse files
authored
Merge pull request #248 from cucumber/pr235
docs: ✏️ Update build documentation
2 parents 08caa03 + 13b00df commit 79a4dd8

File tree

4 files changed

+83
-74
lines changed

4 files changed

+83
-74
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ Please use this Github project for contributing, either through an issue or a Pu
1212

1313
These pages aim to help Cucumber Scala developers understand the codebase.
1414

15-
- [Building](docs/building.md)
16-
- [Project structure](docs/project_structure.md)
15+
- [Build](docs/build.md)
1716
- [Scala implementation details](docs/scala_implementation.md)

docs/build.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Build
2+
3+
To compile and test the whole project you can run the following command:
4+
5+
```shell
6+
$ sbt clean compile test
7+
```
8+
9+
## Project structure
10+
11+
The project contains two functional subprojects:
12+
- `cucumber-scala`: contains the codebase of the Cucumber Scala implementation
13+
- `examples`: contains a sample project
14+
15+
Each of these subproject is also derived for each target Scala version. See below.
16+
17+
## Cross compilation
18+
19+
Cross compilation to multiple Scala versions is handled by the [sbt-projectmatrix](https://github.com/sbt/sbt-projectmatrix) plugin.
20+
21+
The target versions are defined in the `build.sbt` on each sub-project:
22+
```scala
23+
project
24+
...
25+
.jvmPlatform(scalaVersions = Seq(scala3, scala213, scala212))
26+
```
27+
28+
A sbt sub-project is generated for each targeted Scala version with the version as a suffix
29+
(with Scala 2.13 being the current default version):
30+
31+
```shell
32+
$ sbt projects
33+
...
34+
[info] cucumberScala
35+
[info] cucumberScala2_12
36+
[info] cucumberScala3
37+
[info] examples
38+
[info] examples2_12
39+
[info] examples3
40+
[info] * root
41+
```
42+
43+
### Sources
44+
45+
Sources should most of the time be compatible for all target Scala versions in order to ease maintenance.
46+
47+
However, if needed, it's possible to define different sources for each Scala version.
48+
49+
These version-specific sources should be put in a directory called `src/main/scala-<version>` and the `build.sbt`
50+
should declare them as additional sources directories like:
51+
```scala
52+
Compile / unmanagedSourceDirectories ++= {
53+
val sourceDir = (Compile / sourceDirectory).value
54+
CrossVersion.partialVersion(scalaVersion.value) match {
55+
case Some((2, n)) =>
56+
Seq(sourceDir / "scala-2")
57+
case Some((3, 0)) =>
58+
Seq(sourceDir / "scala-3")
59+
case _ =>
60+
Seq()
61+
}
62+
}
63+
```
64+
65+
The same can be done for tests.
66+
67+
## Language traits generation
68+
69+
The language traits (`io.cucumber.scala.EN` for instance) are generated automatically at compile time.
70+
71+
The `project` meta project defines a `I18nGenerator` object responsible for generating their content.
72+
73+
At compilation, this generated content is injected as source files thanks to a sbt source generator:
74+
```scala
75+
// Generate I18n traits
76+
Compile / sourceGenerators += Def.task {
77+
val file =
78+
(Compile / sourceManaged).value / "io/cucumber/scala" / "I18n.scala"
79+
IO.write(file, I18nGenerator.i18n)
80+
Seq(file)
81+
}.taskValue
82+
```

docs/building.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/project_structure.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)