Skip to content

Commit

Permalink
add support for custom build directory (#120)
Browse files Browse the repository at this point in the history
* fix the environment path when running the executables
  • Loading branch information
arun3688 authored Mar 25, 2024
1 parent a3234ea commit ca5ed4d
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/modelicaSystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CONDITIONS OF OSMC-PL.

"""
ModelicaSystem(omc, fileName, modelName, library=nothing;
commandLineOptions=nothing, variableFilter=nothing)
commandLineOptions=nothing, variableFilter=nothing, customBuildDirectory=nothing)
Set command line options for OMCSession and build model `modelName` to prepare for a simulation.
Expand Down Expand Up @@ -73,7 +73,8 @@ function ModelicaSystem(omc::OMCSession,
modelName::AbstractString,
library::Union{<:AbstractString, Tuple{<:AbstractString, <:AbstractString}, Array{<:AbstractString}, Array{Tuple{<:AbstractString, <:AbstractString}}, Nothing} = nothing;
commandLineOptions::Union{<:AbstractString, Nothing} = nothing,
variableFilter::Union{<:AbstractString, Nothing} = nothing)
variableFilter::Union{<:AbstractString, Nothing} = nothing,
customBuildDirectory::Union{<:AbstractString, Nothing} = nothing)

## check for commandLineOptions
setCommandLineOptions(omc, commandLineOptions)
Expand All @@ -94,7 +95,7 @@ function ModelicaSystem(omc::OMCSession,
end

#set temp directory for each modelica session
setTempDirectory(omc)
setTempDirectory(omc, customBuildDirectory)

#load Libraries provided by users
loadLibrary(omc, library)
Expand All @@ -106,7 +107,7 @@ end

"""
ModelicaSystem(omc; modelName, library=nothing,
commandLineOptions=nothing, variableFilter=nothing)
commandLineOptions=nothing, variableFilter=nothing, customBuildDirectory=nothing)
Set command line options for OMCSession and build model `modelname` to prepare for a simulation.
Expand Down Expand Up @@ -142,9 +143,10 @@ function ModelicaSystem(omc::OMCSession;
modelName::AbstractString,
library::Union{<:AbstractString,Tuple{<:AbstractString,<:AbstractString},Array{<:AbstractString},Array{Tuple{<:AbstractString,<:AbstractString}},Nothing} = nothing,
commandLineOptions::Union{<:AbstractString,Nothing} = nothing,
variableFilter::Union{<:AbstractString,Nothing} = nothing)
variableFilter::Union{<:AbstractString,Nothing} = nothing,
customBuildDirectory::Union{<:AbstractString,Nothing} = nothing)

ModelicaSystem(omc, fileName, modelName, library; commandLineOptions=commandLineOptions, variableFilter=variableFilter)
ModelicaSystem(omc, fileName, modelName, library; commandLineOptions=commandLineOptions, variableFilter=variableFilter, customBuildDirectory=customBuildDirectory)
end


Expand All @@ -171,10 +173,17 @@ function loadFile(omc::OMCSession, filename::AbstractString)
end
end

function setTempDirectory(omc::OMCSession)
omc.tempdir = replace(mktempdir(), r"[/\\]+" => "/")
if !isdir(omc.tempdir)
error("Failed to create temp directory \"$(omc.tempdir)\"")
function setTempDirectory(omc::OMCSession, customBuildDirectory::Union{<:AbstractString,Nothing}=nothing)
if !isnothing(customBuildDirectory)
if !isdir(customBuildDirectory)
error("Directory does not exist \"$(customBuildDirectory)\"")
end
omc.tempdir = replace(abspath(customBuildDirectory), r"[/\\]+" => "/")
else
omc.tempdir = replace(mktempdir(), r"[/\\]+" => "/")
if !isdir(omc.tempdir)
error("Failed to create temp directory \"$(omc.tempdir)\"")
end
end
sendExpression(omc, "cd(\"" * omc.tempdir * "\")")
end
Expand Down Expand Up @@ -266,7 +275,6 @@ function buildModel(omc::OMCSession; variableFilter::Union{<:AbstractString, Not
else
varFilter = join(["variableFilter=\"", ".*" ,"\""])
end
varFilter

buildmodelexpr = join(["buildModel(",omc.modelname,", ", varFilter,")"])
@debug "buildmodelexpr: $buildmodelexpr"
Expand Down Expand Up @@ -701,7 +709,7 @@ function simulate(omc::OMCSession;
if Sys.iswindows()
installPath = sendExpression(omc, "getInstallationDirectoryPath()")
envPath = ENV["PATH"]
newPath = "$(envPath);$(installPath)/bin/;$(installPath)/lib/omc;$(installPath)/lib/omc/cpp;$(installPath)/lib/omc/omsicpp"
newPath = "$(installPath)/bin/;$(installPath)/lib/omc;$(installPath)/lib/omc/cpp;$(installPath)/lib/omc/omsicpp;$(envPath)"
# println("Path: $newPath")
withenv("PATH" => newPath) do
if verbose
Expand Down Expand Up @@ -1273,7 +1281,7 @@ function linearize(omc::OMCSession; lintime = nothing, simflags= nothing, verbos
if Sys.iswindows()
installPath = sendExpression(omc, "getInstallationDirectoryPath()")
envPath = ENV["PATH"]
newPath = "$(envPath);$(installPath)/bin/;$(installPath)/lib/omc;$(installPath)/lib/omc/cpp;$(installPath)/lib/omc/omsicpp"
newPath = "$(installPath)/bin/;$(installPath)/lib/omc;$(installPath)/lib/omc/cpp;$(installPath)/lib/omc/omsicpp;$(envPath)"
# println("Path: $newPath")
withenv("PATH" => newPath) do
if verbose
Expand Down

0 comments on commit ca5ed4d

Please sign in to comment.