-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.dang.tmpl
More file actions
125 lines (116 loc) · 4.67 KB
/
Copy pathmain.dang.tmpl
File metadata and controls
125 lines (116 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""
Manage Dagger modules that use the Java SDK (new self-contained code organisation).
Modules created by `init` use the self-contained layout: the Java SDK is vendored
as source and code is generated into the module (see `generate`), and the module
runtime is this repository's build/package-only runtime
(`github.com/dagger/java-sdk/runtime`). Because the generated files are committed,
the runtime skips codegen at module load and just builds and packages the
committed sources.
"""
type JavaSdk {
"""
Runtime source written into the dagger-module.toml of new Java modules.
"""
targetRuntime: String! { "github.com/dagger/java-sdk/runtime" }
"""
Marker filename that skips generate when found at or above a Java SDK module root.
"""
skipGenerateFilename: String! = ".dagger-java-sdk-skip-generate"
"""
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
recompiling the vendored SDK sources. The sources stay checked in for IDE use.
Opt-in (set `settings.vendorSdkJar = true` under `[modules.java-sdk]` in the
workspace dagger.toml) because it adds a committed binary artifact.
"""
vendorSdkJar: Boolean! = false
"""
Initialize Java-owned files for a new Dagger module.
"""
initModule(
ws: Workspace!,
name: String!,
path: String!,
"""
Template to use to init the module: <placeholder-list-templates>
"""
template: String! = "default",
): Changeset! {
let rawPath = path.trimPrefix("./").trimPrefix("/")
let modPath = if (rawPath == "" or rawPath == ".") {
"."
} else if (rawPath == ".." or rawPath.trimPrefix("../") != rawPath) {
raise "path escapes workspace: " + rawPath
} else {
rawPath.trimSuffix("/")
}
let selectedTemplate = if (template == "") { "default" } else { template }
# `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)
}
"""
Render a Java init template, substituting the requested module name.
"""
let renderedTemplate(name: String!, template: String!): Directory! {
container
.from("golang:1.25-alpine")
.withoutEntrypoint
.withMountedCache("/go/pkg/mod", cacheVolume("go-mod"))
.withMountedCache("/root/.cache/go-build", cacheVolume("go-build"))
.withDirectory(
"/helper",
currentModule.source.directory("helpers/render-java-template"),
)
# target/ is gitignored, so it is absent from a clean checkout but present
# in a developer's — and the renderer substitutes the module name into
# every file it walks, including .class bytes, producing a corrupt class
# that then breaks the scaffolded module's build.
.withDirectory(
"/template",
currentModule.source.directory("templates/" + template),
exclude: ["**/target/**"],
)
.withWorkdir("/helper")
.withExec(["go", "build", "-o", "/usr/local/bin/render-java-template", "."])
.withExec(["render-java-template", name, "/template", "/rendered"])
.directory("/rendered")
}
"""
Return every Java SDK module this workspace manages that is visible from the
client's current location.
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!]! {
currentModule
.asSDK(workspace: ws)
.modules
.{{path}}
.map { module => Mod(
rootPath: module.path,
ws: ws,
skipGenerateFilename: skipGenerateFilename,
vendorSdkJar: vendorSdkJar,
) }
}
"""
Generate every managed Java SDK module visible from the client's current
location (runs at `dagger generate`). Discovery goes through modules(ws), so
running from a subdirectory generates only the project you're in and the
projects beneath it.
"""
generateAll(ws: Workspace!): Changeset! @generate {
changeset.withChangesets(
modules(ws)
.filter { mod => mod.skipGenerate(ws) == false }
.map { mod => mod.generate(ws) },
)
}
}