Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for custom build directory #120

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading