From 55f899d7aadc0426651f95d19a1527a6e54f3057 Mon Sep 17 00:00:00 2001 From: ivborissov Date: Tue, 3 Sep 2024 20:29:01 +0300 Subject: [PATCH] heta_compiler v check moved to load_jlplatform --- src/heta_cli/connect.jl | 5 +++++ src/import_platform.jl | 4 ---- test/dummy_jlmodel.jl | 18 ++++++++++++++++++ test/heta_compiler_test.jl | 3 ++- 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 test/dummy_jlmodel.jl diff --git a/src/heta_cli/connect.jl b/src/heta_cli/connect.jl index ef2284e..4cfa6b8 100644 --- a/src/heta_cli/connect.jl +++ b/src/heta_cli/connect.jl @@ -62,8 +62,13 @@ function load_jlplatform( model_jl::AbstractString; rm_out::Bool = false ) + # load model to Main Base.include(Main, model_jl) + + version = Main.__platform__[3] + @assert version == HETA_COMPILER_VERSION "The model was build with Heta compiler v$version, which is not supported.\n"* + "This HetaSimulator release includes Heta compiler v$HETA_COMPILER_VERSION. Please re-compile the model with HetaSimulator load_platform()." # remove output after model load rm_out && rm(dirname("$model_jl"); force=true, recursive=true) diff --git a/src/import_platform.jl b/src/import_platform.jl index 8177947..f3b9591 100644 --- a/src/import_platform.jl +++ b/src/import_platform.jl @@ -8,10 +8,6 @@ function Platform( scenarios::Tuple, version::String ) - # TODO: semver approach might be better - @assert version == HETA_COMPILER_VERSION "The model was build with Heta compiler v$version, which is not supported.\n"* - "This HetaSimulator release includes Heta compiler v$HETA_COMPILER_VERSION. Please re-compile the model with HetaSimulator load_platform()." - print("Loading platform... ") model_pairs = [pair[1] => Model(pair[2]...) for pair in pairs(models)] diff --git a/test/dummy_jlmodel.jl b/test/dummy_jlmodel.jl new file mode 100644 index 0000000..ffd1974 --- /dev/null +++ b/test/dummy_jlmodel.jl @@ -0,0 +1,18 @@ +#= + This code was generated by heta-compiler 0.0.1 +=# + +__platform__ = (function() + +### NO MODEL CODE ### + +return ( + ( + nameless = nothing, + ), + (), + "0.0.1" +) + +end +)() \ No newline at end of file diff --git a/test/heta_compiler_test.jl b/test/heta_compiler_test.jl index 9af8405..23f24bb 100644 --- a/test/heta_compiler_test.jl +++ b/test/heta_compiler_test.jl @@ -1,2 +1,3 @@ -@test chomp(read(`$(HetaSimulator.heta_exe_path) -v`, String)) == HetaSimulator.HETA_COMPILER_VERSION \ No newline at end of file +@test chomp(read(`$(HetaSimulator.heta_exe_path) -v`, String)) == HetaSimulator.HETA_COMPILER_VERSION +@test_throws AssertionError("The model was build with Heta compiler v0.0.1, which is not supported.\nThis HetaSimulator release includes Heta compiler v0.8.6. Please re-compile the model with HetaSimulator load_platform().") load_jlplatform("$HetaSimulatorDir/test/dummy_jlmodel.jl") \ No newline at end of file