From d1cb2ced74a0ff064ff30f794a9903193a6bde64 Mon Sep 17 00:00:00 2001 From: paopaol <467847281@qq.com> Date: Fri, 27 May 2022 10:06:34 +0800 Subject: [PATCH] fix: some -D read error --- sln/project.go | 26 ++++++++++++-------------- sln/sln.go | 36 +++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/sln/project.go b/sln/project.go index 4cc0a35..d0f5af6 100644 --- a/sln/project.go +++ b/sln/project.go @@ -2,13 +2,13 @@ package sln import ( "encoding/xml" - "path/filepath" - "os" - "io/ioutil" - "strings" - "fmt" "errors" + "fmt" + "io/ioutil" + "os" + "path/filepath" "regexp" + "strings" ) type Project struct { @@ -55,15 +55,15 @@ type CompileCommand struct { File string `json:"file"` } - var badInclude = []string{ ";%(AdditionalIncludeDirectories)", + "%(AdditionalIncludeDirectories);", } var badDef = []string{ ";%(PreprocessorDefinitions)", + "%(PreprocessorDefinitions);", } - func NewProject(path string) (Project, error) { var pro Project var err error @@ -87,7 +87,6 @@ func NewProject(path string) (Project, error) { return pro, nil } - //return include, definition,error func (pro *Project) FindConfig(conf string) (string, string, error) { var cfgList []ProjectConfiguration @@ -120,12 +119,12 @@ func (pro *Project) FindConfig(conf string) (string, string, error) { platform := vlist[1] willReplaceEnv := map[string]string{ - "$(ProjectDir)": pro.ProjectDir, - "$(Configuration)": configuration, + "$(ProjectDir)": pro.ProjectDir, + "$(Configuration)": configuration, "$(ConfigurationName)": configuration, - "$(Platform)": platform, + "$(Platform)": platform, } - for _,v := range os.Environ(){ + for _, v := range os.Environ() { kv := strings.Split(v, "=") willReplaceEnv[fmt.Sprintf("$(%s)", kv[0])] = kv[1] } @@ -163,7 +162,6 @@ func (pro *Project) FindSourceFiles() []string { return fileList } - func RemoveBadInclude(include string) string { for _, bad := range badInclude { include = strings.Replace(include, bad, ";.", -1) @@ -176,4 +174,4 @@ func RemoveBadDefinition(def string) string { def = strings.Replace(def, bad, "", -1) } return def -} \ No newline at end of file +} diff --git a/sln/sln.go b/sln/sln.go index d8c30e1..23af9d1 100644 --- a/sln/sln.go +++ b/sln/sln.go @@ -1,13 +1,13 @@ package sln import ( - "path/filepath" - "os" - "io/ioutil" - "strings" - "fmt" "errors" + "fmt" + "io/ioutil" + "os" + "path/filepath" "regexp" + "strings" ) type Sln struct { @@ -15,7 +15,6 @@ type Sln struct { ProjectList []Project } - func NewSln(path string) (Sln, error) { var sln Sln var err error @@ -66,8 +65,6 @@ func findAllProject(path string) ([]string, error) { return list, nil } - - func (sln *Sln) CompileCommandsJson(conf string) ([]CompileCommand, error) { var cmdList []CompileCommand @@ -91,17 +88,12 @@ func (sln *Sln) CompileCommandsJson(conf string) ([]CompileCommand, error) { } } def = RemoveBadDefinition(def) - def = strings.Replace(def, ";", " -D", -1) + def = preappend(def, "-D") + inc = RemoveBadInclude(inc) - inc = strings.Replace(inc, ";", " -I", -1) - if len(inc) > 0{ - inc = " -I" + inc - } - if len(def) > 0{ - def = " -D" + def - } + inc = preappend(inc, "-I") - cmd := "clang-cl.exe" + def + inc + " -c " + f + cmd := "clang-cl.exe " + def + " " + inc + " -c " + f item.Cmd = cmd cmdList = append(cmdList, item) @@ -111,3 +103,13 @@ func (sln *Sln) CompileCommandsJson(conf string) ([]CompileCommand, error) { return cmdList, nil } +func preappend(sepedString string, append string) string { + defList := strings.Split(sepedString, ";") + var output string + + for _, v := range defList { + v = append + v + " " + output += v + } + return output +}