From 06defd0cb0019326d7a6daedb206437045c1bc9d Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 16 Oct 2021 02:43:22 +0200 Subject: [PATCH] paths are now always relative --- compiler/src/prog8/CompilerMain.kt | 2 +- compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt | 4 ++-- compiler/test/AsmgenTests.kt | 2 +- compilerAst/src/prog8/parser/Prog8Parser.kt | 2 +- compilerAst/src/prog8/parser/SourceCode.kt | 3 ++- docs/source/todo.rst | 2 +- httpCompilerService/src/prog8/http/TestHttp.kt | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/compiler/src/prog8/CompilerMain.kt b/compiler/src/prog8/CompilerMain.kt index 7c77c238b..d1cab9029 100644 --- a/compiler/src/prog8/CompilerMain.kt +++ b/compiler/src/prog8/CompilerMain.kt @@ -85,7 +85,7 @@ private fun compileMain(args: Array): Boolean { for (importedFile in allImportedFiles) { print(" ") println(importedFile) - val watchDir = importedFile.parent ?: Path.of(".") + val watchDir = importedFile.parent ?: Path.of("") watchDir.register(watchservice, StandardWatchEventKinds.ENTRY_MODIFY) } println("[${LocalDateTime.now().withNano(0)}] Waiting for file changes.") diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt index df4f59b02..0f0dda547 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt @@ -1343,8 +1343,8 @@ $repeatLabel lda $counterVar val sourcePath = Path(stmt.definingModule.source.pathString()) val includedPath = sourcePath.resolveSibling(includedName) val pathForAssembler = outputDir // #54: 64tass needs the path *relative to the .asm file* - .absolute() // avoid IllegalArgumentExc due to non-absolute path .relativize(absolute path) - .relativize(includedPath) + .toAbsolutePath() + .relativize(includedPath.toAbsolutePath()) .normalize() // avoid assembler warnings (-Wportable; only some, not all) .toString().replace('\\', '/') out(" .binary \"$pathForAssembler\" $offset $length") diff --git a/compiler/test/AsmgenTests.kt b/compiler/test/AsmgenTests.kt index 228187337..c66db1ce6 100644 --- a/compiler/test/AsmgenTests.kt +++ b/compiler/test/AsmgenTests.kt @@ -79,7 +79,7 @@ locallabel: val errors = ErrorReporter() val options = CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, true, C64Target) val zp = C64MachineDefinition.C64Zeropage(options) - val asmgen = AsmGen(program, errors, zp, options, C64Target, Path.of(".")) + val asmgen = AsmGen(program, errors, zp, options, C64Target, Path.of("")) return asmgen } diff --git a/compilerAst/src/prog8/parser/Prog8Parser.kt b/compilerAst/src/prog8/parser/Prog8Parser.kt index 546615afa..5ae045491 100644 --- a/compilerAst/src/prog8/parser/Prog8Parser.kt +++ b/compilerAst/src/prog8/parser/Prog8Parser.kt @@ -43,7 +43,7 @@ object Prog8Parser { } private class ParsedModule(source: SourceCode) : - Module(mutableListOf(), Position(source.origin, 1, 0, 0), source) + Module(mutableListOf(), Position(source.pathString(), 1, 0, 0), source) { /** diff --git a/compilerAst/src/prog8/parser/SourceCode.kt b/compilerAst/src/prog8/parser/SourceCode.kt index 70fb7b159..605598f5e 100644 --- a/compilerAst/src/prog8/parser/SourceCode.kt +++ b/compilerAst/src/prog8/parser/SourceCode.kt @@ -65,6 +65,7 @@ sealed class SourceCode { * filename prefix to designate library files that will be retreived from internal resources rather than disk */ const val libraryFilePrefix = "library:" + val curdir: Path = Path.of(".").toAbsolutePath() } /** @@ -102,7 +103,7 @@ sealed class SourceCode { } override val isFromResources = false - override val origin = normalized.absolutePathString() + override val origin = curdir.relativize(normalized.toAbsolutePath()).normalize().toString() override fun getCharStream(): CharStream = CharStreams.fromPath(normalized) } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 21ba9e832..caa212a6a 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,7 @@ TODO For next compiler release ^^^^^^^^^^^^^^^^^^^^^^^^^ -fix github issue #64 about inconsistent absolute path usage +re-test https://github.com/irmen/prog8/pull/54 on windows Blocked by Commander-x16 v39 release diff --git a/httpCompilerService/src/prog8/http/TestHttp.kt b/httpCompilerService/src/prog8/http/TestHttp.kt index 2cae665c7..f89c38378 100644 --- a/httpCompilerService/src/prog8/http/TestHttp.kt +++ b/httpCompilerService/src/prog8/http/TestHttp.kt @@ -35,7 +35,7 @@ class RequestParser : Take { slowCodegenWarnings = true, compilationTarget = "c64", sourceDirs = emptyList(), - outputDir = Path.of(".") + outputDir = Path.of("") ) return RsJson(Jsonding()) }