Skip to content

Commit

Permalink
Add API for a package manager (#814)
Browse files Browse the repository at this point in the history
* Add API for a package manager

- `installPackage(Buidlings, "6.0.0")`
- `updatePackageIndex()`
- `upgradeInstalledPackages(installNewestVersions=true)`

The `getAvailableLibraries` and `loadModel` APIs no longer look for the
impact binary, and `getAvailableLibraries()` only lists installed
libraries.

Note that `loadModel()` still needs to be updated to do the dependency resolution; the package manager is slightly separate.
  • Loading branch information
sjoelund committed Apr 29, 2020
1 parent d37a91d commit 98d8681
Show file tree
Hide file tree
Showing 22 changed files with 1,334 additions and 76 deletions.
3 changes: 2 additions & 1 deletion .openmodelica.aspell
@@ -1,4 +1,4 @@
personal_ws-1.1 en 74 UTF-8
personal_ws-1.1 en 75 UTF-8
subscripted
UTF
RML
Expand Down Expand Up @@ -72,3 +72,4 @@ evalRecursionLimit
cgraphGraphVizFile
cardinality
URI
SHA
26 changes: 13 additions & 13 deletions Jenkinsfile
Expand Up @@ -46,7 +46,7 @@ pipeline {
stage('gcc') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.13-qt4-xenial'
image 'docker.openmodelica.org/build-deps:v1.16-qt4-xenial'
label 'linux'
alwaysPull true
args "-v /var/lib/jenkins/gitcache:/var/lib/jenkins/gitcache"
Expand All @@ -64,7 +64,7 @@ pipeline {
stage('clang') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.15'
image 'docker.openmodelica.org/build-deps:v1.16'
label 'linux'
alwaysPull true
args "-v /var/lib/jenkins/gitcache:/var/lib/jenkins/gitcache"
Expand Down Expand Up @@ -135,7 +135,7 @@ pipeline {
stage('checks') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.15'
image 'docker.openmodelica.org/build-deps:v1.16'
label 'linux'
alwaysPull true
args "-v /var/lib/jenkins/gitcache:/var/lib/jenkins/gitcache"
Expand Down Expand Up @@ -318,7 +318,7 @@ pipeline {
stage('build-gui-clang-qt5') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.15'
image 'docker.openmodelica.org/build-deps:v1.16'
label 'linux'
alwaysPull true
}
Expand All @@ -334,7 +334,7 @@ pipeline {
stage('build-gui-gcc-qt4') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.13-qt4-xenial'
image 'docker.openmodelica.org/build-deps:v1.16-qt4-xenial'
label 'linux'
alwaysPull true
}
Expand Down Expand Up @@ -387,7 +387,7 @@ pipeline {
stage('testsuite-clang-parmod') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.15'
image 'docker.openmodelica.org/build-deps:v1.16'
label 'linux'
alwaysPull true
// No runtest.db cache necessary; the tests run in serial and do not load libraries!
Expand All @@ -409,7 +409,7 @@ pipeline {
stage('testsuite-clang-metamodelica') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.15'
image 'docker.openmodelica.org/build-deps:v1.16'
label 'linux'
}
}
Expand All @@ -427,7 +427,7 @@ pipeline {
stage('testsuite-matlab-translator') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.15'
image 'docker.openmodelica.org/build-deps:v1.16'
label 'linux'
alwaysPull true
}
Expand All @@ -449,7 +449,7 @@ pipeline {
stage('test-clang-icon-generator') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.15'
image 'docker.openmodelica.org/build-deps:v1.16'
label 'linux'
args "--mount type=volume,source=runtest-clang-icon-generator,target=/cache/runtest " +
"--mount type=volume,source=omlibrary-cache,target=/cache/omlibrary"
Expand Down Expand Up @@ -480,7 +480,7 @@ pipeline {
stage('clang-qt5') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.15'
image 'docker.openmodelica.org/build-deps:v1.16'
label 'linux'
alwaysPull true
}
Expand Down Expand Up @@ -573,7 +573,7 @@ pipeline {
stage('fmuchecker-results') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.15'
image 'docker.openmodelica.org/build-deps:v1.16'
label 'linux'
alwaysPull true
}
Expand All @@ -599,7 +599,7 @@ pipeline {
stage('upload-compliance') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.15'
image 'docker.openmodelica.org/build-deps:v1.16'
label 'linux'
alwaysPull true
}
Expand All @@ -617,7 +617,7 @@ pipeline {
stage('upload-doc') {
agent {
docker {
image 'docker.openmodelica.org/build-deps:v1.15'
image 'docker.openmodelica.org/build-deps:v1.16'
label 'linux'
alwaysPull true
}
Expand Down
4 changes: 4 additions & 0 deletions OMCompiler/COPYING
Expand Up @@ -314,3 +314,7 @@ or online http://opensource.org/licenses/LGPL-2.1.
This product includes software developed by the University of Chicago,
as Operator of Argonne National Laboratory.
Disclaimer: http://www.netlib.org/minpack/disclaimer

Dynamically links against (not exhaustive):

[MIT-like] libcurl
35 changes: 19 additions & 16 deletions OMCompiler/Compiler/FrontEnd/ClassLoader.mo
Expand Up @@ -51,8 +51,8 @@ import Error;
import Flags;
import HashTableStringToProgram;
import List;
import PackageManagement;
import Parser;
import Settings;
import System;
import Testsuite;
import Util;
Expand Down Expand Up @@ -143,28 +143,31 @@ protected
String mp, name, pwd, cmd, version, userLibraries;
Boolean isDir, impactOK;
Absyn.Class cl;
list<String> versionsThatProvideTheWanted, commands;
algorithm
try
(mp,name,isDir) := System.getLoadModelPath(id,prios,mps,requireExactVersion);
else
pwd := System.pwd();
userLibraries := Settings.getHomeDir(Testsuite.isRunning()) + "/.openmodelica/libraries/";
true := System.directoryExists(userLibraries);
true := listMember(userLibraries, mps);
System.cd(userLibraries);
version := match prios
case version::_ guard version <> "default" then version;
else "";
case version::_ then version;
else "default";
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,true);
else
fail();
versionsThatProvideTheWanted := PackageManagement.versionsThatProvideTheWanted(id, version, printError=false);
if not listEmpty(versionsThatProvideTheWanted) then
if version=="default" or version=="" then
commands := {" packageInstall("+id+")"};
else
commands := {
" packageInstall("+id+", \""+version+"\", exactMatch=false)",
" packageInstall("+id+", \""+version+"\", exactMatch="+String(listMember(version,versionsThatProvideTheWanted))+")"
};
end if;
if listHead(versionsThatProvideTheWanted) <> version then
commands := " packageInstall("+id+", \""+listHead(versionsThatProvideTheWanted)+"\", exactMatch=true)" :: commands;
end if;
Error.addMessage(Error.NOTIFY_PKG_FOUND, {stringDelimitList(commands, "\n")});
end if;
fail();
end try;
// print("System.getLoadModelPath: " + id + " {" + stringDelimitList(prios,",") + "} " + stringDelimitList(mps,",") + " => " + mp + " " + name + " " + boolString(isDir));
Config.setLanguageStandardFromMSL(name);
Expand Down
38 changes: 38 additions & 0 deletions OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -3851,6 +3851,44 @@ annotation(
preferredView="text");
end getAvailableLibraries;

function installPackage
input TypeName pkg;
input String version = "";
input Boolean exactMatch = false;
output Boolean result;
external "builtin";
annotation(
Documentation(info="<html>
Installs the package with the best matching version (or only the specified version if exactMatch is given).
To update the index, call <code>updatePackageIndex()</code>.
</html>"),
preferredView="text");
end installPackage;

function updatePackageIndex
output Boolean result;
external "builtin";
annotation(
Documentation(info="<html>
Updates the package index from the internet.
This adds new packages to be able to install or upgrade packages.
To upgrade installed packages, call <code>upgradeInstalledPackages()</code>.
</html>"),
preferredView="text");
end updatePackageIndex;

function upgradeInstalledPackages
input Boolean installNewestVersions = true;
output Boolean result;
external "builtin";
annotation(
Documentation(info="<html>
Upgrades installed packages that have been registered by the package manager.
To update the index, call <code>updatePackageIndex()</code>.
</html>"),
preferredView="text");
end upgradeInstalledPackages;

function getUses
input TypeName pack;
output String[:,:] uses;
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/Global/Global.mo
Expand Up @@ -68,6 +68,7 @@ constant Integer optionSimCode = 24;
constant Integer interactiveCache = 25;
constant Integer isInStream = 26;
constant Integer MMToJLListIndex = 27;
constant Integer packageIndexCacheIndex = 28;

// indexes in System.tick
// ----------------------
Expand Down
45 changes: 45 additions & 0 deletions OMCompiler/Compiler/Parsers/JSON.mo
Expand Up @@ -89,6 +89,12 @@ end FALSE;
record NULL
end NULL;

function emptyObject
output JSON obj;
algorithm
obj := OBJECT({},{},AvlTree.EMPTY());
end emptyObject;

function toString
input JSON value;
output String str;
Expand Down Expand Up @@ -125,6 +131,45 @@ algorithm
value := parse_value_check_empty(tokens);
end parseFile;

function hasKey
input JSON obj;
input String str;
output Boolean b;
algorithm
b := match obj
case OBJECT() then AvlTree.hasKey(obj.dict, str);
end match;
end hasKey;

function get
input JSON obj;
input String str;
output JSON out;
algorithm
out := match obj
case OBJECT() then AvlTree.get(obj.dict, str);
end match;
end get;

function getOrDefault
input JSON obj;
input String str;
input JSON default;
output JSON out;
algorithm
out := matchcontinue obj
case OBJECT() then AvlTree.get(obj.dict, str);
else default;
end matchcontinue;
end getOrDefault;

function getString
input JSON obj;
output String str;
algorithm
JSON.STRING(str) := obj;
end getString;

function parse
input String content;
input String fileName="<String>";
Expand Down

0 comments on commit 98d8681

Please sign in to comment.