8 "github.com/Sirupsen/logrus"
9 "github.com/iotbzh/xds-server/lib/common"
10 "github.com/iotbzh/xds-server/lib/xdsconfig"
13 // SDKs List of installed SDK
20 // Init creates a new instance of Syncthing
21 func Init(cfg *xdsconfig.Config, log *logrus.Logger) (*SDKs, error) {
24 // Retrieve installed sdks
25 sdkRD := cfg.FileConf.SdkRootDir
27 if common.Exists(sdkRD) {
29 // Assume that SDK install tree is <rootdir>/<profile>/<version>/<arch>
30 dirs, err := filepath.Glob(path.Join(sdkRD, "*", "*", "*"))
32 log.Debugf("Error while retrieving SDKs: dir=%s, error=%s", sdkRD, err.Error())
36 defer s.mutex.Unlock()
38 for _, d := range dirs {
39 sdk, err := NewCrossSDK(d)
41 log.Debugf("Error while processing SDK dir=%s, err=%s", d, err.Error())
44 s.Sdks = append(s.Sdks, *sdk)
48 log.Debugf("SDKs: %d cross sdks found", len(s.Sdks))
53 // GetAll returns all existing SDKs
54 func (s *SDKs) GetAll() []SDK {
56 defer s.mutex.Unlock()
61 // Get returns an SDK from id
62 func (s *SDKs) Get(id int) SDK {
64 defer s.mutex.Unlock()
66 if id < 0 || id > len(s.Sdks) {
73 // GetEnvCmd returns the command used to initialized the environment for an SDK
74 func (s *SDKs) GetEnvCmd(id string, defaultID string) []string {
75 if id == "" && defaultID == "" {
81 defer s.mutex.Unlock()
82 defaultEnv := []string{}
83 for _, sdk := range s.Sdks {
85 return sdk.GetEnvCmd()
87 if sdk.ID == defaultID {
88 defaultEnv = sdk.GetEnvCmd()
91 // Return default env that may be empty