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