Skip to content

Commit

Permalink
Revert recent TSFileConfig changes and instead do not override
Browse files Browse the repository at this point in the history
  • Loading branch information
petervdonovan committed Jun 21, 2024
1 parent 6828b22 commit 759cd9d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
4 changes: 1 addition & 3 deletions core/src/main/java/org/lflang/generator/LFGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public static FileConfig createFileConfig(
case Python -> new PyFileConfig(resource, srcGenBasePath, useHierarchicalBin);
case CPP -> new CppFileConfig(resource, srcGenBasePath, useHierarchicalBin);
case Rust -> new RustFileConfig(resource, srcGenBasePath, useHierarchicalBin);
// null is passed to the docker argument because it is up to the TS Generator to tell the
// FileConfig whether Docker is enabled
case TS -> new TSFileConfig(resource, srcGenBasePath, useHierarchicalBin, null);
case TS -> new TSFileConfig(resource, srcGenBasePath, useHierarchicalBin);
};
} catch (IOException e) {
throw new RuntimeException(
Expand Down
35 changes: 1 addition & 34 deletions core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import java.nio.file.Path
* @author Hokeun Kim
*/
class TSFileConfig(
resource: Resource, srcGenBasePath: Path, useHierarchicalBin: Boolean, var docker: Boolean? = null
resource: Resource, srcGenBasePath: Path, useHierarchicalBin: Boolean
) : FileConfig(resource, srcGenBasePath, useHierarchicalBin) {

/**
Expand All @@ -53,37 +53,4 @@ class TSFileConfig(
super.doClean()
FileUtil.deleteDirectory(srcGenPath)
}

fun setDocker(dockerEnabled: Boolean) {
docker = dockerEnabled
}

override fun getCommand(): LFCommand {
if (docker == true) {
return super.getCommand()
} else if (docker == false) {
return LFCommand.get(
"node",
listOf(srcPkgPath.relativize(executable).toString()),
true,
srcPkgPath
)
} else {
throw java.lang.IllegalStateException("The execute command cannot be determined because it is not known whether code generation is in Docker mode.")
}
}

override fun getExecutableExtension(): String {
if (docker == true) {
return super.getExecutableExtension()
}
return ".js"
}

override fun getExecutable(): Path {
if (docker == true) {
return super.getExecutable()
}
return srcGenPath.resolve("dist").resolve(name + executableExtension)
}
}
9 changes: 7 additions & 2 deletions core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class TSGenerator(
override fun doGenerate(resource: Resource, context: LFGeneratorContext) {
// Register the after delay transformation to be applied by GeneratorBase.
registerTransformation(DelayedConnectionTransformation(TSDelayBodyGenerator, targetTypes, resource, true, true))
fileConfig.setDocker(targetConfig.get(DockerProperty.INSTANCE).enabled)

super.doGenerate(resource, context)

instantiationGraph
Expand Down Expand Up @@ -453,7 +453,12 @@ class TSGenerator(
context.finish(GeneratorResult.Status.COMPILED, codeMaps)
val shScriptPath = fileConfig.binPath.resolve(fileConfig.name)
val jsPath = fileConfig.srcGenPath.resolve("dist").resolve("${fileConfig.name}.js")
FileUtil.writeToFile("#!/bin/sh\nnode $jsPath", shScriptPath)
if (targetConfig.get(DockerProperty.INSTANCE).enabled) {
val launchScriptPath = context.fileConfig.srcPkgPath.relativize(fileConfig.binPath).toString()
FileUtil.writeToFile("#!/bin/sh\n $launchScriptPath", shScriptPath)
} else {
FileUtil.writeToFile("#!/bin/sh\nnode $jsPath", shScriptPath)
}
shScriptPath.toFile().setExecutable(true)
messageReporter.nowhere().info("Script for running the program: $shScriptPath.")
}
Expand Down

0 comments on commit 759cd9d

Please sign in to comment.