mirror of
https://github.com/apple/pkl.git
synced 2026-05-25 16:19:20 +02:00
Improve handling of evaling dependency notation URIs (#1595)
This commit is contained in:
@@ -67,7 +67,7 @@ constructor(
|
||||
val evaluator = builder.build()
|
||||
evaluator.use {
|
||||
evaluator.evaluateCommand(
|
||||
uri(resolvedSourceModules.first()),
|
||||
uri(options.normalizedSourceModules.first()),
|
||||
reservedFlagNames,
|
||||
reservedFlagShortNames,
|
||||
) { spec ->
|
||||
|
||||
@@ -115,7 +115,7 @@ constructor(
|
||||
// used just to resolve the `%{moduleName}` placeholder
|
||||
val moduleResolver = ModuleResolver(moduleKeyFactories(ModulePathResolver.empty()))
|
||||
|
||||
return resolvedSourceModules.associateWith { uri ->
|
||||
return options.base.normalizedSourceModules.associateWith { uri ->
|
||||
val moduleDir: String? =
|
||||
IoUtils.toPath(uri)?.let {
|
||||
IoUtils.relativize(it.parent, workingDir).toString().ifEmpty { "." }
|
||||
@@ -191,7 +191,7 @@ constructor(
|
||||
}
|
||||
} else {
|
||||
var outputWritten = false
|
||||
for (moduleUri in resolvedSourceModules) {
|
||||
for (moduleUri in options.base.normalizedSourceModules) {
|
||||
val moduleSource = toModuleSource(moduleUri, inputStream)
|
||||
if (options.expression != null) {
|
||||
val output = evaluator.evaluateExpressionString(moduleSource, options.expression)
|
||||
|
||||
@@ -66,7 +66,7 @@ constructor(
|
||||
try {
|
||||
return builder
|
||||
.apply {
|
||||
for ((idx, sourceModule) in resolvedSourceModules.withIndex()) {
|
||||
for ((idx, sourceModule) in options.base.normalizedSourceModules.withIndex()) {
|
||||
addExternalProperty("pkl.analyzeImports.$idx", sourceModule.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ constructor(
|
||||
|
||||
private fun evalTest(builder: EvaluatorBuilder) {
|
||||
val sources =
|
||||
resolvedSourceModules.ifEmpty { project?.tests?.map { it.toUri() } }
|
||||
options.normalizedSourceModules.ifEmpty { project?.tests?.map { it.toUri() } }
|
||||
?:
|
||||
// keep in sync with error message thrown by clikt
|
||||
throw CliException(
|
||||
|
||||
@@ -1754,6 +1754,32 @@ result = someLib.x
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `eval dependency notation source`(@TempDir tempDir: Path) {
|
||||
PackageServer.populateCacheDir(tempDir)
|
||||
val projectPath =
|
||||
FileTestUtils.rootProjectDir.resolve(
|
||||
"pkl-commons-cli/src/main/resources/org/pkl/commons/cli/project1/"
|
||||
)
|
||||
val options =
|
||||
CliEvaluatorOptions(
|
||||
CliBaseOptions(
|
||||
sourceModules = listOf(URI("@fruit/catalog/apple.pkl")),
|
||||
projectDir = projectPath,
|
||||
moduleCacheDir = tempDir,
|
||||
)
|
||||
)
|
||||
val output = evalToConsole(options)
|
||||
assertThat(output)
|
||||
.isEqualTo(
|
||||
"""
|
||||
name = "Apple 🍎"
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
private fun evalModuleThatImportsPackage(certsFile: Path?, testPort: Int = -1) {
|
||||
val moduleUri =
|
||||
writePklFile(
|
||||
|
||||
Reference in New Issue
Block a user