Add gitlab issue/merge request templates
[src/xds/xds-server.git] / lib / xdsserver / sdks.go
index c006861..1accc60 100644 (file)
@@ -24,8 +24,9 @@ import (
        "strings"
        "sync"
 
-       common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib"
-       "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
+       common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git"
+       "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/xdsconfig"
+       "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/xsapiv1"
 )
 
 // SDKs List of installed SDK
@@ -38,8 +39,8 @@ type SDKs struct {
        stop  chan struct{} // signals intentional stop
 }
 
-// NewSDKs creates a new instance of SDKs
-func NewSDKs(ctx *Context) (*SDKs, error) {
+// SDKsConstructor creates a new instance of SDKs
+func SDKsConstructor(ctx *Context) (*SDKs, error) {
        s := SDKs{
                Context:      ctx,
                Sdks:         make(map[string]*CrossSDK),
@@ -49,7 +50,7 @@ func NewSDKs(ctx *Context) (*SDKs, error) {
 
        scriptsDir := ctx.Config.FileConf.SdkScriptsDir
        if !common.Exists(scriptsDir) {
-               // allow to use scripts/sdk in debug mode
+               // allow to use scripts/sdk when debugging with vscode(EXEPATH=WORKSPACE)
                scriptsDir = filepath.Join(filepath.Dir(ctx.Config.FileConf.SdkScriptsDir), "scripts", "sdks")
                if !common.Exists(scriptsDir) {
                        return &s, fmt.Errorf("scripts directory doesn't exist (%v)", scriptsDir)
@@ -63,6 +64,12 @@ func NewSDKs(ctx *Context) (*SDKs, error) {
                return &s, err
        }
 
+       // Update SDK DB on startup by default (can be disable using config file)
+       update := true
+       if s.Config.FileConf.SdkDbUpdate != "startup" {
+               update = false
+       }
+
        s.mutex.Lock()
        defer s.mutex.Unlock()
 
@@ -73,10 +80,11 @@ func NewSDKs(ctx *Context) (*SDKs, error) {
                        continue
                }
 
-               sdksList, err := ListCrossSDK(d, s.Log)
+               sdksList, err := ListCrossSDK(d, update, s.Log)
                if err != nil {
                        // allow to use XDS even if error on list
                        s.Log.Errorf("Cannot retrieve SDK list: %v", err)
+                       sdksList, _ = ListCrossSDK(d, false, s.Log)
                }
                s.LogSillyf("'%s' SDKs list: %v", d, sdksList)
 
@@ -95,7 +103,7 @@ func NewSDKs(ctx *Context) (*SDKs, error) {
                }
        }
 
-       ctx.Log.Debugf("Cross SDKs: %d defined, %d installed", len(s.Sdks), nbInstalled)
+       ctx.Log.Infof("Cross SDKs: %d defined, %d installed", len(s.Sdks), nbInstalled)
 
        // Start monitor thread to detect new SDKs
        sdksDirs := []string{}
@@ -333,7 +341,7 @@ func (s *SDKs) Install(id, filepath string, force bool, timeout int, args []stri
 
                // Update path when not set
                if sdk.Path == "" {
-                       sdkDef, err := GetSDKInfo(scriptDir, sdk.URL, "", "", s.Log)
+                       sdkDef, err := GetSDKInfo(scriptDir, sdk.URL, "", "", sdk.UUID, s.Log)
                        if err != nil || sdkDef.Path == "" {
                                return nil, fmt.Errorf("cannot retrieve sdk path %v", err)
                        }
@@ -342,14 +350,15 @@ func (s *SDKs) Install(id, filepath string, force bool, timeout int, args []stri
 
        } else if filepath != "" {
                // FIXME support any location and also sharing either by pathmap or Syncthing
-               baseDir := "${HOME}/xds-workspace/sdks"
+
+               baseDir := path.Join(xdsconfig.WorkspaceRootDir(), "sdks")
                sdkFilename, _ = common.ResolveEnvVar(path.Join(baseDir, path.Base(filepath)))
                if !common.Exists(sdkFilename) {
                        return nil, fmt.Errorf("SDK file not accessible, must be in %s", baseDir)
                }
 
                for _, sf := range s.SdksFamilies {
-                       sdkDef, err := GetSDKInfo(sf.ScriptsDir, "", sdkFilename, "", s.Log)
+                       sdkDef, err := GetSDKInfo(sf.ScriptsDir, "", sdkFilename, "", "", s.Log)
                        if err == nil {
                                // OK, sdk found
                                sdk = &sdkDef