@@ -332,6 +332,7 @@ func (ss *SSHServer) legacyIncomingSSHPostAuth(s gssh.Session, rb *Buildlet) {
332
332
}
333
333
}()
334
334
go func () {
335
+ ss .setupRemoteSSHEnv (bconf , workDir , f )
335
336
io .Copy (f , s ) // stdin
336
337
}()
337
338
io .Copy (s , f ) // stdout
@@ -476,13 +477,39 @@ func (ss *SSHServer) IncomingSSHPostAuth(s gssh.Session, rs *Session) {
476
477
}
477
478
}()
478
479
go func () {
480
+ ss .setupRemoteSSHEnv (bconf , workDir , f )
479
481
io .Copy (f , s ) // stdin
480
482
}()
481
483
io .Copy (s , f ) // stdout
482
484
cmd .Process .Kill ()
483
485
cmd .Wait ()
484
486
}
485
487
488
+ // setupRemoteSSHEnv sets up environment variables on the remote system.
489
+ // This makes the new SSH session easier to use for Go testing.
490
+ func (ss * SSHServer ) setupRemoteSSHEnv (bconf * dashboard.BuildConfig , workDir string , f io.Writer ) {
491
+ switch bconf .GOOS () {
492
+ default :
493
+ // A Unix system.
494
+ for _ , env := range bconf .Env () {
495
+ fmt .Fprintln (f , env )
496
+ }
497
+ fmt .Fprintf (f , "GOPATH=%s/gopath\n " , workDir )
498
+ fmt .Fprintf (f , "PATH=$PATH:%s/go/bin\n " , workDir )
499
+ fmt .Fprintf (f , "export GOPATH PATH\n " )
500
+ fmt .Fprintf (f , "cd %s/go/src\n " , workDir )
501
+ case "windows" :
502
+ for _ , env := range bconf .Env () {
503
+ fmt .Fprintf (f , "set %s\n " , env )
504
+ }
505
+ fmt .Fprintf (f , `set GOPATH=%s\gopath` + "\n " , workDir )
506
+ fmt .Fprintf (f , `set PATH=$PATH;%s\go\bin` + "\n " , workDir )
507
+ fmt .Fprintf (f , `cd %s\go\src` + "\n " , workDir )
508
+ case "plan9" :
509
+ // TODO
510
+ }
511
+ }
512
+
486
513
// WriteSSHPrivateKeyToTempFile writes a key to a temporary file on the local file system. It also
487
514
// sets the permissions on the file to what is expected by OpenSSH implementations of SSH.
488
515
func WriteSSHPrivateKeyToTempFile (key []byte ) (path string , err error ) {
0 commit comments