Skip to content

Commit

Permalink
fix: some -D read error
Browse files Browse the repository at this point in the history
  • Loading branch information
paopaol committed May 27, 2022
1 parent f2b04f5 commit d1cb2ce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
26 changes: 12 additions & 14 deletions sln/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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)
Expand All @@ -176,4 +174,4 @@ func RemoveBadDefinition(def string) string {
def = strings.Replace(def, bad, "", -1)
}
return def
}
}
36 changes: 19 additions & 17 deletions sln/sln.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package sln

import (
"path/filepath"
"os"
"io/ioutil"
"strings"
"fmt"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
)

type Sln struct {
SolutionDir string
ProjectList []Project
}


func NewSln(path string) (Sln, error) {
var sln Sln
var err error
Expand Down Expand Up @@ -66,8 +65,6 @@ func findAllProject(path string) ([]string, error) {
return list, nil
}



func (sln *Sln) CompileCommandsJson(conf string) ([]CompileCommand, error) {
var cmdList []CompileCommand

Expand All @@ -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)
Expand All @@ -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
}

0 comments on commit d1cb2ce

Please sign in to comment.