Fix pkl project package with multiple projects (#1981)

This commit is contained in:
Islon Scherer authored and Jen Basch committed 2026-11-17 11:07:17 -08:00
1 parent 83e47694ef
commit c3d555d49c
8 files changed
+110 -42

No files matched your search

+8 -6
View File
@@ -87,8 +87,9 @@ tasks.jar {
tasks.javadoc { enabled = false }
// has its own dedicated task; see `testProfilerOutput` and `testNativeProfilerOutput` below
tasks.test { exclude("**/SubprocessProfilerOutputTest.class") }
// subprocess tests have their own dedicated tasks; see `testProfilerOutput` and
// `testNativeProfilerOutput` below
tasks.test { exclude("**/Subprocess*Test.class") }
tasks.shadowJar {
archiveFileName.set("jpkl")
@@ -112,8 +113,9 @@ val testJavaExecutable =
// executable;
// to verify that, we don't want to include them here)
(configurations.testRuntimeClasspath.get() - configurations.runtimeClasspath.get())
// has its own dedicated task; see `testProfilerOutput` and `testNativeProfilerOutput` below
exclude("**/SubprocessProfilerOutputTest.class")
// subprocess tests have their own dedicated tasks; see `testProfilerOutput` and
// `testNativeProfilerOutput` below
exclude("**/Subprocess*Test.class")
}
// Setup `testJavaExecutable` tasks for multi-JDK testing.
@@ -223,7 +225,7 @@ val testProfilerOutput =
dependsOn(tasks.javaExecutable)
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath
include("**/SubprocessProfilerOutputTest.class")
include("**/Subprocess*Test.class")
systemProperty(
"org.pkl.cli.testJar",
tasks.javaExecutable.get().outputs.files.singleFile.absolutePath,
@@ -236,7 +238,7 @@ val testNativeProfilerOutput =
dependsOn(tasks.assembleNative)
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath
include("**/SubprocessProfilerOutputTest.class")
include("**/Subprocess*Test.class")
systemProperty(
"org.pkl.cli.testExecutable",
tasks.assembleNative.get().outputs.files.singleFile.absolutePath,
@@ -21,7 +21,6 @@ import com.github.ajalt.clikt.core.*
import com.github.ajalt.clikt.parameters.arguments.*
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.int
import com.oracle.truffle.api.TruffleOptions
import java.io.OutputStream
import java.net.URI
import java.nio.file.Path
@@ -42,7 +41,6 @@ import org.pkl.core.ModuleSource.uri
import org.pkl.core.PklBugException
import org.pkl.core.PklException
import org.pkl.core.ProfilerOptions
import org.pkl.core.runtime.VmUtils
import org.pkl.core.util.IoUtils
class CliCommandRunner
@@ -63,9 +61,6 @@ constructor(
} finally {
Closeables.closeQuietly(builder.moduleKeyFactories)
Closeables.closeQuietly(builder.resourceReaders)
if (TruffleOptions.AOT) {
VmUtils.closeEngine()
}
}
}
@@ -15,7 +15,6 @@
*/
package org.pkl.cli
import com.oracle.truffle.api.TruffleOptions
import java.io.File
import java.io.InputStream
import java.io.OutputStream
@@ -110,9 +109,6 @@ constructor(
} finally {
Closeables.closeQuietly(builder.moduleKeyFactories)
Closeables.closeQuietly(builder.resourceReaders)
if (TruffleOptions.AOT) {
VmUtils.closeEngine()
}
}
}
@@ -15,7 +15,6 @@
*/
package org.pkl.cli
import com.oracle.truffle.api.TruffleOptions
import java.io.StringWriter
import java.io.Writer
import org.pkl.commons.cli.*
@@ -25,7 +24,6 @@ import org.pkl.core.ModuleSource.uri
import org.pkl.core.PklException
import org.pkl.core.ProfilerOptions
import org.pkl.core.TestResults
import org.pkl.core.runtime.VmUtils
import org.pkl.core.stdlib.test.report.JUnitReporter
import org.pkl.core.stdlib.test.report.MinimalReporter
import org.pkl.core.stdlib.test.report.SpecReporter
@@ -47,9 +45,6 @@ constructor(
} finally {
Closeables.closeQuietly(builder.moduleKeyFactories)
Closeables.closeQuietly(builder.resourceReaders)
if (TruffleOptions.AOT) {
VmUtils.closeEngine()
}
}
}
@@ -36,29 +36,13 @@ import org.junit.jupiter.api.io.TempDir
* `-Dorg.pkl.cli.testJar=<path>` (or `-Dorg.pkl.cli.testExecutable=<path>`).
*/
class SubprocessProfilerOutputTest {
/**
* The command that launches Pkl: the native executable if `org.pkl.cli.testExecutable` is set,
* otherwise the executable jar given by `org.pkl.cli.testJar`.
*/
private fun launcher(): Array<String> {
System.getProperty("org.pkl.cli.testExecutable")?.let {
return arrayOf(it)
}
val jar =
checkNotNull(System.getProperty("org.pkl.cli.testJar")) {
"neither system property `org.pkl.cli.testExecutable` nor `org.pkl.cli.testJar` is set"
}
val javaBin = ProcessHandle.current().info().command().orElseThrow()
return arrayOf(javaBin, "-jar", jar)
}
private fun runTest(tempDir: Path, pklCode: String, command: Array<String>) {
val sourceFile = tempDir.resolve("profiled.pkl").also { it.writeText(pklCode) }
val outputFile = tempDir.resolve("profile.pb.gz")
val process =
ProcessBuilder(
*launcher(),
*subprocessLauncher(),
*command,
"--profile-cpu-output",
outputFile.absolutePathString(),
@@ -0,0 +1,84 @@
/*
* Copyright © 2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pkl.cli
import java.nio.file.Path
import kotlin.io.path.exists
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
/**
* Runs `pkl project package` using the packaged executable jar (or native executable) as a
* subprocess.
*/
class SubprocessProjectPackagerTest {
private fun Path.writeProject(name: String) {
writeFile(
"$name/PklProject",
"""
amends "pkl:Project"
package {
name = "$name"
baseUri = "package://example.com/$name"
version = "1.0.0"
packageZipUrl = "https://example.com/$name@\(version).zip"
apiTests { "test.pkl" }
}
"""
.trimIndent(),
)
writeFile(
"$name/test.pkl",
"""
amends "pkl:test"
facts {
["ok"] { true }
}
"""
.trimIndent(),
)
}
@Test
fun `multiple projects with apiTests`(@TempDir tempDir: Path) {
tempDir.writeProject("project1")
tempDir.writeProject("project2")
val process =
ProcessBuilder(
*subprocessLauncher(),
"project",
"package",
"--skip-publish-check",
"--output-path",
".out",
"project1",
"project2",
)
.directory(tempDir.toFile())
.redirectErrorStream(true)
.start()
val output = process.inputStream.bufferedReader().readText()
val exitCode = process.waitFor()
assertThat(exitCode).withFailMessage { "process failed with output:\n$output" }.isZero()
assertThat(tempDir.resolve(".out/project1@1.0.0.zip").exists()).isTrue
assertThat(tempDir.resolve(".out/project2@1.0.0.zip").exists()).isTrue
}
}
@@ -1,5 +1,5 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,3 +28,19 @@ fun Path.writeFile(fileName: String, contents: String): Path {
}
fun Path.writeEmptyFile(fileName: String): Path = writeFile(fileName, "")
/**
* The command that launches Pkl in subprocess tests: the native executable if
* `org.pkl.cli.testExecutable` is set, otherwise the executable jar given by `org.pkl.cli.testJar`.
*/
fun subprocessLauncher(): Array<String> {
System.getProperty("org.pkl.cli.testExecutable")?.let {
return arrayOf(it)
}
val jar =
checkNotNull(System.getProperty("org.pkl.cli.testJar")) {
"neither system property `org.pkl.cli.testExecutable` nor `org.pkl.cli.testJar` is set"
}
val javaBin = ProcessHandle.current().info().command().orElseThrow()
return arrayOf(javaBin, "-jar", jar)
}
@@ -122,10 +122,6 @@ public final class VmUtils {
return Engine.newBuilder("pkl").option("engine.WarnInterpreterOnly", "false").build();
}
public static void closeEngine() {
PKL_ENGINE.close(true);
}
static VmTyped createEmptyModule() {
return new VmTyped(createEmptyMaterializedFrame(), null, EconomicMaps.create());
}