From 2f7828d01f4c4ca2909f95f098627cd5475ed225 Mon Sep 17 00:00:00 2001 From: Sebastien Douheret Date: Wed, 29 Nov 2017 08:54:00 +0100 Subject: Refit source files to have a public xs-apiv1 lib package. Signed-off-by: Sebastien Douheret --- lib/crosssdk/sdk.go | 56 ----------------------- lib/crosssdk/sdks.go | 126 --------------------------------------------------- 2 files changed, 182 deletions(-) delete mode 100644 lib/crosssdk/sdk.go delete mode 100644 lib/crosssdk/sdks.go (limited to 'lib/crosssdk') diff --git a/lib/crosssdk/sdk.go b/lib/crosssdk/sdk.go deleted file mode 100644 index 5be8954..0000000 --- a/lib/crosssdk/sdk.go +++ /dev/null @@ -1,56 +0,0 @@ -package crosssdk - -import ( - "fmt" - "path/filepath" - - uuid "github.com/satori/go.uuid" -) - -// SDK Define a cross tool chain used to build application -type SDK struct { - ID string `json:"id" binding:"required"` - Name string `json:"name"` - Profile string `json:"profile"` - Version string `json:"version"` - Arch string `json:"arch"` - Path string `json:"path"` - - // Not exported fields - EnvFile string `json:"-"` -} - -// NewCrossSDK creates a new instance of Syncthing -func NewCrossSDK(path string) (*SDK, error) { - // Assume that we have .../// - 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) - - // Use V3 to ensure that we get same uuid on restart - s.ID = uuid.NewV3(uuid.FromStringOrNil("sdks"), s.Profile+"_"+s.Arch+"_"+s.Version).String() - s.Name = s.Arch + " (" + s.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.EnvFile = ef[0] - - return &s, nil -} - -// GetEnvCmd returns the command used to initialized the environment -func (s *SDK) GetEnvCmd() []string { - return []string{"source", s.EnvFile} -} diff --git a/lib/crosssdk/sdks.go b/lib/crosssdk/sdks.go deleted file mode 100644 index a3da184..0000000 --- a/lib/crosssdk/sdks.go +++ /dev/null @@ -1,126 +0,0 @@ -package crosssdk - -import ( - "fmt" - "path" - "path/filepath" - "strings" - "sync" - - "github.com/Sirupsen/logrus" - common "github.com/iotbzh/xds-common/golib" - "github.com/iotbzh/xds-server/lib/xdsconfig" -) - -// SDKs List of installed SDK -type SDKs struct { - Sdks map[string]*SDK - - mutex sync.Mutex -} - -// Init creates a new instance of Syncthing -func Init(cfg *xdsconfig.Config, log *logrus.Logger) (*SDKs, error) { - s := SDKs{ - Sdks: make(map[string]*SDK), - } - - // Retrieve installed sdks - sdkRD := cfg.FileConf.SdkRootDir - - if common.Exists(sdkRD) { - - // Assume that SDK install tree is /// - 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 - } - s.mutex.Lock() - defer s.mutex.Unlock() - - for _, d := range dirs { - if !common.IsDir(d) { - continue - } - sdk, err := NewCrossSDK(d) - if err != nil { - log.Debugf("Error while processing SDK dir=%s, err=%s", d, err.Error()) - continue - } - s.Sdks[sdk.ID] = sdk - } - } - - log.Debugf("SDKs: %d cross sdks found", len(s.Sdks)) - - return &s, nil -} - -// ResolveID Complete an SDK ID (helper for user that can use partial ID value) -func (s *SDKs) ResolveID(id string) (string, error) { - if id == "" { - return "", nil - } - - match := []string{} - for iid := range s.Sdks { - if strings.HasPrefix(iid, id) { - match = append(match, iid) - } - } - - if len(match) == 1 { - return match[0], nil - } else if len(match) == 0 { - return id, fmt.Errorf("Unknown sdk id") - } - return id, fmt.Errorf("Multiple sdk IDs found with provided prefix: " + id) -} - -// Get returns an SDK from id -func (s *SDKs) Get(id string) *SDK { - s.mutex.Lock() - defer s.mutex.Unlock() - - sc, exist := s.Sdks[id] - if !exist { - return nil - } - return sc -} - -// GetAll returns all existing SDKs -func (s *SDKs) GetAll() []SDK { - s.mutex.Lock() - defer s.mutex.Unlock() - res := []SDK{} - for _, v := range s.Sdks { - res = append(res, *v) - } - return res -} - -// GetEnvCmd returns the command used to initialized the environment for an SDK -func (s *SDKs) GetEnvCmd(id string, defaultID string) []string { - if id == "" && defaultID == "" { - // no env cmd - return []string{} - } - - s.mutex.Lock() - defer s.mutex.Unlock() - - if iid, err := s.ResolveID(id); err == nil { - if sdk, exist := s.Sdks[iid]; exist { - return sdk.GetEnvCmd() - } - } - - if sdk, exist := s.Sdks[defaultID]; defaultID != "" && exist { - return sdk.GetEnvCmd() - } - - // Return default env that may be empty - return []string{} -} -- cgit 1.2.3-korg