Defined structures for /exec and /signal response.
[src/xds/xds-server.git] / lib / crosssdk / sdk.go
1 package crosssdk
2
3 import (
4         "fmt"
5         "path/filepath"
6
7         uuid "github.com/satori/go.uuid"
8 )
9
10 // SDK Define a cross tool chain used to build application
11 type SDK struct {
12         ID      string `json:"id" binding:"required"`
13         Name    string `json:"name"`
14         Profile string `json:"profile"`
15         Version string `json:"version"`
16         Arch    string `json:"arch"`
17         Path    string `json:"path"`
18
19         // Not exported fields
20         EnvFile string `json:"-"`
21 }
22
23 // NewCrossSDK creates a new instance of Syncthing
24 func NewCrossSDK(path string) (*SDK, error) {
25         // Assume that we have .../<profile>/<version>/<arch>
26         s := SDK{Path: path}
27
28         s.Arch = filepath.Base(path)
29
30         d := filepath.Dir(path)
31         s.Version = filepath.Base(d)
32
33         d = filepath.Dir(d)
34         s.Profile = filepath.Base(d)
35
36         // Use V3 to ensure that we get same uuid on restart
37         s.ID = uuid.NewV3(uuid.FromStringOrNil("sdks"), s.Profile+"_"+s.Arch+"_"+s.Version).String()
38         s.Name = s.Arch + "  (" + s.Version + ")"
39
40         envFile := filepath.Join(path, "environment-setup*")
41         ef, err := filepath.Glob(envFile)
42         if err != nil {
43                 return nil, fmt.Errorf("Cannot retrieve environment setup file: %v", err)
44         }
45         if len(ef) != 1 {
46                 return nil, fmt.Errorf("No environment setup file found match %s", envFile)
47         }
48         s.EnvFile = ef[0]
49
50         return &s, nil
51 }
52
53 // GetEnvCmd returns the command used to initialized the environment
54 func (s *SDK) GetEnvCmd() []string {
55         return []string{"source", s.EnvFile}
56 }