aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xdsserver/sdk.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-11-29 08:54:00 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-11-29 11:10:30 +0100
commit2f7828d01f4c4ca2909f95f098627cd5475ed225 (patch)
treeb5e71920b813b95cae3e32044be08b99223348ec /lib/xdsserver/sdk.go
parent5caebfb4b7c3b73988f067082b219ce5b7f409ba (diff)
Refit source files to have a public xs-apiv1 lib package.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xdsserver/sdk.go')
-rw-r--r--lib/xdsserver/sdk.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/xdsserver/sdk.go b/lib/xdsserver/sdk.go
new file mode 100644
index 0000000..c0acb24
--- /dev/null
+++ b/lib/xdsserver/sdk.go
@@ -0,0 +1,56 @@
+package xdsserver
+
+import (
+ "fmt"
+ "path/filepath"
+
+ "github.com/iotbzh/xds-server/lib/xsapiv1"
+ uuid "github.com/satori/go.uuid"
+)
+
+// CrossSDK Hold SDK config
+type CrossSDK struct {
+ sdk xsapiv1.SDK
+}
+
+// NewCrossSDK creates a new instance of Syncthing
+func NewCrossSDK(path string) (*CrossSDK, error) {
+ // Assume that we have .../<profile>/<version>/<arch>
+ s := CrossSDK{
+ sdk: xsapiv1.SDK{Path: path},
+ }
+
+ s.sdk.Arch = filepath.Base(path)
+
+ d := filepath.Dir(path)
+ s.sdk.Version = filepath.Base(d)
+
+ d = filepath.Dir(d)
+ s.sdk.Profile = filepath.Base(d)
+
+ // Use V3 to ensure that we get same uuid on restart
+ s.sdk.ID = uuid.NewV3(uuid.FromStringOrNil("sdks"), s.sdk.Profile+"_"+s.sdk.Arch+"_"+s.sdk.Version).String()
+ s.sdk.Name = s.sdk.Arch + " (" + s.sdk.Version + ")"
+
+ envFile := filepath.Join(path, "environment-setup*")
+ ef, err := filepath.Glob(envFile)
+ if err != nil {
+ return nil, fmt.Errorf("Cannot retrieve environment setup file: %v", err)
+ }
+ if len(ef) != 1 {
+ return nil, fmt.Errorf("No environment setup file found match %s", envFile)
+ }
+ s.sdk.EnvFile = ef[0]
+
+ return &s, nil
+}
+
+// Get Return SDK definition
+func (s *CrossSDK) Get() *xsapiv1.SDK {
+ return &s.sdk
+}
+
+// GetEnvCmd returns the command used to initialized the environment
+func (s *CrossSDK) GetEnvCmd() []string {
+ return []string{"source", s.sdk.EnvFile}
+}