Skip to content

Commit

Permalink
Fixed bugs with the OPENMODELICAHOME variable. MathModelica now works…
Browse files Browse the repository at this point in the history
… without having this variable and OpenModelica works with it. This means that it is now possible to have both installed.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2469 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Aug 18, 2006
1 parent 259de82 commit 0261fe9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 38 deletions.
50 changes: 42 additions & 8 deletions Compiler/Ceval.mo
Expand Up @@ -1856,6 +1856,13 @@ algorithm
then
(cache,Values.BOOL(true),st);

case (cache,env,Exp.CALL(path = Absyn.IDENT(name = "getInstallationDirectoryPath"),expLst = {}),(st as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
local String res;
equation
res = Settings.getInstallationDirectoryPath();
then
(cache,Values.STRING(res),st);

case (cache,env,Exp.CALL(path = Absyn.IDENT(name = "setModelicaPath"),expLst = {Exp.SCONST(string = cmd)}),(st as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
equation
cmd = Util.rawStringToInputString(cmd);
Expand Down Expand Up @@ -2725,7 +2732,9 @@ algorithm
local
String pd,omhome,omhome_1,cd_path,libsfilename,libs_str,s_call,fileprefix,file_dir,command,filename,str;
list<String> libs;
case (fileprefix,libs,file_dir) /* executable name external libs directory for mo-file */

// If compileCommand not set, use <installationDirectory>\bin\Compile
case (fileprefix,libs,file_dir)
equation
"" = Settings.getCompileCommand();
pd = System.pathDelimiter();
Expand All @@ -2735,12 +2744,13 @@ algorithm
libsfilename = stringAppend(fileprefix, ".libs");
libs_str = Util.stringDelimitList(libs, " ");
System.writeFile(libsfilename, libs_str);
s_call = Util.stringAppendList({"\"",omhome_1,pd,"bin",pd,"Compile","\""," ",fileprefix/*," \"",omhome_1,"\""*/});
s_call = Util.stringAppendList({"\"",omhome_1,pd,"bin",pd,"Compile","\""," ",fileprefix,
" ", omhome_1});
// print(s_call);
// print("<<<<<\n");
0 = System.systemCall(s_call) "> output.log 2>&1 = redirect stderr to stdout and put it in output.log print s_call & print \"\\n\" &" ;
0 = System.systemCall(s_call) ;
then
();
// If compileCommand is set.
case (fileprefix,libs,file_dir)
equation
command = Settings.getCompileCommand();
Expand All @@ -2751,12 +2761,12 @@ algorithm
libs_str = Util.stringDelimitList(libs, " ");
libsfilename = stringAppend(fileprefix, ".libs");
System.writeFile(libsfilename, libs_str);
s_call = Util.stringAppendList({command," ",fileprefix/*," \"",omhome_1,"\""*/}) ;
s_call = Util.stringAppendList({command," ",fileprefix," ",omhome_1});
// print(s_call);
// print("<<<<<222\n");
0 = System.systemCall(s_call) "> output.log 2>&1 = redirect stderr to stdout and put it in output.log print s_call & print \"\\n\" &" ;
0 = System.systemCall(s_call) ;
then
();
();

case (fileprefix,libs,file_dir) /* compilation failed\\n */
equation
filename = Util.stringAppendList({fileprefix,".log"});
Expand All @@ -2765,6 +2775,30 @@ algorithm
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {str});
then
fail();
case (fileprefix,libs,file_dir)
local Integer retVal;
equation
command = Settings.getCompileCommand();
false = Util.isEmptyString(command);
retVal = System.regularFileExists(command);
true = retVal != 0;
str=Util.stringAppendList({"command ",command," not found. Check OPENMODELICAHOME"});
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {str});
then fail();

case (fileprefix,libs,file_dir) /* compilation failed\\n */
local Integer retVal;
equation
omhome = Settings.getInstallationDirectoryPath();
omhome_1 = System.stringReplace(omhome, "\"", "");
pd = System.pathDelimiter();
s_call = Util.stringAppendList({"\"",omhome_1,pd,"bin",pd,"Compile.bat","\""});
retVal = System.regularFileExists(s_call);
true = retVal != 0;
str=Util.stringAppendList({"command ",s_call," not found. Check OPENMODELICAHOME"});
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {str});
then
fail();
case (fileprefix,libs,file_dir)
equation
Print.printErrorBuf("#Error building simulation code.\n ");
Expand Down
6 changes: 6 additions & 0 deletions Compiler/Static.mo
Expand Up @@ -4404,6 +4404,12 @@ algorithm

case (cache,env,Absyn.CREF_IDENT(name = "setInstallationDirectoryPath"),{Absyn.STRING(value = str)},{},impl,SOME(st)) then (cache, Exp.CALL(Absyn.IDENT("setInstallationDirectoryPath"),
{Exp.SCONST(str)},false,true),Types.PROP((Types.T_BOOL({}),NONE),Types.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "getInstallationDirectoryPath"),{},{},impl,SOME(st)) then (cache, Exp.CALL(Absyn.IDENT("getInstallationDirectoryPath"),
{},false,true),Types.PROP((Types.T_STRING({}),NONE),Types.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "setModelicaPath"),{Absyn.STRING(value = str)},{},impl,SOME(st)) then (cache, Exp.CALL(Absyn.IDENT("setModelicaPath"),
{Exp.SCONST(str)},false,true),Types.PROP((Types.T_BOOL({}),NONE),Types.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "setCompilerFlags"),{Absyn.STRING(value = str)},{},impl,SOME(st)) then (cache, Exp.CALL(Absyn.IDENT("setCompilerFlags"),{Exp.SCONST(str)},false,
true),Types.PROP((Types.T_BOOL({}),NONE),Types.C_VAR()),SOME(st));
Expand Down
57 changes: 30 additions & 27 deletions Compiler/runtime/settingsimpl.c
Expand Up @@ -5,10 +5,8 @@
#include <malloc.h>

char* compileCommand = 0;
char* installationDirectoryPath = 0;
char* tempDirectoryPath = 0;
char* plotCommand = 0;
char* modelicaPath = 0;
int echo = 1; //true
void Settings_5finit(void)
{
Expand Down Expand Up @@ -79,8 +77,7 @@ RML_BEGIN_LABEL(Settings__setInstallationDirectoryPath)
{
char* command = RML_STRINGDATA(rmlA0);
char* omhome = 0;
if(installationDirectoryPath)
free(installationDirectoryPath);
char* installationDirectoryPath = NULL;

installationDirectoryPath = (char*)malloc(strlen(command)+1);
if (installationDirectoryPath == NULL) {
Expand Down Expand Up @@ -110,17 +107,15 @@ RML_END_LABEL

RML_BEGIN_LABEL(Settings__getInstallationDirectoryPath)
{
if(installationDirectoryPath)
rmlA0 = (void*) mk_scon(strdup(installationDirectoryPath));
else{

char *path = getenv("OPENMODELICAHOME");
if (path == NULL) {
rmlA0 = (void*) mk_scon("");
RML_TAILCALLK(rmlFC);
}
else
rmlA0 = (void*) mk_scon(path);
}

RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
Expand Down Expand Up @@ -154,33 +149,46 @@ RML_END_LABEL
RML_BEGIN_LABEL(Settings__setModelicaPath)
{
char* command = RML_STRINGDATA(rmlA0);
if(modelicaPath)
free(modelicaPath);
char* mmpath;
char* modelicaPath = NULL;

modelicaPath = (char*)malloc(strlen(command)+1);
if (modelicaPath == NULL) {
RML_TAILCALLK(rmlFC);
}
memcpy(modelicaPath,command,strlen(command)+1);

/* create a str of the form: MODELICAPATH=<PATH>*/
mmpath = (char*)malloc(strlen(command)+1+strlen("MODELICAPATH="));
if (mmpath == NULL) {
RML_TAILCALLK(rmlFC);
}
strncpy(mmpath,"MODELICAPATH=",strlen("MODELICAPATH="));
mmpath[strlen("MODELICAPATH=")+1]='\0';
strncat(mmpath,command,strlen(command));
/*set the env-var to created string
this is useful when scripts and clients started
by omc wants to use OPENMODELICAHOME*/
if( putenv(mmpath) != 0) // adrpo: in Linux there is not _putenv if( _putenv(omhome) != 0)
{
RML_TAILCALLK(rmlFC);
}

RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(Settings__getModelicaPath)
{
if(modelicaPath)
rmlA0 = (void*) mk_scon(strdup(modelicaPath));
else{
char *path = getenv("MODELICAPATH");
if (path == NULL) {
rmlA0 = (void*) mk_scon("");
RML_TAILCALLK(rmlFC);
}
else
rmlA0 = (void*) mk_scon(path);
}
RML_TAILCALLK(rmlSC);

char *path = getenv("MODELICAPATH");
if (path == NULL) {
rmlA0 = (void*) mk_scon("");
RML_TAILCALLK(rmlFC);
}
else
rmlA0 = (void*) mk_scon(path);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

Expand All @@ -207,18 +215,13 @@ RML_BEGIN_LABEL(Settings__dumpSettings)
if(compileCommand)
printf("compile command: %s\n",compileCommand);

if(installationDirectoryPath)
printf("installation directory path: %s\n",installationDirectoryPath);

if(tempDirectoryPath)
printf("temp directory path: %s\n",tempDirectoryPath);

if(plotCommand)
printf("plot command: %s\n",plotCommand);

if(modelicaPath)
printf("modelica path: %s\n",modelicaPath);


RML_TAILCALLK(rmlSC);
}
Expand Down
7 changes: 4 additions & 3 deletions Compiler/winruntime/systemimpl.c
Expand Up @@ -490,7 +490,7 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__pathDelimiter)
{
rmlA0 = (void*) mk_scon("\\");
rmlA0 = (void*) mk_scon("/");

RML_TAILCALLK(rmlSC);
}
Expand Down Expand Up @@ -606,7 +606,8 @@ RML_END_LABEL
RML_BEGIN_LABEL(System__readEnv)
{
char* envname = RML_STRINGDATA(rmlA0);
char *envvalue = getenv(envname);
char *envvalue;
envvalue = getenv(envname);
if (envvalue == NULL) {
RML_TAILCALLK(rmlFC);
}
Expand All @@ -624,7 +625,7 @@ RML_BEGIN_LABEL(System__setEnv)
int setenv_result = 0;
char *temp = (char*)malloc(strlen(envname)+strlen(envvalue)+2);
sprintf(temp,"%s=%s", envname, envvalue);
setenv_result = _putenv(temp);
setenv_result = putenv(temp);
rmlA0 = (void*) mk_icon(setenv_result);
RML_TAILCALLK(rmlSC);
}
Expand Down

0 comments on commit 0261fe9

Please sign in to comment.