Skip to content

Commit

Permalink
also fix C++ ros2 docker generation
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnrd committed Jun 20, 2024
1 parent a6b8982 commit 90e6828
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.lflang.target.property.NoRuntimeValidationProperty
import org.lflang.target.property.PrintStatisticsProperty
import org.lflang.target.property.TracingProperty
import org.lflang.toDefinition
import org.lflang.toUnixString
import java.nio.file.Path

/** Abstract class for generating platform specific files and invoking the target compiler. */
Expand All @@ -24,6 +25,7 @@ abstract class CppPlatformGenerator(protected val generator: CppGenerator) {
protected val mainReactor = generator.mainDef.reactorClass.toDefinition()

open val srcGenPath: Path = generator.fileConfig.srcGenPath
protected val relativeBinDir = fileConfig.outPath.relativize(fileConfig.binPath).toUnixString()

abstract fun generatePlatformFiles()

Expand Down
30 changes: 17 additions & 13 deletions core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CppRos2Generator(generator: CppGenerator) : CppPlatformGenerator(generator
)
val scriptPath =
if (targetConfig.get(DockerProperty.INSTANCE).enabled)
fileConfig.srcGenPath.resolve("bin").resolve(fileConfig.name)
fileConfig.srcGenPath.resolve(relativeBinDir).resolve(fileConfig.name)
else
fileConfig.binPath.resolve(fileConfig.name)
FileUtil.writeToFile(packageGenerator.generateBinScript(), scriptPath)
Expand All @@ -58,7 +58,8 @@ class CppRos2Generator(generator: CppGenerator) : CppPlatformGenerator(generator
return false
}
val colconCommand = commandFactory.createCommand(
"colcon", colconArgs(), fileConfig.outPath)
"colcon", colconArgs(), fileConfig.outPath
)
val returnCode = colconCommand?.run(context.cancelIndicator)
if (returnCode != 0 && !messageReporter.errorsOccurred) {
// If errors occurred but none were reported, then the following message is the best we can do.
Expand All @@ -70,13 +71,13 @@ class CppRos2Generator(generator: CppGenerator) : CppPlatformGenerator(generator

private fun colconArgs(): List<String> {
return listOf(
"build",
"--packages-select",
fileConfig.name,
packageGenerator.reactorCppName,
"--cmake-args",
"-DLF_REACTOR_CPP_SUFFIX=${packageGenerator.reactorCppSuffix}",
) + cmakeArgs
"build",
"--packages-select",
fileConfig.name,
packageGenerator.reactorCppName,
"--cmake-args",
"-DLF_REACTOR_CPP_SUFFIX=${packageGenerator.reactorCppSuffix}",
) + cmakeArgs
}

inner class CppDockerGenerator(context: LFGeneratorContext?) : DockerGenerator(context) {
Expand All @@ -90,13 +91,16 @@ class CppRos2Generator(generator: CppGenerator) : CppPlatformGenerator(generator

override fun generateRunForInstallingDeps(): String = ""

override fun defaultEntryPoint(): List<String> = listOf(fileConfig.outPath.relativize(fileConfig.binPath).toUnixString() + "/" + fileConfig.name)
override fun defaultEntryPoint(): List<String> =
listOf("$relativeBinDir/${fileConfig.name}")

override fun generateCopyOfExecutable(): String =
"""
${super.generateCopyOfExecutable()}
override fun generateCopyOfExecutable(): String {
val name = fileConfig.name
return """
COPY --from=builder /lingua-franca/$name/$relativeBinDir/$name ./$relativeBinDir/$name
COPY --from=builder lingua-franca/${fileConfig.name}/install install
""".trimIndent()
}

override fun defaultBuildCommands(): List<String> {
val commands = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class CppStandaloneGenerator(generator: CppGenerator) :
const val DEFAULT_BASE_IMAGE: String = "alpine:latest"
}

private val relativeBinDir = fileConfig.outPath.relativize(fileConfig.binPath).toUnixString()

override fun generatePlatformFiles() {

// generate the main source file (containing main())
Expand Down Expand Up @@ -194,6 +192,7 @@ class CppStandaloneGenerator(generator: CppGenerator) :
return cmd
}


inner class StandaloneDockerGenerator(context: LFGeneratorContext?) : DockerGenerator(context) {

override fun generateCopyForSources(): String = "COPY src-gen src-gen"
Expand Down

0 comments on commit 90e6828

Please sign in to comment.