aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crosssdk
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-17 11:28:57 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-17 14:04:32 +0200
commit40a7183f3b4aa32379aa8b4949f5f9c5e32f79f6 (patch)
tree25a98c1b6c6c7b5e186ae3cf0dc11807b2fa088a /lib/crosssdk
parentc07adb807c41a1545a9a0f5bbf40080d86946538 (diff)
Add SDKs support.
Don't allow to install SDKs through XDS for now. Only probe existing SDKs that have been manually installed using scripts/agl/install-agl-sdks.sh. Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/crosssdk')
-rw-r--r--lib/crosssdk/sdk.go47
-rw-r--r--lib/crosssdk/sdks.go39
2 files changed, 86 insertions, 0 deletions
diff --git a/lib/crosssdk/sdk.go b/lib/crosssdk/sdk.go
new file mode 100644
index 0000000..2f22f22
--- /dev/null
+++ b/lib/crosssdk/sdk.go
@@ -0,0 +1,47 @@
+package crosssdk
+
+import (
+ "fmt"
+ "path"
+ "path/filepath"
+)
+
+// SDK Define a cross tool chain used to build application
+type SDK struct {
+ Profile string
+ Version string
+ Arch string
+ Path string
+ EnvFile string
+}
+
+// NewCrossSDK creates a new instance of Syncthing
+func NewCrossSDK(path string) (*SDK, error) {
+ // Assume that we have .../<profile>/<version>/<arch>
+ s := SDK{Path: path}
+
+ s.Arch = filepath.Base(path)
+
+ d := filepath.Dir(path)
+ s.Version = filepath.Base(d)
+
+ d = filepath.Dir(d)
+ s.Profile = filepath.Base(d)
+
+ 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.EnvFile = ef[0]
+
+ return &s, nil
+}
+
+// GetEnvCmd returns the command to initialized the environment to use a cross SDK
+func (s *SDK) GetEnvCmd() string {
+ return ". " + path.Join(s.Path, s.EnvFile)
+}
diff --git a/lib/crosssdk/sdks.go b/lib/crosssdk/sdks.go
new file mode 100644
index 0000000..435aae6
--- /dev/null
+++ b/lib/crosssdk/sdks.go
@@ -0,0 +1,39 @@
+package crosssdk
+
+import (
+ "path"
+ "path/filepath"
+
+ "github.com/Sirupsen/logrus"
+ "github.com/iotbzh/xds-server/lib/common"
+ "github.com/iotbzh/xds-server/lib/xdsconfig"
+)
+
+// SDKs List of installed SDK
+type SDKs []*SDK
+
+// Init creates a new instance of Syncthing
+func Init(cfg *xdsconfig.Config, log *logrus.Logger) (*SDKs, error) {
+ s := SDKs{}
+
+ // Retrieve installed sdks
+ sdkRD := cfg.FileConf.SdkRootDir
+
+ if common.Exists(sdkRD) {
+
+ // Assume that SDK install tree is <rootdir>/<profile>/<version>/<arch>
+ dirs, err := filepath.Glob(path.Join(sdkRD, "*", "*", "*"))
+ if err != nil {
+ log.Debugf("Error while retrieving SDKs: dir=%s, error=%s", sdkRD, err.Error())
+ return &s, err
+ }
+ for _, d := range dirs {
+ sdk, err := NewCrossSDK(d)
+ if err != nil {
+ log.Debugf("Error while processing SDK dir=%s, err=%s", d, err.Error())
+ }
+ s = append(s, sdk)
+ }
+ }
+ return &s, nil
+}