-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.dang
More file actions
87 lines (80 loc) · 3.14 KB
/
Copy pathmain.dang
File metadata and controls
87 lines (80 loc) · 3.14 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
"""
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.
"""
pub targetRuntime: String! { "github.com/dagger/java-sdk/runtime" }
"""
Marker filename that skips generate when found at or above a Java SDK module root.
"""
pub 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.
"""
pub vendorSdkJar: Boolean! = false
"""
Initialize Java-owned files for a new Dagger module.
"""
pub initModule(
ws: Workspace!,
name: String!,
path: String!,
): 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 before = if (modPath == ".") {
ws.directory("/", include: ["**"])
} else {
ws.directory("/", include: [modPath + "/**"])
}
before.withDirectory(modPath, renderedTemplate(name, "default")).changes(before)
}
"""
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"),
)
.withDirectory("/template", currentModule.source.directory("templates/" + template))
.withWorkdir("/helper")
.withExec(["go", "build", "-o", "/usr/local/bin/render-java-template", "."])
.withExec(["render-java-template", name, "/template", "/rendered"])
.directory("/rendered")
}
"""
Generate all discovered new-style Java SDK modules (runs at `dagger generate`).
"""
pub generateAll(ws: Workspace!): Changeset! @generate {
changeset.withChangesets(
currentModule.asSDK.modules.{{path}}
.map { m => Mod(path: m.path, ws: ws, skipGenerateFilename: skipGenerateFilename, vendorSdkJar: vendorSdkJar) }
.filter { mod => mod.skipGenerate(ws) == false }
.map { mod => mod.generate(ws) },
)
}
}