From 64a0b8aa95c61b2731ec252ec69e26512f2647ee Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 14 Jul 2022 17:05:44 +0200 Subject: [PATCH] use absolute paths --- .../org/lflang/generator/rust/RustCargoTomlEmitter.kt | 2 +- .../src/org/lflang/generator/rust/RustEmitterBase.kt | 1 - .../src/org/lflang/generator/rust/RustGenerator.kt | 2 +- org.lflang/src/org/lflang/generator/rust/RustModel.kt | 10 ++++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt b/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt index 044522e1ab..c4ef1b8a16 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt @@ -79,7 +79,7 @@ ${" |"..crate.dependencies.asIterable().joinToString("\n") { (name, spec private fun CargoDependencySpec.toToml(): String = mutableMapOf().apply { if (version != null) this["version"] = version.asStringLiteral() - if (localPath != null) this["path"] = Paths.get(localPath).toString().asStringLiteral() + if (localPath != null) this["path"] = Paths.get(localPath).toAbsolutePath().toString().asStringLiteral() if (features != null) this["features"] = features.map { it.asStringLiteral() }.joinWithCommas("[", "]") if (gitRepo != null) this["git"] = gitRepo.asStringLiteral() if (rev != null) this["rev"] = rev.asStringLiteral() diff --git a/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt b/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt index d2b976c01c..0ba355de2a 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt @@ -63,7 +63,6 @@ abstract class RustEmitterBase { /** Name of the runtime crate that is in its Cargo.toml.*/ const val runtimeCrateFullName = "reactor_rt" const val runtimeGitUrl = "https://github.com/lf-lang/reactor-rust.git" - const val runtimeLocalPath = "../reactor-rs" /** Qualification prefix to refer to a member of the runtime library crate. */ const val rsRuntime = "::$runtimeCrateFullName" diff --git a/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt b/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt index 46a74f005b..cb30d63a57 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt @@ -84,7 +84,7 @@ class RustGenerator( true ) - val gen = RustModelBuilder.makeGenerationInfo(targetConfig, reactors, errorReporter) + val gen = RustModelBuilder.makeGenerationInfo(targetConfig, fileConfig, reactors, errorReporter) val codeMaps: Map = RustEmitter.generateRustProject(fileConfig, gen) if (targetConfig.noCompile || errorsOccurred()) { diff --git a/org.lflang/src/org/lflang/generator/rust/RustModel.kt b/org.lflang/src/org/lflang/generator/rust/RustModel.kt index 4a9bc3b672..03ffafa768 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustModel.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustModel.kt @@ -412,7 +412,7 @@ object RustModelBuilder { /** * Given the input to the generator, produce the model classes. */ - fun makeGenerationInfo(targetConfig: TargetConfig, reactors: List, errorReporter: ErrorReporter): GenerationInfo { + fun makeGenerationInfo(targetConfig: TargetConfig, fileConfig: RustFileConfig, reactors: List, errorReporter: ErrorReporter): GenerationInfo { val reactorsInfos = makeReactorInfos(reactors) // todo how do we pick the main reactor? it seems like super.doGenerate sets that field... val mainReactor = reactorsInfos.lastOrNull { it.isMain } ?: reactorsInfos.last() @@ -420,7 +420,7 @@ object RustModelBuilder { val dependencies = targetConfig.rust.cargoDependencies.toMutableMap() dependencies.compute(RustEmitterBase.runtimeCrateFullName) { _, spec -> - computeDefaultRuntimeConfiguration(spec, targetConfig, errorReporter) + computeDefaultRuntimeConfiguration(spec, targetConfig, fileConfig, errorReporter) } return GenerationInfo( @@ -448,8 +448,10 @@ object RustModelBuilder { private fun computeDefaultRuntimeConfiguration( userSpec: CargoDependencySpec?, targetConfig: TargetConfig, + fileConfig: RustFileConfig, errorReporter: ErrorReporter ): CargoDependencySpec { + val defaultRuntimePath = fileConfig.srcGenBasePath.resolve(RustGenerator.runtimeName).toString() if (userSpec == null) { // default configuration for the runtime crate @@ -467,14 +469,14 @@ object RustModelBuilder { spec.gitRepo = RustEmitterBase.runtimeGitUrl spec.rev = userRtVersion } else { - spec.localPath = RustEmitterBase.runtimeLocalPath + spec.localPath = defaultRuntimePath } return spec } else { if (userSpec.localPath == null && userSpec.gitRepo == null) { // default the location - userSpec.localPath = RustEmitterBase.runtimeLocalPath + userSpec.localPath = defaultRuntimePath } // override location