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