Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Look for libraries in ~/.openmodelica/libraries


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13179 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 4, 2012
1 parent 76dffc1 commit d596b41
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -1171,7 +1171,8 @@ function getModelicaPath "Get the Modelica Library Path."
output String modelicaPath;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://OpenModelica.Scripting.loadModel\">loadModel()</a> for a description of what the MODELICAPATH is used for.
<p>The MODELICAPATH is list of paths to search when trying to <a href=\"modelica://OpenModelica.Scripting.loadModel\">load a library</a>. It is a string separated by colon (:) on all OSes except Windows, which uses semicolon (;).</p>
<p>To override the default path (<a href=\"modelica://OpenModelica.Scripting.getModelicaPath\">getInstallationDirectoryPath()</a>/lib/omlibrary/:~/.openmodelica/libraries/), set the environment variable OPENMODELICALIBRARY=...</p>
</html>"),
preferredView="text");
end getModelicaPath;
Expand Down Expand Up @@ -1691,7 +1692,7 @@ Loads a Modelica library.
<pre><b>loadModel</b>(Modelica,{\"3.2\"})</pre>
</blockquote>
<h4>Description</h4>
<p>loadModel() begins by parsing the getModelicaPath(), and looking for candidate packages to load in the given paths (separated by : or ; depending on OS).</p>
<p>loadModel() begins by parsing the <a href=\"modelica://OpenModelica.Scripting.getModelicaPath\">getModelicaPath()</a>, and looking for candidate packages to load in the given paths (separated by : or ; depending on OS).</p>
<p>The candidate is selected by choosing the one with the highest priority, chosen by looking through the <i>priorityVersion</i> argument to the function.
If the version searched for is \"default\", the following special priority is used: no version name > highest main release > highest pre-release > lexical sort of others (see table below for examples).
If none of the searched versions exist, false is returned and an error is added to the buffer.</p>
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Main/Main.mo
Expand Up @@ -472,7 +472,7 @@ algorithm
case (lib::rest, st as Interactive.SYMBOLTABLE(p,aDep,_,ic,iv,cf,lf))
equation
path = parsePathFromString(lib);
mp = Settings.getModelicaPath();
mp = Settings.getModelicaPath(Config.getRunningTestsuite());
pnew = ClassLoader.loadClass(path, {"default"}, mp, NONE());
pnew = Interactive.updateProgram(pnew, p);
newst = Interactive.SYMBOLTABLE(pnew,aDep,NONE(),ic,iv,cf,lf);
Expand Down
10 changes: 5 additions & 5 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -1224,7 +1224,7 @@ algorithm

case (cache,env,"getModelicaPath",{},st,_)
equation
res = Settings.getModelicaPath();
res = Settings.getModelicaPath(Config.getRunningTestsuite());
then
(cache,Values.STRING(res),st);

Expand Down Expand Up @@ -1737,7 +1737,7 @@ algorithm
Interactive.SYMBOLTABLE(p,sp,ic,iv,(path,t)::cf),
but where to get t? */
equation
mp = Settings.getModelicaPath();
mp = Settings.getModelicaPath(Config.getRunningTestsuite());
strings = List.map(cvars, ValuesUtil.extractValueString);
(p,b) = loadModel({(path,strings)},mp,p,true,b);
str = Print.getString();
Expand Down Expand Up @@ -1973,7 +1973,7 @@ algorithm
equation
vars_1 = {"OPENMODELICAHOME","OPENMODELICALIBRARY","OMC_PATH","OMDEV_PATH","OMC_FOUND","MODELICAUSERCFLAGS","WORKING_DIRECTORY","CREATE_FILE_WORKS","REMOVE_FILE_WORKS","OS","SYSTEM_INFO","RTLIBS","C_COMPILER","C_COMPILER_RESPONDING","HAVE_CORBA","CONFIGURE_CMDLINE"};
omhome = Settings.getInstallationDirectoryPath();
omlib = Settings.getModelicaPath();
omlib = Settings.getModelicaPath(Config.getRunningTestsuite());
omcpath = omhome +& "/bin/omc" +& System.getExeExt();
omdev = Util.makeValueOrDefault(System.readEnv,"OMDEV","");
omcfound = System.regularFileExists(omcpath);
Expand Down Expand Up @@ -2781,7 +2781,7 @@ algorithm
re = Absyn.restrString(restriction);
Error.assertionOrAddSourceMessage(relaxedFrontEnd or not (Absyn.isFunctionRestriction(restriction) or Absyn.isPackageRestriction(restriction)),
Error.INST_INVALID_RESTRICTION,{str,re},Absyn.dummyInfo);
(p,true) = loadModel(Interactive.getUsesAnnotationOrDefault(Absyn.PROGRAM({absynClass},Absyn.TOP(),Absyn.dummyTimeStamp)),Settings.getModelicaPath(),p,false,true);
(p,true) = loadModel(Interactive.getUsesAnnotationOrDefault(Absyn.PROGRAM({absynClass},Absyn.TOP(),Absyn.dummyTimeStamp)),Settings.getModelicaPath(Config.getRunningTestsuite()),p,false,true);

ptot = Dependency.getTotalProgram(className,p);

Expand Down Expand Up @@ -4355,7 +4355,7 @@ protected
String str1,str2,str3;
algorithm
(str1,str2,str3) := System.uriToClassAndPath(uri);
path := getBasePathFromUri(str1,str2,Settings.getModelicaPath(),printError) +& str3;
path := getBasePathFromUri(str1,str2,Settings.getModelicaPath(Config.getRunningTestsuite()),printError) +& str3;
end getFullPathFromUri;

protected function errorToValue
Expand Down
3 changes: 2 additions & 1 deletion Compiler/Util/Settings.mo
Expand Up @@ -94,8 +94,9 @@ public function setModelicaPath
end setModelicaPath;

public function getModelicaPath
input Boolean runningTestsuite;
output String outString;
external "C" outString=Settings_getModelicaPath() annotation(Library = "omcruntime");
external "C" outString=Settings_getModelicaPath(runningTestsuite) annotation(Library = "omcruntime");
end getModelicaPath;

public function getEcho
Expand Down
4 changes: 2 additions & 2 deletions Compiler/runtime/Settings_omc.cpp
Expand Up @@ -48,9 +48,9 @@ extern const char* Settings_getInstallationDirectoryPath()
return strdup(path);
}

extern const char* Settings_getModelicaPath()
extern const char* Settings_getModelicaPath(int runningTestsuite)
{
const char *path = SettingsImpl__getModelicaPath();
const char *path = SettingsImpl__getModelicaPath(runningTestsuite);
if (path == NULL)
MMC_THROW();
return path;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/Settings_rml.c
Expand Up @@ -134,7 +134,7 @@ RML_END_LABEL

RML_BEGIN_LABEL(Settings__getModelicaPath)
{
char *path = SettingsImpl__getModelicaPath();
char *path = SettingsImpl__getModelicaPath(RML_UNTAGFIXNUM(rmlA0));
if (path == NULL)
RML_TAILCALLK(rmlFC);
else
Expand Down
26 changes: 23 additions & 3 deletions Compiler/runtime/settingsimpl.c
Expand Up @@ -42,6 +42,12 @@
#include <malloc.h>
#endif

#if defined(_MSC_VER)
#else
#include <unistd.h>
#include <pwd.h>
#endif

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
Expand Down Expand Up @@ -96,7 +102,7 @@ const char* SettingsImpl__getInstallationDirectoryPath() {
char* winLibPath = NULL;

// Do not free the returned variable. It's malloc'ed
char* SettingsImpl__getModelicaPath() {
char* SettingsImpl__getModelicaPath(int runningTestsuite) {
const char *path = getenv("OPENMODELICALIBRARY");
int i = 0;
if (path == NULL) {
Expand All @@ -105,8 +111,22 @@ char* SettingsImpl__getModelicaPath() {
if (omhome == NULL)
return NULL;
int lenOmhome = strlen(omhome);
char *buffer = (char*) malloc(lenOmhome+100);
snprintf(buffer,lenOmhome+100,"%s/lib/omlibrary",omhome);
char *buffer;
#if !defined(_MSC_VER)
const char *homePath = getenv("HOME");
if (homePath == NULL)
homePath = getpwuid(getuid())->pw_dir;
if (homePath == NULL || runningTestsuite) {
#endif
buffer = (char*) malloc(lenOmhome+100);
snprintf(buffer,lenOmhome+100,"%s/lib/omlibrary",omhome);
#if !defined(_MSC_VER)
} else {
int lenHome = strlen(homePath);
buffer = (char*) malloc(lenOmhome+lenOmhome+100);
snprintf(buffer,lenOmhome+100,"%s/lib/omlibrary:%s/.openmodelica/libraries/",omhome,homePath);
}
#endif
return buffer;
}

Expand Down

0 comments on commit d596b41

Please sign in to comment.