mirror of
https://github.com/apple/pkl.git
synced 2026-03-27 19:41:18 +01:00
Add support for Windows (#492)
This adds support for Windows. The in-language path separator is still `/`, to ensure Pkl programs are cross-platform. Log lines are written using CRLF endings on Windows. Modules that are combined with `--module-output-separator` uses LF endings to ensure consistent rendering across platforms. `jpkl` does not work on Windows as a direct executable. However, it can work with `java -jar jpkl`. Additional details: * Adjust git settings for Windows * Add native executable for pkl cli * Add jdk17 windows Gradle check in CI * Adjust CI test reports to be staged within Gradle rather than by shell script. * Fix: encode more characters that are not safe Windows paths * Skip running tests involving symbolic links on Windows (these require administrator privileges to run). * Introduce custom implementation of `IoUtils.relativize` * Allow Gradle to initialize ExecutableJar `Property` values * Add Gradle flag to enable remote JVM debugging Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
This commit is contained in:
@@ -111,7 +111,9 @@ constructor(
|
||||
|
||||
return moduleUris.associateWith { uri ->
|
||||
val moduleDir: String? =
|
||||
IoUtils.toPath(uri)?.let { workingDir.relativize(it.parent).toString().ifEmpty { "." } }
|
||||
IoUtils.toPath(uri)?.let {
|
||||
IoUtils.relativize(it.parent, workingDir).toString().ifEmpty { "." }
|
||||
}
|
||||
val moduleKey =
|
||||
try {
|
||||
moduleResolver.resolve(uri)
|
||||
@@ -158,7 +160,7 @@ constructor(
|
||||
} else {
|
||||
if (output.isNotEmpty()) {
|
||||
outputFile.writeString(
|
||||
options.moduleOutputSeparator + IoUtils.getLineSeparator(),
|
||||
options.moduleOutputSeparator + '\n',
|
||||
Charsets.UTF_8,
|
||||
StandardOpenOption.WRITE,
|
||||
StandardOpenOption.APPEND
|
||||
@@ -192,6 +194,14 @@ constructor(
|
||||
if (uri == VmUtils.REPL_TEXT_URI) ModuleSource.create(uri, reader.readText())
|
||||
else ModuleSource.uri(uri)
|
||||
|
||||
private fun checkPathSpec(pathSpec: String) {
|
||||
val illegal = pathSpec.indexOfFirst { IoUtils.isReservedFilenameChar(it) && it != '/' }
|
||||
if (illegal == -1) {
|
||||
return
|
||||
}
|
||||
throw CliException("Path spec `$pathSpec` contains illegal character `${pathSpec[illegal]}`.")
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders each module's `output.files`, writing each entry as a file into the specified output
|
||||
* directory.
|
||||
@@ -207,6 +217,7 @@ constructor(
|
||||
val moduleSource = toModuleSource(moduleUri, consoleReader)
|
||||
val output = evaluator.evaluateOutputFiles(moduleSource)
|
||||
for ((pathSpec, fileOutput) in output) {
|
||||
checkPathSpec(pathSpec)
|
||||
val resolvedPath = outputDir.resolve(pathSpec).normalize()
|
||||
val realPath = if (resolvedPath.exists()) resolvedPath.toRealPath() else resolvedPath
|
||||
if (!realPath.startsWith(outputDir)) {
|
||||
@@ -228,7 +239,10 @@ constructor(
|
||||
writtenFiles[realPath] = OutputFile(pathSpec, moduleUri)
|
||||
realPath.createParentDirectories()
|
||||
realPath.writeString(fileOutput.text)
|
||||
consoleWriter.write(currentWorkingDir.relativize(resolvedPath).toString() + "\n")
|
||||
consoleWriter.write(
|
||||
IoUtils.relativize(resolvedPath, currentWorkingDir).toString() +
|
||||
IoUtils.getLineSeparator()
|
||||
)
|
||||
consoleWriter.flush()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,11 @@ class CliPackageDownloader(
|
||||
}
|
||||
when (errors.size) {
|
||||
0 -> return
|
||||
1 -> throw CliException(errors.values.single().message!!)
|
||||
1 ->
|
||||
throw CliException(
|
||||
errors.values.single().message
|
||||
?: ("An unexpected error occurred: " + errors.values.single())
|
||||
)
|
||||
else ->
|
||||
throw CliException(
|
||||
buildString {
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.github.ajalt.clikt.parameters.groups.provideDelegate
|
||||
import java.net.URI
|
||||
import org.pkl.cli.CliTestRunner
|
||||
import org.pkl.commons.cli.commands.BaseCommand
|
||||
import org.pkl.commons.cli.commands.BaseOptions
|
||||
import org.pkl.commons.cli.commands.ProjectOptions
|
||||
import org.pkl.commons.cli.commands.TestOptions
|
||||
|
||||
@@ -29,7 +30,7 @@ class TestCommand(helpLink: String) :
|
||||
BaseCommand(name = "test", help = "Run tests within the given module(s)", helpLink = helpLink) {
|
||||
val modules: List<URI> by
|
||||
argument(name = "<modules>", help = "Module paths or URIs to evaluate.")
|
||||
.convert { parseModuleName(it) }
|
||||
.convert { BaseOptions.parseModuleName(it) }
|
||||
.multiple()
|
||||
|
||||
private val projectOptions by ProjectOptions()
|
||||
|
||||
Reference in New Issue
Block a user