X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fxds%2Fxds-gdb.git;a=blobdiff_plain;f=main.go;h=b193676c7daf455462dba242a8028278c8253716;hp=81b9154a38260d09cad6912a6146173287bbbfac;hb=b79e2a08a58bef2121463ecaa8e902be7850ccc7;hpb=295f712b2d3838b6576bd7ed12dbf7cf7c9e1e4f diff --git a/main.go b/main.go index 81b9154..b193676 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 "IoT.bzh" + * Copyright (C) 2017-2018 "IoT.bzh" * Author Sebastien Douheret * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,9 +34,9 @@ import ( "path" + common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib" "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" - common "github.com/iotbzh/xds-common/golib" "github.com/joho/godotenv" ) @@ -58,11 +58,11 @@ var AppSubVersion = "unknown-dev" // Create logger var log = logrus.New() -var logFileInitial = "/tmp/xds-gdb.log" +var logFileInitial = path.Join(os.TempDir(), "xds-gdb.log") // Application details const ( - appCopyright = "Copyright (C) 2017 IoT.bzh - Apache-2.0" + appCopyright = "Copyright (C) 2017-2018 IoT.bzh - Apache-2.0" defaultLogLevel = "warning" ) @@ -90,7 +90,8 @@ func exitError(code syscall.Errno, f string, a ...interface{}) { // main func main() { - var uri, prjID, rPath, logLevel, logFile, sdkid, confFile, gdbNative string + var agentURL, serverURL string + var prjID, rPath, logLevel, logFile, sdkid, confFile, gdbNative string var listProject bool var err error @@ -99,14 +100,15 @@ func main() { logFile = logFileInitial fdL, err := os.OpenFile(logFileInitial, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666) if err != nil { - msgErr := fmt.Sprintf("Cannot create log file %s", logFileInitial) - exitError(syscall.EPERM, msgErr) + fmt.Printf("WARNING: Cannot create initial log file %s\n", logFileInitial) + log.Level = logrus.WarnLevel + } else { + log.Out = fdL + log.Level = logrus.DebugLevel } log.Formatter = &logrus.TextFormatter{} - log.Out = fdL - log.Level = logrus.DebugLevel - uri = "localhost:8000" + agentURL = "localhost:8800" logLevel = defaultLogLevel // Create a new App instance @@ -165,10 +167,15 @@ func main() { Usage: "Cross Sdk ID to use to build project", Destination: &sdkid, }, + EnvVar{ + Name: "XDS_AGENT_URL", + Usage: "local XDS agent url", + Destination: &agentURL, + }, EnvVar{ Name: "XDS_SERVER_URL", - Usage: "remote XDS server url", - Destination: &uri, + Usage: "overwrite remote XDS server url (default value set in xds-agent-config.json file)", + Destination: &serverURL, }, } @@ -295,7 +302,8 @@ endloop: gdb = NewGdbNative(log, gdbArgs, env) } else { gdb = NewGdbXds(log, gdbArgs, env) - gdb.SetConfig("uri", uri) + gdb.SetConfig("agentURL", agentURL) + gdb.SetConfig("serverURL", serverURL) gdb.SetConfig("prjID", prjID) gdb.SetConfig("sdkID", sdkid) gdb.SetConfig("rPath", rPath) @@ -333,7 +341,13 @@ endloop: }) gdb.OnDisconnect(func(err error) { - fmt.Println("Disconnection: ", err.Error()) + errMsg := "\nXDS-Agent disconnected" + if err != nil { + fmt.Printf("%s: %v\n", errMsg, err.Error()) + } else { + fmt.Println(errMsg) + } + exitChan <- exitResult{err, int(syscall.ESHUTDOWN)} }) @@ -343,8 +357,14 @@ endloop: log.Debugf("Recv OUT: <%s>", stdout) } if stderr != "" { - fmt.Fprintf(os.Stderr, "%s", stderr) - log.Debugf("Recv ERR: <%s>", stderr) + // Filter-out ugly message (python error when cross gdb exited) + if !strings.Contains(stderr, "readline.write_history_file") && + !(strings.Contains(stderr, "Traceback") && strings.Contains(stderr, "__exithandler")) { + fmt.Fprintf(os.Stderr, "%s", stderr) + log.Debugf("Recv ERR: <%s>", stderr) + } else { + log.Debugf("Recv ERR (FILTERED OUT): <%s>", stderr) + } } // Correctly report error about init file @@ -454,8 +474,8 @@ endloop: time.Sleep(time.Millisecond * 200) } - gdb.Write(command + "\n") log.Debugf("Send: <%v>", command) + gdb.Write(command + "\n") } log.Infof("Stdin scanner exit, close stdin (err=%v)", sc.Err()) @@ -574,9 +594,9 @@ func loadConfigEnvFile(confFile, gdbCmdFile string) (map[string]string, string, All commented lines (#) in gdb command file that start with ':XDS-ENV:' prefix will be considered as XDS env commands. For example the 3 syntaxes below are supported: - # :XDS-ENV: XDS_PROJECT_ID=IW7B4EE-DBY4Z74_myProject - #:XDS-ENV:XDS_SDK_ID=poky-agl_aarch64_3.99.1+snapshot - # :XDS-ENV: export XDS_SERVER_URL=localhost:8800 + # :XDS-ENV: XDS_PROJECT_ID=4021617e-ced0-11e7-acd2-3c970e49ad9b + #:XDS-ENV:XDS_SDK_ID=06c0e95a-e215-3a5a-b373-f677c0dabd3b + # :XDS-ENV: export XDS_AGENT_URL=localhost:8800 */ func extractEnvFromCmdFile(cmdFile string) (string, error) { if !common.Exists(cmdFile) {