sprint1-Installation1.xreate
No OneTemporary

File Metadata

Created
Wed, Jul 8, 11:25 PM

sprint1-Installation1.xreate

import raw ("core/dependencies.lp")
import raw ("core/control-context.lp")
import raw ("core/unit-tests.lp")
InstallationStatus = type variant(NOT_INSTALLED, INSTALLED).
interface(adhoc){
pre function expectNoErrors:: InstallationStatus {
case Error {NOT_INSTALLED}
case Success {INSTALLED}
}
}
interface(extern-c){
libFake = library:: pkgconfig("libxml-2.0").
include {
libFake = ["stdio.h", "stdlib.h"]
}.
}
exec = pre function(comm:: string) {
result = system(comm):: num.
if (result==0)::InstallationStatus
{ad hoc "Success"}
else {ad hoc "Error"}
}
start = function:: int; entry {
context:: goal(artefact(gcc)).
provideGoals()
}
provideGoals = function:: int {
loop context ("goal") {
provideArtefact()
}
}
provideArtefact = function:: int{
switch (actionEXISTS())::int
case INSTALLED {0}
case NOT_INSTALLED {
sequence [
provideDependencies(),
actionPROVIDE()
]
}
case default {-1}
}
provideDependencies = function::int {
rule context:: childs(Child)
case artefact(Item) {
artefact_depends(Item, Child)
}
loop context ("childs") {
provideArtefact()
}
}
case context:: artefact(subversion) {
actionEXISTS = function::int {
context:: expectNoErrors.
exec("svn --version")
}
actionPROVIDE = function::int {
context:: expectNoErrors.
exec("sudo apt-get install subversion")
}
}
actionEXISTS = function::int {
-1
}
actionPROVIDE = function::int {
-1
}
// DRAFT
/*
flagIsProvided = if(dictProvided(<item>)) {true} else
dictProvided = dictProvided + <item>
expectErrorCode = pre function(x::int){
if (x==0)::bool {ad hoc "Success"}
else {ad hoc "Error"}
}
*/

Event Timeline