Skip to content

Commit

Permalink
During loadModel, use the impact command if the user has impact i…
Browse files Browse the repository at this point in the history
…nstalled

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23693 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Dec 8, 2014
1 parent 9e90ddc commit da5bbac
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 14 deletions.
27 changes: 24 additions & 3 deletions Compiler/FrontEnd/ClassLoader.mo
Expand Up @@ -53,6 +53,7 @@ import Flags;
import HashTableStringToProgram;
import List;
import Parser;
import Settings;
import System;
import Util;

Expand Down Expand Up @@ -149,11 +150,31 @@ protected function loadClassFromMps
input Option<String> encoding;
output Absyn.Program outProgram;
protected
String mp,name;
Boolean isDir;
String mp, name, pwd, cmd, version, userLibraries;
Boolean isDir, impactOK;
Absyn.Class cl;
algorithm
(mp,name,isDir) := System.getLoadModelPath(id,prios,mps);
try
(mp,name,isDir) := System.getLoadModelPath(id,prios,mps);
else
pwd := System.pwd();
userLibraries := Settings.getHomeDir(Config.getRunningTestsuiteFile()<>"") + "/.openmodelica/libraries/";
true := System.directoryExists(userLibraries);
System.cd(userLibraries);
version := match prios
case version::_ guard version <> "default" then version;
else "";
end match;
cmd := "impact install \"" + id + (if version<>"" then "#" + version else "") + "\"";
impactOK := 0==System.systemCall(cmd, "/dev/null");
System.cd(pwd);
if impactOK then
Error.addMessage(Error.NOTIFY_IMPACT_FOUND, {id, (if version <> "" then (" "+version) else ""), userLibraries});
(mp,name,isDir) := System.getLoadModelPath(id,prios,mps);
else
fail();
end if;
end try;
// print("System.getLoadModelPath: " + id + " {" + stringDelimitList(prios,",") + "} " + stringDelimitList(mps,",") + " => " + mp + " " + name + " " + boolString(isDir));
Config.setLanguageStandardFromMSL(name);
cl := loadClassFromMp(id, mp, name, isDir, encoding);
Expand Down
3 changes: 2 additions & 1 deletion Compiler/Util/Error.mo
Expand Up @@ -673,7 +673,8 @@ public constant Message ENUM_DUPLICATES = MESSAGE(253, TRANSLATION(), ERROR(),
Util.gettext("Enumeration has duplicate names: %s in list of names %s."));
public constant Message RESERVED_IDENTIFIER = MESSAGE(254, TRANSLATION(), ERROR(),
Util.gettext("Identifier %s is reserved for the built-in type with the same name."));

public constant Message NOTIFY_IMPACT_FOUND = MESSAGE(255, SCRIPTING(), NOTIFICATION(),
Util.gettext("The impact package manager downloaded package %s%s to directory %s."));

public constant Message UNBOUND_PARAMETER_WITH_START_VALUE_WARNING = MESSAGE(499, TRANSLATION(), WARNING(),
Util.gettext("Parameter %s has no value, and is fixed during initialization (fixed=true), using available start value (start=%s) as default value."));
Expand Down
6 changes: 6 additions & 0 deletions Compiler/Util/Settings.mo
Expand Up @@ -100,6 +100,12 @@ public function getModelicaPath
external "C" outString=Settings_getModelicaPath(runningTestsuite) annotation(Library = "omcruntime");
end getModelicaPath;

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

public function getEcho
output Integer echo;
external "C" echo=Settings_getEcho() annotation(Library = "omcruntime");
Expand Down
4 changes: 2 additions & 2 deletions Compiler/runtime/ErrorMessage.cpp
Expand Up @@ -105,7 +105,7 @@ std::string ErrorMessage::getMessage_(int warningsAsErrors)
return "";
}
message_.replace(str_pos, 2, *tok);
str_pos += tok->size() + 1;
str_pos += tok->size();
*tok++;
} else if(index_symbol >= '0' || index_symbol <= '9') {
index = index_symbol - '0' - 1;
Expand All @@ -118,7 +118,7 @@ std::string ErrorMessage::getMessage_(int warningsAsErrors)
}

message_.replace(str_pos, 2, tokens_[index]);
str_pos += tokens_[index].size() + 1;
str_pos += tokens_[index].size();
}
}
veryshort_msg = message_;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/Settings_omc.cpp
Expand Up @@ -46,7 +46,7 @@ extern const char* Settings_getInstallationDirectoryPath()
const char *path = SettingsImpl__getInstallationDirectoryPath();
if (path == NULL)
MMC_THROW();
return strcpy(ModelicaAllocateString(strlen(path)), path);
return path;
}

extern const char* Settings_getModelicaPath(int runningTestsuite)
Expand Down
27 changes: 20 additions & 7 deletions Compiler/runtime/settingsimpl.c
Expand Up @@ -188,6 +188,21 @@ const char* SettingsImpl__getInstallationDirectoryPath(void) {

char* winLibPath = NULL;

char* Settings_getHomeDir(int runningTestsuite)
{
const char *homePath = NULL;
#if !(defined(_MSC_VER) || defined(__MINGW32__))
homePath = getenv("HOME");
if (homePath == NULL) {
homePath = getpwuid(getuid())->pw_dir;
}
#endif
if (homePath == NULL || runningTestsuite) {
return "";
}
return GC_strdup(homePath);
}

// Do not free the returned variable. It's malloc'ed
char* SettingsImpl__getModelicaPath(int runningTestsuite) {
const char *path = getenv("OPENMODELICALIBRARY");
Expand All @@ -200,17 +215,15 @@ char* SettingsImpl__getModelicaPath(int runningTestsuite) {
int lenOmhome = strlen(omhome);
char *buffer;
#if !(defined(_MSC_VER) || defined(__MINGW32__))
const char *homePath = getenv("HOME");
if (homePath == NULL)
homePath = getpwuid(getuid())->pw_dir;
const char *homePath = Settings_getHomeDir(runningTestsuite);
if (homePath == NULL || runningTestsuite) {
#endif
buffer = (char*) malloc(lenOmhome+15);
snprintf(buffer,lenOmhome+15,"%s/lib/omlibrary",omhome);
#if !(defined(_MSC_VER) || defined(__MINGW32__))
} else {
int lenHome = strlen(homePath);
buffer = (char*) malloc(lenOmhome+lenHome+41);
buffer = (char*) GC_malloc_atomic(lenOmhome+lenHome+41);
snprintf(buffer,lenOmhome+lenHome+41,"%s/lib/omlibrary:%s/.openmodelica/libraries/",omhome,homePath);
}
#endif
Expand All @@ -220,11 +233,11 @@ char* SettingsImpl__getModelicaPath(int runningTestsuite) {
#if defined(__MINGW32__) || defined(_MSC_VER)
/* adrpo: translate this to forward slashes! */
/* duplicate the path */
winLibPath = strdup(path);
winLibPath = GC_strdup(path);

/* ?? not enough memory for duplication */
if (!winLibPath)
return strdup(path);
return GC_strdup(path);

/* convert \\ to / */
while(winLibPath[i] != '\0')
Expand All @@ -235,7 +248,7 @@ char* SettingsImpl__getModelicaPath(int runningTestsuite) {
return winLibPath;
#endif

return strdup(path);
return GC_strdup(path);
}

static const char* SettingsImpl__getCompileCommand(void)
Expand Down

0 comments on commit da5bbac

Please sign in to comment.