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
10 changes: 5 additions & 5 deletions .dagger/modules/e2e/fixtures/dagger.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ check.skip = ["*"]
name = "java"

[[modules.java-sdk.as-sdk.modules]]
path = ".dagger/modules/e2e/fixtures/generate/app"
path = "generate/app"

[[modules.java-sdk.as-sdk.modules]]
path = ".dagger/modules/e2e/fixtures/lookup/app"
path = "lookup/app"

[[modules.java-sdk.as-sdk.modules]]
path = ".dagger/modules/e2e/fixtures/deps/app"
path = "deps/app"

[[modules.java-sdk.as-sdk.modules]]
path = ".dagger/modules/e2e/fixtures/skip/app"
path = "skip/app"

[[modules.java-sdk.as-sdk.modules]]
path = ".dagger/modules/e2e/fixtures/managed-toml/app"
path = "managed-toml/app"
9 changes: 4 additions & 5 deletions .dagger/modules/e2e/main.dang
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,10 @@ type E2e {
modules that live outside it.
"""
modulesCwdCheck(ws: Workspace!): Void @check {
# A stable snapshot of the workspace, re-anchorable at any cwd. Snapshot the
# whole workspace (not just config files) so the re-anchored workspace keeps
# its dagger.toml — modules() reads the managed-module list from it via
# ws.sdk — alongside every module config (dagger.json and dagger-module.toml,
# for discovery) and lookup/app/nested (a config-less subdirectory).
# A stable snapshot of the workspace, re-anchorable at any cwd. It has to
# carry the fixture dagger.toml, which is where currentModule.asSDK reads the
# managed-module list from, and lookup/app/nested, the config-less
# subdirectory the find-up case is anchored in.
let root = testWS(ws).directory("/")

# Walk-down: from fixtures/generate only generate/app is in the cone; the
Expand Down
7 changes: 1 addition & 6 deletions dagger-module.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name = "java-sdk"
engineVersion = "v1.0.0-0"
engineVersion = "v1.0.0-beta.10"

[runtime]
source = "dang"

[[dependencies]]
name = "polyfill"
source = "github.com/dagger/polyfill@main"
pin = "e90bbfc4843258a877a3a95b8db1571e7981e65f"
11 changes: 2 additions & 9 deletions dagger.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{
"name": "java-sdk",
"engineVersion": "latest",
"engineVersion": "v1.0.0-beta.10",
"sdk": {
"source": "dang"
},
"dependencies": [
{
"name": "polyfill",
"source": "github.com/dagger/polyfill@main",
"pin": "e90bbfc4843258a877a3a95b8db1571e7981e65f"
}
]
}
}
7 changes: 3 additions & 4 deletions dagger.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[["version","1"]]
["","git.head",["https://github.com/dagger/dang-sdk"],"c724eec4270870aae489daa9f3cb8cbacfb44680","float"]
["","git.head",["https://github.com/dagger/sdk-sdk"],"e1747f4b6221fa24da080701e027243e0cc5fa33","float"]
["","git.ref",["https://github.com/dagger/polyfill","main"],"ec3ea84a2351b4beb06ecece951f2e5ef66509ff","float"]
[["version","2"]]
["","git.ref",["https://github.com/dagger/dang-sdk","HEAD"],{"ref":"refs/heads/main","sha":"c724eec4270870aae489daa9f3cb8cbacfb44680"}]
["","git.ref",["https://github.com/dagger/sdk-sdk","HEAD"],{"ref":"refs/heads/main","sha":"00bb06748bcf22d724ed467f2298d31f1fb49be0"}]
79 changes: 17 additions & 62 deletions main.dang
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ type JavaSdk {
"""
skipGenerateFilename: String! = ".dagger-java-sdk-skip-generate"

"""
Config filenames that mark a Dagger module root: the CLI 1.0
`dagger-module.toml` (workspace-managed modules) and the legacy `dagger.json`.
A managed module is discovered by whichever it uses.
"""
let moduleConfigFilenames: [String!]! = ["dagger-module.toml", "dagger.json"]

"""
Commit the compiled Dagger Java SDK as a jar into each generated module so its
runtime build compiles only the module's own code against the jar instead of
Expand Down Expand Up @@ -56,14 +49,12 @@ type JavaSdk {
rawPath.trimSuffix("/")
}

let before = if (modPath == ".") {
ws.directory("/", include: ["**"])
} else {
ws.directory("/", include: [modPath + "/**"])
}

let selectedTemplate = if (template == "") { "default" } else { template }
before.withDirectory(modPath, renderedTemplate(name, selectedTemplate)).changes(before)
# `path` is workspace-root-relative, so anchor it: relative workspace paths
# resolve from ws.cwd and would be prefixed again when initModule is called
# directly from a subdirectory instead of being driven by the engine.
let target = if (modPath == ".") { "/" } else { "/" + modPath }
ws.withNewDirectory(target, renderedTemplate(name, selectedTemplate)).changes(ws)
}

"""
Expand Down Expand Up @@ -98,62 +89,26 @@ type JavaSdk {
Return every Java SDK module this workspace manages that is visible from the
client's current location.

Discovery is anchored at the client's cwd (never the workspace root): the
nearest enclosing module plus every module at or below the cwd, intersected
with the SDK's engine-owned list of managed modules
(currentModule.asSDK.modules). So running from a subdirectory acts on the
project you're in — and the projects beneath it — not the whole workspace.

Discovery is the polyfill's cwd-aware findConfigDirs (dagger/dagger#13688);
this maps its cwd-relative results to workspace-root-relative paths and keeps
the ones this SDK manages, whether they use dagger-module.toml or dagger.json.
The engine owns both the list and the cwd policy: currentModule.asSDK returns
the modules registered to this SDK that sit at or below the client's cwd, plus
the nearest enclosing one when the cwd is not itself a module. So running from
a subdirectory acts on the project you're in — and the projects beneath it —
not the whole workspace. Paths come back relative to the workspace root, the
currency Mod.rootPath uses.
"""
modules(ws: Workspace!): [Mod!]! {
let managed = ws.sdk(name: currentModule.name).modules.{{source}}
let cwd = normalizePath(ws.cwd)
polyfill
.workspace(ws)
.findConfigDirs(moduleConfigFilenames, exclude: ["**/target/**"])
.map { dir => moduleRelPath(cwd, dir) }
.uniq
.filter { path => managed.filter { m => normalizePath(m.source) == path }.length > 0 }
.map { path => Mod(
rootPath: path,
currentModule
.asSDK(workspace: ws)
.modules
.{{path}}
.map { module => Mod(
rootPath: module.path,
ws: ws,
skipGenerateFilename: skipGenerateFilename,
vendorSdkJar: vendorSdkJar,
) }
}

"""
Normalize a workspace path: strip a leading "./" or "/" and any trailing "/",
and map the empty/root path to ".".
"""
let normalizePath(path: String!): String! {
let normalized = path.trimPrefix("./").trimPrefix("/").trimSuffix("/")
if (normalized == "") { "." } else { normalized }
}

"""
Resolve a findConfigDirs result — a cwd-relative path, at or below the cwd
("." , "sub/dir") or a strict ancestor (".." , "../..") — against the cwd into a
workspace-root-relative path, the format both managed module sources and
Mod.rootPath use.
"""
let moduleRelPath(cwd: String!, dir: String!): String! {
let base = if (cwd == "" or cwd == ".") { [] } else { cwd.split("/") }
let segs = dir.split("/").reduce(base) { acc, seg =>
if (seg == "..") {
acc.dropLast(1)
} else if (seg == "." or seg == "") {
acc
} else {
acc + [seg]
}
}
if (segs.length == 0) { "." } else { segs.join("/") }
}

"""
Generate every managed Java SDK module visible from the client's current
location (runs at `dagger generate`). Discovery goes through modules(ws), so
Expand Down
79 changes: 17 additions & 62 deletions main.dang.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ type JavaSdk {
"""
skipGenerateFilename: String! = ".dagger-java-sdk-skip-generate"

"""
Config filenames that mark a Dagger module root: the CLI 1.0
`dagger-module.toml` (workspace-managed modules) and the legacy `dagger.json`.
A managed module is discovered by whichever it uses.
"""
let moduleConfigFilenames: [String!]! = ["dagger-module.toml", "dagger.json"]

"""
Commit the compiled Dagger Java SDK as a jar into each generated module so its
runtime build compiles only the module's own code against the jar instead of
Expand Down Expand Up @@ -56,14 +49,12 @@ type JavaSdk {
rawPath.trimSuffix("/")
}

let before = if (modPath == ".") {
ws.directory("/", include: ["**"])
} else {
ws.directory("/", include: [modPath + "/**"])
}

let selectedTemplate = if (template == "") { "default" } else { template }
before.withDirectory(modPath, renderedTemplate(name, selectedTemplate)).changes(before)
# `path` is workspace-root-relative, so anchor it: relative workspace paths
# resolve from ws.cwd and would be prefixed again when initModule is called
# directly from a subdirectory instead of being driven by the engine.
let target = if (modPath == ".") { "/" } else { "/" + modPath }
ws.withNewDirectory(target, renderedTemplate(name, selectedTemplate)).changes(ws)
}

"""
Expand Down Expand Up @@ -98,62 +89,26 @@ type JavaSdk {
Return every Java SDK module this workspace manages that is visible from the
client's current location.

Discovery is anchored at the client's cwd (never the workspace root): the
nearest enclosing module plus every module at or below the cwd, intersected
with the SDK's engine-owned list of managed modules
(currentModule.asSDK.modules). So running from a subdirectory acts on the
project you're in — and the projects beneath it — not the whole workspace.

Discovery is the polyfill's cwd-aware findConfigDirs (dagger/dagger#13688);
this maps its cwd-relative results to workspace-root-relative paths and keeps
the ones this SDK manages, whether they use dagger-module.toml or dagger.json.
The engine owns both the list and the cwd policy: currentModule.asSDK returns
the modules registered to this SDK that sit at or below the client's cwd, plus
the nearest enclosing one when the cwd is not itself a module. So running from
a subdirectory acts on the project you're in — and the projects beneath it —
not the whole workspace. Paths come back relative to the workspace root, the
currency Mod.rootPath uses.
"""
modules(ws: Workspace!): [Mod!]! {
let managed = ws.sdk(name: currentModule.name).modules.{{source}}
let cwd = normalizePath(ws.cwd)
polyfill
.workspace(ws)
.findConfigDirs(moduleConfigFilenames, exclude: ["**/target/**"])
.map { dir => moduleRelPath(cwd, dir) }
.uniq
.filter { path => managed.filter { m => normalizePath(m.source) == path }.length > 0 }
.map { path => Mod(
rootPath: path,
currentModule
.asSDK(workspace: ws)
.modules
.{{path}}
.map { module => Mod(
rootPath: module.path,
ws: ws,
skipGenerateFilename: skipGenerateFilename,
vendorSdkJar: vendorSdkJar,
) }
}

"""
Normalize a workspace path: strip a leading "./" or "/" and any trailing "/",
and map the empty/root path to ".".
"""
let normalizePath(path: String!): String! {
let normalized = path.trimPrefix("./").trimPrefix("/").trimSuffix("/")
if (normalized == "") { "." } else { normalized }
}

"""
Resolve a findConfigDirs result — a cwd-relative path, at or below the cwd
("." , "sub/dir") or a strict ancestor (".." , "../..") — against the cwd into a
workspace-root-relative path, the format both managed module sources and
Mod.rootPath use.
"""
let moduleRelPath(cwd: String!, dir: String!): String! {
let base = if (cwd == "" or cwd == ".") { [] } else { cwd.split("/") }
let segs = dir.split("/").reduce(base) { acc, seg =>
if (seg == "..") {
acc.dropLast(1)
} else if (seg == "." or seg == "") {
acc
} else {
acc + [seg]
}
}
if (segs.length == 0) { "." } else { segs.join("/") }
}

"""
Generate every managed Java SDK module visible from the client's current
location (runs at `dagger generate`). Discovery goes through modules(ws), so
Expand Down
Loading