10 "github.com/Sirupsen/logrus"
11 common "github.com/iotbzh/xds-common/golib"
12 "github.com/iotbzh/xds-server/lib/xdsconfig"
15 // SDKs List of installed SDK
22 // Init creates a new instance of Syncthing
23 func Init(cfg *xdsconfig.Config, log *logrus.Logger) (*SDKs, error) {
25 Sdks: make(map[string]*SDK),
28 // Retrieve installed sdks
29 sdkRD := cfg.FileConf.SdkRootDir
31 if common.Exists(sdkRD) {
33 // Assume that SDK install tree is <rootdir>/<profile>/<version>/<arch>
34 dirs, err := filepath.Glob(path.Join(sdkRD, "*", "*", "*"))
36 log.Debugf("Error while retrieving SDKs: dir=%s, error=%s", sdkRD, err.Error())
40 defer s.mutex.Unlock()
42 for _, d := range dirs {
46 sdk, err := NewCrossSDK(d)
48 log.Debugf("Error while processing SDK dir=%s, err=%s", d, err.Error())
55 log.Debugf("SDKs: %d cross sdks found", len(s.Sdks))
60 // ResolveID Complete an SDK ID (helper for user that can use partial ID value)
61 func (s *SDKs) ResolveID(id string) (string, error) {
67 for iid := range s.Sdks {
68 fmt.Printf("SEB prefix iid=%v id=%v\n", iid, id)
69 if strings.HasPrefix(iid, id) {
70 match = append(match, iid)
71 fmt.Printf(" SEB match (%d): %v\n", len(match), match)
74 fmt.Printf("SEB match (%d): %v\n", len(match), match)
78 } else if len(match) == 0 {
79 return id, fmt.Errorf("Unknown id")
81 return id, fmt.Errorf("Multiple IDs found with provided prefix: " + id)
84 // Get returns an SDK from id
85 func (s *SDKs) Get(id string) *SDK {
87 defer s.mutex.Unlock()
89 sc, exist := s.Sdks[id]
96 // GetAll returns all existing SDKs
97 func (s *SDKs) GetAll() []SDK {
99 defer s.mutex.Unlock()
101 for _, v := range s.Sdks {
102 res = append(res, *v)
107 // GetEnvCmd returns the command used to initialized the environment for an SDK
108 func (s *SDKs) GetEnvCmd(id string, defaultID string) []string {
109 if id == "" && defaultID == "" {
115 defer s.mutex.Unlock()
117 if sdk, exist := s.Sdks[id]; exist {
118 return sdk.GetEnvCmd()
121 if sdk, exist := s.Sdks[defaultID]; defaultID != "" && exist {
122 return sdk.GetEnvCmd()
125 // Return default env that may be empty