Add Cross SDKs support (part 2)
[src/xds/xds-server.git] / lib / apiv1 / make.go
index eac6210..fb6435e 100644 (file)
@@ -14,15 +14,16 @@ import (
 // MakeArgs is the parameters (json format) of /make command
 type MakeArgs struct {
        ID         string `json:"id"`
-       RPath      string `json:"rpath"` // relative path into project
-       Args       string `json:"args"`
+       RPath      string `json:"rpath"`   // relative path into project
+       Args       string `json:"args"`    // args to pass to make command
+       SdkID      string `json:"sdkid"`   // sdk ID to use for setting env
        CmdTimeout int    `json:"timeout"` // command completion timeout in Second
 }
 
 // MakeOutMsg Message send on each output (stdout+stderr) of make command
 type MakeOutMsg struct {
        CmdID     string `json:"cmdID"`
-       Timestamp string `json:timestamp`
+       Timestamp string `json:"timestamp"`
        Stdout    string `json:"stdout"`
        Stderr    string `json:"stderr"`
 }
@@ -30,13 +31,15 @@ type MakeOutMsg struct {
 // MakeExitMsg Message send on make command exit
 type MakeExitMsg struct {
        CmdID     string `json:"cmdID"`
-       Timestamp string `json:timestamp`
+       Timestamp string `json:"timestamp"`
        Code      int    `json:"code"`
        Error     error  `json:"error"`
 }
 
-// Event name send in WS
+// MakeOutEvent Event send in WS when characters are received on stdout/stderr
 const MakeOutEvent = "make:output"
+
+// MakeExitEvent Event send in WS when command exited
 const MakeExitEvent = "make:exit"
 
 var makeCommandID = 1
@@ -70,7 +73,7 @@ func (s *APIService) buildMake(c *gin.Context) {
                return
        }
 
-       prj := s.cfg.GetFolderFromID(id)
+       prj := s.mfolder.GetFolderFromID(id)
        if prj == nil {
                common.APIError(c, "Unknown id")
                return
@@ -136,6 +139,11 @@ func (s *APIService) buildMake(c *gin.Context) {
        cmdID := makeCommandID
        makeCommandID++
 
+       // Retrieve env command regarding Sdk ID
+       if envCmd := s.sdks.GetEnvCmd(args.SdkID, prj.DefaultSdk); envCmd != "" {
+               cmd = envCmd + " && " + cmd
+       }
+
        s.log.Debugf("Execute [Cmd ID %d]: %v", cmdID, cmd)
        err := common.ExecPipeWs(cmd, sop, sess.ID, cmdID, execTmo, s.log, oCB, eCB)
        if err != nil {