Skip to content

Commit fb14696

Browse files
committed
make module discovery cwd-aware and resolve dagger-module.toml
Mirror the cwd-aware discovery change already landed in the Go, Python and TypeScript SDKs (dagger/dagger#13688): modules are discovered relative to the client's current directory rather than the whole workspace, and both the CLI 1.0 dagger-module.toml and the legacy dagger.json mark a module root. - Mod.path becomes rootPath (workspace-root-relative, the module's stable identity); a new cwd-relative Mod.path renders listings the way a shell user sees them. - JavaSdk.modules(ws) discovers managed modules through the polyfill's cwd-aware findConfigDirs, intersected with the engine-owned asSDK list, and generateAll now goes through it — so running from a subdirectory acts on the project you're in and the projects beneath it. - Point the polyfill dependency in dagger-module.toml (the effective module config) at github.com/dagger/polyfill@main, which provides findConfigDirs. - Wire the workspace dagger.toml for e2e (register java-sdk as the "java" SDK with fixtures) and add modulesCheck / modulesCwdCheck covering both config formats and cwd scoping. Signed-off-by: Tom Chauveau <tom@dagger.io>
1 parent 207600c commit fb14696

21 files changed

Lines changed: 255 additions & 146 deletions

File tree

.dagger/modules/e2e/dagger-module.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "e2e"
2-
engineVersion = "latest"
2+
engineVersion = "v1.0.0-0"
33

44
[runtime]
55
source = "dang"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "deps-app",
3+
"engineVersion": "latest",
4+
"sdk": {
5+
"source": "java"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "generate-app",
3+
"engineVersion": "latest",
4+
"sdk": {
5+
"source": "java"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "lookup-app",
3+
"engineVersion": "latest",
4+
"sdk": {
5+
"source": "java"
6+
}
7+
}

.dagger/modules/e2e/fixtures/lookup/app/nested/.keep

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "not-java",
3+
"engineVersion": "latest",
4+
"sdk": {
5+
"source": "go"
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name = "managed-toml-app"
2+
engineVersion = "v1.0.0-beta.7"
3+
4+
[runtime]
5+
source = "java"

.dagger/modules/e2e/fixtures/skip/.dagger-java-sdk-skip-generate

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "skip-app",
3+
"engineVersion": "latest",
4+
"sdk": {
5+
"source": "java"
6+
}
7+
}

.dagger/modules/e2e/main.dang

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ End-to-end checks for the Java SDK helper module.
44
type E2e {
55
let outputRoot: String! = ".dagger/modules/e2e/out"
66

7+
let fixtureRoot: String! = ".dagger/modules/e2e/fixtures"
8+
let generateModulePath: String! = fixtureRoot + "/generate/app"
9+
let lookupModulePath: String! = fixtureRoot + "/lookup/app"
10+
let lookupNestedPath: String! = lookupModulePath + "/nested"
11+
let depsModulePath: String! = fixtureRoot + "/deps/app"
12+
let skipModulePath: String! = fixtureRoot + "/skip/app"
13+
# A CLI 1.0 managed module: configured by dagger-module.toml, not dagger.json.
14+
let managedTomlModulePath: String! = fixtureRoot + "/managed-toml/app"
15+
# A module using a different SDK; this SDK must never manage it.
16+
let nonJavaModulePath: String! = fixtureRoot + "/lookup/not-java"
17+
718
"""Fail the current check when a condition is false."""
819
let assert(condition: Boolean!, message: String!): Void {
920
if (condition == false) { raise message }
@@ -81,4 +92,72 @@ type E2e {
8192

8293
null
8394
}
95+
96+
"""
97+
From the workspace root the whole workspace is in scope, so modules() should
98+
return every Java SDK module this workspace manages — whether it is configured
99+
by the legacy dagger.json or the CLI 1.0 dagger-module.toml — and nothing that
100+
isn't managed by this SDK (e.g. a sibling module using another SDK).
101+
"""
102+
pub modulesCheck(ws: Workspace!): Void @check {
103+
let pathRecords = javaSdk.modules(ws).{{rootPath}}
104+
105+
assert(pathRecords.filter { r => r.rootPath == lookupModulePath }.length > 0, "lookup Java module should be listed")
106+
assert(pathRecords.filter { r => r.rootPath == skipModulePath }.length > 0, "skip-marked Java module should still be listed (skip only affects generate)")
107+
assert(pathRecords.filter { r => r.rootPath == generateModulePath }.length > 0, "generate Java module should be listed")
108+
assert(pathRecords.filter { r => r.rootPath == depsModulePath }.length > 0, "deps Java module should be listed")
109+
assert(pathRecords.filter { r => r.rootPath == managedTomlModulePath }.length > 0, "a dagger-module.toml (CLI 1.0) managed module should be listed")
110+
assert(pathRecords.filter { r => r.rootPath == nonJavaModulePath }.length == 0, "a module not managed by this SDK should be excluded from modules listing")
111+
112+
null
113+
}
114+
115+
"""
116+
Discovery is anchored at the client's cwd, not the workspace root. Re-anchoring
117+
the workspace to a subdirectory scopes modules() to the managed modules in that
118+
cone (walk-down) plus the nearest enclosing one (find-up), and excludes managed
119+
modules that live outside it.
120+
"""
121+
pub modulesCwdCheck(ws: Workspace!): Void @check {
122+
# A stable snapshot of the workspace, re-anchorable at any cwd. Keep every
123+
# module config (both dagger.json and dagger-module.toml, for discovery) and
124+
# the nested .keep so lookup/app/nested survives the include filter and can
125+
# serve as a config-less subdirectory.
126+
let root = ws.directory("/", include: ["**/dagger.json", "**/dagger-module.toml", "**/.keep"])
127+
128+
# Walk-down: from fixtures/generate only generate/app is in the cone; the
129+
# sibling managed modules live outside it and must be excluded. Its
130+
# cwd-relative path is "app" — a directory beneath the cwd.
131+
let fromGenerate = javaSdk.modules(root.asWorkspace(cwd: fixtureRoot + "/generate"))
132+
let fromGenerateRoots = fromGenerate.{{rootPath}}
133+
assert(fromGenerateRoots.filter { r => r.rootPath == generateModulePath }.length > 0, "cwd=generate: the managed module in the cone should be discovered")
134+
assert(fromGenerateRoots.filter { r => r.rootPath == lookupModulePath }.length == 0, "cwd=generate: lookup/app is outside the cone and must be excluded")
135+
assert(fromGenerateRoots.filter { r => r.rootPath == depsModulePath }.length == 0, "cwd=generate: deps/app is outside the cone and must be excluded")
136+
assert(fromGenerateRoots.filter { r => r.rootPath == skipModulePath }.length == 0, "cwd=generate: skip/app is outside the cone and must be excluded")
137+
assert(fromGenerateRoots.length == 1, "cwd=generate: exactly one managed module is in the cone")
138+
assert(fromGenerate.{{path}}.filter { r => r.path == "app" }.length > 0, "cwd=generate: the discovered module's path should be cwd-relative (app)")
139+
140+
# Find-up: from inside lookup/app (a nested subdir with no config of its own)
141+
# the enclosing managed module is discovered; siblings are not. Its
142+
# cwd-relative path is ".." — an ancestor of the cwd.
143+
let fromNested = javaSdk.modules(root.asWorkspace(cwd: lookupNestedPath))
144+
let fromNestedRoots = fromNested.{{rootPath}}
145+
assert(fromNestedRoots.filter { r => r.rootPath == lookupModulePath }.length > 0, "cwd=lookup/app/nested: find-up should discover the enclosing lookup/app")
146+
assert(fromNestedRoots.filter { r => r.rootPath == generateModulePath }.length == 0, "cwd=lookup/app/nested: generate/app is outside the cone")
147+
assert(fromNestedRoots.length == 1, "cwd=lookup/app/nested: only the enclosing module should be discovered")
148+
assert(fromNested.{{path}}.filter { r => r.path == ".." }.length > 0, "cwd=lookup/app/nested: the enclosing module's path should be cwd-relative (..)")
149+
150+
# Root cwd: the whole workspace is in scope, so every managed module — and
151+
# only the managed ones — is discovered, whether marked by dagger.json or
152+
# dagger-module.toml.
153+
let fromRoot = javaSdk.modules(root.asWorkspace(cwd: "/")).{{rootPath}}
154+
assert(fromRoot.filter { r => r.rootPath == generateModulePath }.length > 0, "cwd=/: generate/app should be listed")
155+
assert(fromRoot.filter { r => r.rootPath == lookupModulePath }.length > 0, "cwd=/: lookup/app should be listed")
156+
assert(fromRoot.filter { r => r.rootPath == depsModulePath }.length > 0, "cwd=/: deps/app should be listed")
157+
assert(fromRoot.filter { r => r.rootPath == skipModulePath }.length > 0, "cwd=/: skip/app should be listed")
158+
assert(fromRoot.filter { r => r.rootPath == managedTomlModulePath }.length > 0, "cwd=/: the dagger-module.toml managed module should be listed")
159+
assert(fromRoot.length == 5, "cwd=/: exactly the five managed modules should be listed")
160+
161+
null
162+
}
84163
}

0 commit comments

Comments
 (0)