Skip to content

Commit

Permalink
Slang runner (#228)
Browse files Browse the repository at this point in the history
* #224: Use uuid.UUID instead of string in Def

* #224: Refactor uuid in elementary operators

* #224: Refactor uuid in storage and fs

* #224: Refactor uuid in daemon

* #224: Refactor uuid in makedocs

* #224: Fix tests files

* #224: Remove obsolete tests

* #224: Refactor uuid in slangr

* Close #223: Rename OperatorDef into Blueprint

* #227: Add global logger to project

* #227: Use project logging module in relevant parts of slang

* #227: Run slang operator, log messages and periodical ping

* Remove slangr

* Refactor: Rename Port.Primitive into Port.PrimitiveType

* Fix SlangFileDef.Blueprints

* Implement mode process

* Pass slangFile as arg, too

* Auto trigger operator in process mode

* Close #229: run mode httpPost

* Build slang runner on release

* Refactor SlangBundle and them in slang runner

* Read slangBundle from file and pass it as positional argument

* We need insert the actual operator into the bundle aswell
  • Loading branch information
td5r authored and kairichard committed Jul 22, 2019
1 parent 8e1564a commit 813a296
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 630 deletions.
46 changes: 39 additions & 7 deletions ci/build.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import sys
import time
from os import system, chdir
from os import chdir

from utils import execute_commands

OS = ['darwin', 'linux', 'windows']
ARCHS = ['386', 'amd64']

if __name__ == '__main__':
if len(sys.argv) < 2:
print('Usage: python3 build.py vx.y.z [b6k_cs_pw]')
exit(-1)

version = sys.argv[1]
b6k_cs_pw = sys.argv[2] if len(sys.argv) > 2 else None
def build_slangd(version, b6k_cs_pw):
versioned_dist = 'slangd-' + version.replace('.', '_')
build_time = int(time.time())

Expand Down Expand Up @@ -47,3 +43,39 @@
f"rm {filename_with_ending}",
])
chdir("../..")


def build_slang(version):
versioned_dist = 'slang-' + version.replace('.', '_')

for os in OS:
for arch in ARCHS:
filename_with_ending = filename = f"{versioned_dist}-{os}-{arch}"
if os == 'windows':
filename_with_ending += ".exe"
compress_cmd = f"zip {filename}.zip {filename_with_ending}"
else:
compress_cmd = f"tar -czvf {filename}.tar.gz {filename_with_ending}"

execute_commands([
f"env GOOS={os} GOARCH={arch} go build -o ./ci/release/{filename_with_ending} ./cmd/slang",
])

chdir("./ci/release/")
execute_commands([
compress_cmd,
f"rm {filename_with_ending}",
])
chdir("../..")


if __name__ == '__main__':
if len(sys.argv) < 2:
print('Usage: python3 build.py vx.y.z [b6k_cs_pw]')
exit(-1)

version = sys.argv[1]
b6k_cs_pw = sys.argv[2] if len(sys.argv) > 2 else None

build_slangd(version, b6k_cs_pw)
build_slang(version)
39 changes: 7 additions & 32 deletions cmd/makebundles/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path"

"github.com/Bitspark/slang/pkg/api"
"github.com/Bitspark/slang/pkg/core"
"github.com/Bitspark/slang/pkg/elem"
"github.com/Bitspark/slang/pkg/storage"
Expand All @@ -17,24 +18,17 @@ import (
var libDir string
var outDir string

type SlangBundle struct {
Main string `json:"main"`
Blueprints map[string]*core.Blueprint `json:"blueprints"`
}

func main() {
var showHelp bool
var bundleLib bool
var bundleElems bool

flag.BoolVar(&showHelp, "help", false, "Show this dialog")
flag.StringVar(&libDir, "libdir", "./", "Input location of the standard library files")
flag.StringVar(&outDir, "outdir", "./", "Output location of the bundle files")
flag.BoolVar(&bundleLib, "bundlelib", true, "Bundle standard library")
flag.BoolVar(&bundleElems, "bundleelems", true, "Bundle elementaries")
flag.Parse()

if showHelp {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
os.Exit(0)
Expand Down Expand Up @@ -76,40 +70,21 @@ func main() {
}

func makeBundle(def *core.Blueprint, store *storage.Storage) error {
b := SlangBundle{
Main: def.Id.String(),
}
b.Blueprints = make(map[string]*core.Blueprint)
b, err := api.CreateBundle(def, store)

gatherDependencies(def, &b, store)
if err != nil {
return err
}

opDefJson, err := json.Marshal(&b)
if err != nil {
return err
}

err = ioutil.WriteFile(path.Join(outDir, def.Id.String()+".bundle.json"), opDefJson, os.ModePerm)
err = ioutil.WriteFile(path.Join(outDir, def.Id.String()+".slang.json"), opDefJson, os.ModePerm)
if err != nil {
return err
}

return nil
}

func gatherDependencies(def *core.Blueprint, bundle *SlangBundle, store *storage.Storage) error {
for _, dep := range def.InstanceDefs {
id := dep.Operator
if _, ok := bundle.Blueprints[id.String()]; !ok {
depDef, err := store.Load(id)
if err != nil {
return err
}
bundle.Blueprints[id.String()] = depDef
err = gatherDependencies(depDef, bundle, store)
if err != nil {
return err
}
}
}
return nil
}

0 comments on commit 813a296

Please sign in to comment.