Skip to content
Open
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
6 changes: 4 additions & 2 deletions .dagger/modules/e2e/entrypoint.dang
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ type EntrypointChecks {

"""
A failing function's error reaches the caller with its text, not as the exit
code of the process that ran it.
code of the process that ran it. An engine that gives the process an error
file reports the error as the function's own; an older one prefixes it with
"call module entrypoint: ".
"""
pub errorCheck(ws: Workspace!): Void @check {
let failed = cli(playground(app(ws)), ["-m", "app", "call", "fail"])
let said = failed.stdout + failed.stderr
assert(
failed.exitCode != 0 and said.contains("call module entrypoint: entry-app failed: boom"),
failed.exitCode != 0 and said.contains("entry-app failed: boom"),
"the function's error lost its text:\n" + said,
)
null
Expand Down
66 changes: 44 additions & 22 deletions entrypoint/build.dang.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,33 @@ github.com/dagger/java-sdk/runtime does, and refuses a module whose generated
files are stale.
"""
type JavaModuleBuild {
"""
The platform the jar is built on: the engine's when unset. The jar runs on
any, but its build is cached per platform.
"""
pub platform: Platform

"""
Maven build output, never an input: a class file an IDE left there is newer
than its source, so the compiler skips the source and packages the stale class.
"""
let buildOutputExclude: [String!]! = ["**/target/**"]

"""
The jar of the SDK that vendorSdkJar commits into the module. It has no
annotation processor, so a module that has it is packaged with its committed
entrypoint and compared with nothing.
"""
let vendoredSdkJar: String! = "sdk/repo/io/dagger/dagger-java-sdk/0.21.4/dagger-java-sdk-0.21.4.jar"

"""
The module's shaded jar, packaged with the entrypoint the annotation processor
generates from the module's code at call time. It is refused when a generated
file changed since dagger generate wrote it, or when that entrypoint differs
from the committed one.
"""
pub jar: File! {
let module = withoutSVE(container.from("<maven-image>"))
let module = withoutSVE(container(platform: platform ?? defaultPlatform).from("<maven-image>"))
.withoutEntrypoint
.withMountedCache("/root/.m2", cacheVolume("sdk-java-maven-m2"), sharing: CacheSharingMode.LOCKED)
.withDirectory("/src", currentModule.contextDirectory, exclude: buildOutputExclude)
Expand All @@ -28,20 +41,39 @@ type JavaModuleBuild {
module.withExec(["sh", "-c", editedScript]).stdout,
"these generated files changed since dagger generate wrote them",
)
let built = module
let named = module
.withEnvVariable("_DAGGER_JAVA_SDK_MODULE_NAME", "<module-name>")
.withEnvVariable("_DAGGER_JAVA_SDK_CLIENT_VERSION", "<client-version>")
.withExec(["sh", "-c", buildScript])
refuseStale(
built.file("/tmp/stale").contents,
"the module's code no longer generates these committed files",
)
let vendored = currentModule.contextDirectory.directory(currentModule.sourceSubpath).exists(vendoredSdkJar)
let built = if (vendored) {
named.withExec(["mvn", "package"] + mavenFlags)
} else {
# The processor writes the entrypoint again, under target/, and the
# committed one is compared with it.
let packaged = named
.withoutDirectory("src/generated/java")
.withExec(["mvn", "package", "-Ddagger.proc=full"] + mavenFlags)
refuseStale(
packaged
.withDirectory("/tmp/committed/java", module.directory("src/generated/java"))
.withExec(["sh", "-c", staleScript])
.stdout,
"the module's code no longer generates these committed files",
)
packaged
}
# The shade plugin leaves the unshaded artifact beside the shaded one.
built
.withExec(["sh", "-c", "set -e; jar=$(ls -1 target/*.jar 2>/dev/null | grep -v '/original-' | head -n1); test -n \"$jar\" || { echo \"no packaged jar found in $(pwd)/target\" >&2; exit 1; }; cp \"$jar\" /tmp/module.jar"])
.file("/tmp/module.jar")
}

"""
Maven's flags for the package: quiet, so a failed build logs its errors, such
as the compiler's, and little else.
"""
let mavenFlags: [String!]! = ["-DskipTests", "--quiet", "--threads", "1C", "--no-transfer-progress"]

"""
Print each file of src/generated/sha256sums whose contents changed or that is
gone, or the list itself when it is gone.
Expand All @@ -54,23 +86,13 @@ type JavaModuleBuild {
}

"""
Package the module with its entrypoint generated again, and list in
/tmp/stale each committed entrypoint file that differs from the fresh one.
The jar vendored by vendorSdkJar has no annotation processor, so that module
is packaged with its committed entrypoint and compared with nothing.
Print each committed entrypoint file that differs from the one the processor
generated again.
"""
let buildScript: String! {
let staleScript: String! {
[
"set -e",
"touch /tmp/stale",
"if [ -f sdk/repo/io/dagger/dagger-java-sdk/0.21.4/dagger-java-sdk-0.21.4.jar ]; then",
" exec mvn package -DskipTests --threads 1C --no-transfer-progress",
"fi",
"mkdir -p /tmp/committed",
"mv src/generated/java /tmp/committed/java",
"mvn package -DskipTests -Ddagger.proc=full --threads 1C --no-transfer-progress",
"diff -r /tmp/committed/java target/generated-sources/annotations >/dev/null || echo src/generated/java >> /tmp/stale",
"cmp -s src/generated/dang/entrypoint/main.dang target/classes/dagger/entrypoint/main.dang || echo src/generated/dang/entrypoint/main.dang >> /tmp/stale",
"diff -r /tmp/committed/java target/generated-sources/annotations >/dev/null || echo src/generated/java",
"cmp -s src/generated/dang/entrypoint/main.dang target/classes/dagger/entrypoint/main.dang || echo src/generated/dang/entrypoint/main.dang",
].join("\n")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ static String render(ModuleInfo moduleInfo, String moduleName, String clientVers
private static final String CALL =
String.join(
"\n",
" # The jar every call runs: the engine builds it ahead of a call, as the",
" # module's build.",
" pub prebuild(platform: Platform): File! {",
" JavaModuleBuild(platform: platform).jar",
" }",
"",
" pub call(",
" receiverType: String!,",
" receiverValue: JSON,",
Expand Down Expand Up @@ -98,10 +104,19 @@ static String render(ModuleInfo moduleInfo, String moduleName, String clientVers
" (result :: JSON!)",
" }",
"",
" # The exec error carries the end of the dispatcher's stderr, whose last marker",
" # line holds the function's error. Without one, the exec failed before the",
" # function returned, and its own error is raised again.",
" # An engine that gives the dispatcher a file for the function's error puts",
" # the error the dispatcher wrote there in its exec's error, and fails the",
" # call with it, values and all: the exec's error is raised as it is.",
" # Otherwise, as with an older engine or a file the dispatcher couldn't",
" # write, the exec error carries the end of the dispatcher's stderr, where",
" # its last marker line holds the function's error; without one, the exec",
" # failed before the function returned, and its own error is raised again.",
" let raiseFunctionError(err: GraphQLError!): String! {",
" let reported = ((JSON.decode(err.extensions) :: {{functionError: {{message: String,"
+ " id: String}}}}).functionError != null) rescue false",
" if (reported) {",
" raise err",
" }",
" let marker = " + Dang.quote(FUNCTION_ERROR_MARKER),
" let stderr = ((JSON.decode(err.extensions) :: {{stderr: String}}).stderr ?? \"\")"
+ " rescue \"\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,34 @@ void aFailedCallRaisesTheTextAfterTheLastErrorMarker() {
.contains("lines.takeLast(1)");
}

/** The engine fails the call with the error the dispatcher reported in its error file. */
@Test
void aFailedCallWhoseErrorTheEngineReadRaisesItAsItIs() {
assertThat(DangEntrypointRenderer.render(module(), "demo", CLIENT_VERSION))
.contains(
String.join(
"\n",
" let reported = ((JSON.decode(err.extensions) :: {{functionError: {{message:"
+ " String, id: String}}}}).functionError != null) rescue false",
" if (reported) {",
" raise err",
" }",
" let marker = "));
}

/** The engine builds what prebuild returns before a call, which builds on the same jar. */
@Test
void prebuildIsTheJarEveryCallRuns() {
assertThat(DangEntrypointRenderer.render(module(), "demo", CLIENT_VERSION))
.contains(
String.join(
"\n",
" pub prebuild(platform: Platform): File! {",
" JavaModuleBuild(platform: platform).jar",
" }"))
.contains(" let build = JavaModuleBuild()\n");
}

@Test
void descriptionsAreEscapedSoTheOutputStaysParseable() {
ObjectInfo object =
Expand Down
Loading