Fix evaluating dependency notation URIs with multiple file output (#1942)
This commit is contained in:
1 parent
434f699887
commit
ea68f7b258
10 files changed
+82
-5
No files matched your search
@@ -123,18 +123,23 @@ constructor(
|
||||
|
||||
return options.base.normalizedSourceModules.associateWith { uri ->
|
||||
val moduleDir: String? =
|
||||
if (!uri.isAbsolute && uri.schemeSpecificPart.startsWith("@")) null
|
||||
else
|
||||
IoUtils.toPath(uri)?.let {
|
||||
IoUtils.relativize(it.parent, workingDir).toString().ifEmpty { "." }
|
||||
}
|
||||
val moduleKey =
|
||||
val moduleName =
|
||||
if (!uri.isAbsolute && uri.schemeSpecificPart.startsWith("@"))
|
||||
IoUtils.getNameWithoutExtension(uri.path)
|
||||
else
|
||||
try {
|
||||
moduleResolver.resolve(uri)
|
||||
IoUtils.inferModuleName(moduleResolver.resolve(uri))
|
||||
} catch (e: VmException) {
|
||||
throw e.toPklException(stackFrameTransformer, options.base.color?.hasColor() ?: false)
|
||||
}
|
||||
val substituted =
|
||||
pathStr
|
||||
.replace("%{moduleName}", IoUtils.inferModuleName(moduleKey))
|
||||
.replace("%{moduleName}", moduleName)
|
||||
.replace("%{outputFormat}", options.outputFormat ?: "%{outputFormat}")
|
||||
.replace("%{moduleDir}", moduleDir ?: "%{moduleDir}")
|
||||
if (substituted.contains("%{moduleDir}")) {
|
||||
|
||||
@@ -1798,6 +1798,31 @@ result = someLib.x
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `eval dependency notation source with multiple file output`(
|
||||
@TempDir tempDir: Path,
|
||||
@TempDir cacheDir: Path,
|
||||
) {
|
||||
PackageServer.populateCacheDir(cacheDir)
|
||||
val projectPath =
|
||||
FileTestUtils.rootProjectDir.resolve(
|
||||
"pkl-commons-cli/src/test/resources/org/pkl/commons/cli/project1/"
|
||||
)
|
||||
val options =
|
||||
CliEvaluatorOptions(
|
||||
CliBaseOptions(
|
||||
sourceModules = listOf(URI("@fruit/catalog/basket.pkl")),
|
||||
projectDir = projectPath,
|
||||
moduleCacheDir = cacheDir,
|
||||
workingDir = tempDir,
|
||||
),
|
||||
multipleFileOutputPath = "output",
|
||||
)
|
||||
val output = evalToConsole(options)
|
||||
assertThat(output.split('\n')).hasSize(3)
|
||||
assertThat(tempDir.resolve("output").listDirectoryEntries()).hasSize(2)
|
||||
}
|
||||
|
||||
private fun evalModuleThatImportsPackage(certsFile: Path?, testPort: Int = -1) {
|
||||
val moduleUri =
|
||||
writePklFile(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
amends "pkl:Project"
|
||||
|
||||
dependencies {
|
||||
["fruit"] { uri = "package://localhost:0/fruit@1.1.0" }
|
||||
["fruit"] { uri = "package://localhost:0/fruit@1.2.0" }
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
"resolvedDependencies": {
|
||||
"package://localhost:0/fruit@1": {
|
||||
"type": "remote",
|
||||
"uri": "projectpackage://localhost:0/fruit@1.1.0",
|
||||
"uri": "projectpackage://localhost:0/fruit@1.2.0",
|
||||
"checksums": {
|
||||
"sha256": "$skipChecksumVerification"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"packageUri": "package://localhost:0/fruit@1.2.0",
|
||||
"name": "fruit",
|
||||
"version": "1.2.0",
|
||||
"packageZipUrl": "https://localhost:0/fruit@1.2.0/fruit@1.2.0.zip",
|
||||
"dependencies": {},
|
||||
"packageZipChecksums": {
|
||||
"sha256": "$computedChecksum"
|
||||
},
|
||||
"sourceCode": "https://example.com/fruit",
|
||||
"documentation": "https://example.com/fruit-docs",
|
||||
"license": "UNLICENSED",
|
||||
"authors": [
|
||||
"apple-1@example.com",
|
||||
"banana-2@example.com"
|
||||
],
|
||||
"issueTracker": "https://example.com/fruit/issues"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module fruit.Fruit
|
||||
|
||||
name: String
|
||||
@@ -0,0 +1,13 @@
|
||||
module fruit.Fruits
|
||||
|
||||
import "Fruit.pkl"
|
||||
|
||||
fruits: Listing<Fruit>
|
||||
|
||||
output {
|
||||
files {
|
||||
for (fruit in fruits) {
|
||||
[fruit.name] = fruit.output
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
amends "../Fruit.pkl"
|
||||
|
||||
name = "Apple 🍎"
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
amends "../Fruits.pkl"
|
||||
|
||||
fruits {
|
||||
import("apple.pkl")
|
||||
import("pineapple.pkl")
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
amends "../Fruit.pkl"
|
||||
|
||||
name = "Pineapple 🍍"
|
||||
Reference in new issue
Block a user