Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ systems like Buck and Bazel.
9. [JVM targets](docs/JVM-TARGETS.md) — pure JVM platform plugin `tools.forma.jvm` (F-030)
10. [JVM sample application](docs/JVM-SAMPLE.md) — multi-module pure-JVM gold standard (`jvm-application/`, F-031)
11. [Bazel adapter design](docs/BAZEL-ADAPTER.md) — target types to rules, restriction graph to visibility (F-040 design)
12. [Bazel adapter spike](bazel-adapter/README.md) — generate/check BUILD from Forma model (F-041; JVM-first)

Configuration made easy:

Expand Down Expand Up @@ -208,6 +209,7 @@ Pure JVM target set (`tools.forma.jvm`, `JvmTargetRegistry`): **F-030** done (se
JVM sample application + `binary` composition root: **F-031** done ([`docs/JVM-SAMPLE.md`](docs/JVM-SAMPLE.md), `jvm-application/`).
JVM getting-started tutorial: **F-032** done ([`docs/JVM-GETTING-STARTED.md`](docs/JVM-GETTING-STARTED.md)).
Bazel adapter mapping design (targets ↔ rules, visibility ↔ deps): **F-040** done (see [`docs/BAZEL-ADAPTER.md`](docs/BAZEL-ADAPTER.md)).
Bazel adapter spike (generate/check BUILD from portable model, JVM matrix): **F-041** done ([`bazel-adapter/`](bazel-adapter/), spike results in BAZEL-ADAPTER.md).

Icons made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a>
from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a>
2 changes: 1 addition & 1 deletion TICKETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Update this file when picking or finishing work. Cron workers must pick the **hi
| ID | Status | Title | Notes |
|----|--------|-------|-------|
| F-040 | done | Design Bazel adapter mapping (targets ↔ rules, visibility ↔ deps) | `docs/BAZEL-ADAPTER.md` + cross-links; commit 45674c7 |
| F-041 | todo | Spike: generate or check Bazel BUILD from forma declarations | |
| F-041 | done | Spike: generate or check Bazel BUILD from forma declarations | `bazel-adapter/` generate+check via core RestrictionGraph; examples + tests green |
| F-042 | todo | Minimal Bazel sample using forma-core concepts | |

## Backlog (lower priority / historical GitHub)
Expand Down
43 changes: 43 additions & 0 deletions bazel-adapter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# bazel-adapter (F-041 spike)

JVM-first adapter that converts a portable `FormaProjectModel` (targets + declared edges) into Bazel `BUILD.bazel` fragments (or validates them) while preserving the forma-core `RestrictionGraph` discipline.

**Core invariant:** `impl` may never depend on another `impl`; composition happens only at `binary`. The adapter enforces this using `RestrictionGraph.isAllowed` from `tools.forma:core`.

## What it contains

- `tools.forma.bazel.model.*` — portable snapshot types (no Gradle APIs)
- `JvmBazelAdapter` implementing `FormaToBazel.generate()` + `check()`
- Hand-built fixture from `jvm-application/` (8 targets)
- Unit tests + committed example BUILD files under `examples/`

## Running

Requires JDK 17+ (Temurin recommended).

```bash
# From repo root
source scripts/env-mac.sh

cd bazel-adapter
./gradlew test
./gradlew runSample # prints generated BUILD text + check report
```

You do **not** need Bazel installed for the spike.

## Limitations (spike)

- Only JVM 6-type matrix (`jvm.api` ... `jvm.binary`)
- Project edges only (no external catalog GAV translation)
- Visibility is computed from declared consumers in the model + graph (hybrid; good enough)
- No full BUILD parser — check validates the *model* edges (and lightly inspects generated text)
- No `kt_jvm_test` emission yet (testDependencies carried in model but ignored for rule emission)
- No content rules (pure JVM has none)

## Golden / committed artifacts

- `examples/jvm-application-build/` — representative generated BUILD.bazel files
- Tests assert key labels, absence of illegal edges, round-trip cleanliness

See `docs/BAZEL-ADAPTER.md` for the full mapping design and F-041 acceptance criteria.
42 changes: 42 additions & 0 deletions bazel-adapter/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
kotlin("jvm")
}

// Co-version with forma; for spike we do not publish the adapter.
group = "tools.forma.experimental"
version = "0.1.3-spike"

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

kotlin {
jvmToolchain(17)
}

repositories {
mavenCentral()
}

dependencies {
// ONLY production dependency allowed per F-041 / BAZEL-ADAPTER design:
// adapter depends on core; core has ZERO Bazel / Gradle-Project / AGP knowledge.
implementation("tools.forma:core:0.1.3")

// Test only
testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}

// Convenience: allow running a small main to dump sample output if added later
tasks.register<JavaExec>("runSample") {
group = "application"
description = "Run a driver that prints generated BUILD for the jvm-application fixture"
mainClass.set("tools.forma.bazel.BazelAdapterSampleKt")
classpath = sourceSets["main"].runtimeClasspath
}
22 changes: 22 additions & 0 deletions bazel-adapter/examples/jvm-application-build/binary/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# GENERATED by JvmBazelAdapter (F-041) — do not edit by hand for the spike.
# gradlePath=:binary type=jvm.binary

kt_jvm_binary(
name = "binary",
srcs = glob(["src/main/kotlin/**/*.kt"]),
deps = [
"//common/library:library",
"//common/util:util",
"//feature/calculator/api:api",
"//feature/calculator/impl:impl",
"//feature/greeter/api:api",
"//feature/greeter/impl:impl",
],
visibility = [
"//visibility:public",
],
main_class = "tools.forma.jvm.sample.binary.MainKt",
tags = [
"forma:type=jvm.binary",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# GENERATED by JvmBazelAdapter (F-041) — do not edit by hand for the spike.
# gradlePath=:feature:greeter:api type=jvm.api

kt_jvm_library(
name = "api",
srcs = glob(["src/main/kotlin/**/*.kt"]),
visibility = [
"//binary:__pkg__",
"//feature/greeter/impl:__pkg__",
],
tags = [
"forma:type=jvm.api",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# GENERATED by JvmBazelAdapter (F-041) — do not edit by hand for the spike.
# gradlePath=:feature:greeter:impl type=jvm.impl

kt_jvm_library(
name = "impl",
srcs = glob(["src/main/kotlin/**/*.kt"]),
deps = [
"//common/library:library",
"//common/util:util",
"//feature/greeter/api:api",
],
visibility = [
"//binary:__pkg__",
],
tags = [
"forma:type=jvm.impl",
],
)
Binary file added bazel-adapter/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions bazel-adapter/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading