-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmod.dang
More file actions
97 lines (88 loc) · 3.38 KB
/
Copy pathmod.dang
File metadata and controls
97 lines (88 loc) · 3.38 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
"""
A Dagger module that uses the PHP SDK.
"""
type Mod {
"""
Workspace-root-relative path of this module root. This stable identity is
independent of the client's cwd.
"""
pub rootPath: String!
"""
The workspace this module belongs to.
"""
let ws: Workspace!
"""
Marker filename that skips generate when found at or above this module root.
"""
let skipGenerateFilename: String!
"""
Module root relative to the client's cwd.
"""
pub path: String! {
let cwd = ws.cwd.trimPrefix("/").trimSuffix("/")
if (rootPath == cwd) {
"."
} else if (cwd == "") {
rootPath
} else if (rootPath.trimPrefix(cwd + "/") != rootPath) {
rootPath.trimPrefix(cwd + "/")
} else if (rootPath == "." or cwd.trimPrefix(rootPath + "/") != cwd) {
let depth = if (rootPath == ".") { 0 } else { rootPath.split("/").length }
cwd.split("/").dropFirst(depth).map { segment => ".." }.join("/")
} else {
rootPath
}
}
"""
Whether this module or an ancestor contains the configured generate skip marker.
"""
pub skipGenerate: Boolean! {
ws.findUp(name: skipGenerateFilename, from: rootPath) != null
}
"""
Generate this module.
If the generate skip marker is present, the changeset is empty.
"""
pub generate: Changeset! {
if (skipGenerate) {
changeset
} else {
# rootPath is workspace-root-relative: Workspace.moduleSource resolves a
# relative path from ws.cwd and would prefix it a second time.
let ref = if (rootPath == ".") { "/" } else { "/" + rootPath }
# Stage the local dependency closure so this module's codegen sees
# up-to-date dependency bindings. The staged workspace is only an input:
# the engine diffs the generated context against the same base it
# generated from, so the dependencies' codegen does not ride along.
let stagedWs = ws.withChanges(ws.moduleSource(ref).generateLocalDependencies(ws))
atCwd(stagedWs.moduleSource(ref).generatedContextChangeset)
}
}
"""
Re-root a workspace-rooted changeset at the client's cwd.
The engine roots a generated context at the workspace, but a returned
changeset is applied relative to the caller's cwd, so without this every path
lands nested under the cwd a second time. `ModuleSource.generate` followed by
`Workspace.changes(from:)` is the native API for this, but that pair reports
a module's whole generated context as added rather than only what generation
changed — including engine-owned files the SDK must not touch — so the
rooting stays explicit here. Tracked by
https://github.com/dagger/dagger/issues/13947
"""
let atCwd(changes: Changeset!): Changeset! {
let cwd = ws.cwd.trimPrefix("/").trimSuffix("/")
if (cwd == "" or cwd == ".") {
changes
} else {
# A cwd-relative changeset cannot express paths outside the cwd — e.g. a
# module discovered above it — and re-rooting would silently drop them,
# leaving that module never regenerated. Fail loudly instead.
let outside = (changes.addedPaths + changes.modifiedPaths + changes.removedPaths)
.filter { path => path != cwd and path.hasPrefix(cwd + "/") == false }
if (outside.length > 0) {
raise "generated changes fall outside the current directory " + cwd + ": " + outside.join(", ")
}
changes.after.directory(cwd).changes(changes.before.directory(cwd))
}
}
}