Skip to content

Commit

Permalink
fix vorbisfile header order error
Browse files Browse the repository at this point in the history
  • Loading branch information
tsingbx committed Jan 10, 2025
1 parent da5dde6 commit cb454a0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
38 changes: 24 additions & 14 deletions cmd/llcppcfg/llcppgcfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,16 @@ func findDepSlice(lines []string) ([]string, string) {
return []string{}, objFileString
}

func parseFileEntry(trimStr, path string, d fs.DirEntry, exts []string, excludeSubdirs []string) *ObjFile {
func getClangArgs(cflags string, relpath string) []string {
args := make([]string, 0)
cflagsField := strings.Fields(cflags)
args = append(args, cflagsField...)
args = append(args, "-MM")
args = append(args, relpath)
return args
}

func parseFileEntry(cflags, trimCflag, path string, d fs.DirEntry, exts []string, excludeSubdirs []string) *ObjFile {
if d.IsDir() || strings.HasPrefix(d.Name(), ".") {
return nil
}
Expand All @@ -197,15 +206,16 @@ func parseFileEntry(trimStr, path string, d fs.DirEntry, exts []string, excludeS
if idx == len(exts) {
return nil
}
relPath, err := filepath.Rel(trimStr, path)
relPath, err := filepath.Rel(trimCflag, path)
if err != nil {
relPath = path
}
if isExcludeDir(relPath, excludeSubdirs) {
return nil
}
clangCmd := cmdout.NewExecCommand("clang", "-I"+trimStr, "-MM", relPath)
outString, err := cmdout.GetOut(clangCmd, trimStr)
args := getClangArgs(cflags, relPath)
clangCmd := cmdout.NewExecCommand("clang", args...)
outString, err := cmdout.GetOut(clangCmd, trimCflag)
if err != nil || outString == "" {
objFile := NewObjFile(relPath, relPath)
return objFile
Expand All @@ -218,22 +228,22 @@ func parseFileEntry(trimStr, path string, d fs.DirEntry, exts []string, excludeS
return objFile
}

func parseCFlagsEntry(l string, exts []string, excludeSubdirs []string) *CflagEntry {
if !strings.HasPrefix(l, "-I") {
func parseCFlagsEntry(cflags, cflag string, exts []string, excludeSubdirs []string) *CflagEntry {
if !strings.HasPrefix(cflag, "-I") {
return nil
}
trimStr := strings.TrimPrefix(l, "-I")
if !strings.HasSuffix(trimStr, string(filepath.Separator)) {
trimStr += string(filepath.Separator)
trimCflag := strings.TrimPrefix(cflag, "-I")
if !strings.HasSuffix(trimCflag, string(filepath.Separator)) {
trimCflag += string(filepath.Separator)
}
var cflagEntry CflagEntry
cflagEntry.Include = trimStr
cflagEntry.Include = trimCflag
cflagEntry.ObjFiles = make([]*ObjFile, 0)
err := filepath.WalkDir(trimStr, func(path string, d fs.DirEntry, err error) error {
err := filepath.WalkDir(trimCflag, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
pObjFile := parseFileEntry(trimStr, path, d, exts, excludeSubdirs)
pObjFile := parseFileEntry(cflags, trimCflag, path, d, exts, excludeSubdirs)
if pObjFile != nil {
cflagEntry.ObjFiles = append(cflagEntry.ObjFiles, pObjFile)
}
Expand All @@ -251,8 +261,8 @@ func parseCFlagsEntry(l string, exts []string, excludeSubdirs []string) *CflagEn
func sortIncludes(expandCflags string, cfg *LLCppConfig, exts []string, excludeSubdirs []string) {
list := strings.Fields(expandCflags)
cflagEntryList := make([]*CflagEntry, 0)
for _, l := range list {
pCflagEntry := parseCFlagsEntry(l, exts, excludeSubdirs)
for _, cflag := range list {
pCflagEntry := parseCFlagsEntry(expandCflags, cflag, exts, excludeSubdirs)
if pCflagEntry != nil {
cflagEntryList = append(cflagEntryList, pCflagEntry)
}
Expand Down
21 changes: 15 additions & 6 deletions cmd/llcppcfg/llcppgcfg/cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,13 @@ func (p *parseEntry) Info() (os.FileInfo, error) {
}

func Test_parseFileEntry(t *testing.T) {
_, inc := newCflags("cfg_test_data/cjson/include/")
cflags, inc := newCflags("cfg_test_data/cjson/include/")
path := inc + "cJSON.h"
internalPath := filepath.Join(inc, "internal")
objFile := NewObjFileString("cJSON.o:cJSON.h")
objFile.Deps = []string{}
type args struct {
cflags string
trimStr string
path string
d fs.DirEntry
Expand All @@ -496,6 +497,7 @@ func Test_parseFileEntry(t *testing.T) {
{
"cjson_ok",
args{
cflags,
inc,
path,
&parseEntry{name: "cJSON.h"},
Expand All @@ -507,6 +509,7 @@ func Test_parseFileEntry(t *testing.T) {
{
"cjson_exts_not_found",
args{
cflags,
inc,
path,
&parseEntry{name: "cJSON.h"},
Expand All @@ -518,6 +521,7 @@ func Test_parseFileEntry(t *testing.T) {
{
"cjson_not_rel_path",
args{
cflags,
inc,
"cJSON.h",
&parseEntry{name: "cJSON.h"},
Expand All @@ -529,6 +533,7 @@ func Test_parseFileEntry(t *testing.T) {
{
"cjson_exclude_dir",
args{
cflags,
inc,
filepath.Join(internalPath, "a.h"),
&parseEntry{name: "a.h"},
Expand All @@ -540,7 +545,7 @@ func Test_parseFileEntry(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := parseFileEntry(tt.args.trimStr, tt.args.path, tt.args.d, tt.args.exts, tt.args.excludeSubdirs)
got := parseFileEntry(tt.args.cflags, tt.args.trimStr, tt.args.path, tt.args.d, tt.args.exts, tt.args.excludeSubdirs)
if tt.want != nil && got != nil && !got.IsEqual(tt.want) {
t.Errorf("parseFileEntry() = %v, want %v", got, tt.want)
}
Expand All @@ -554,9 +559,10 @@ func Test_parseFileEntry(t *testing.T) {
}

func Test_parseCFlagsEntry(t *testing.T) {
trimStr, inc := newCflags("cfg_test_data/cjson/include/")
cflags, inc := newCflags("cfg_test_data/cjson/include/")
type args struct {
l string
cflags string
cflag string
exts []string
excludeSubdirs []string
}
Expand All @@ -568,7 +574,8 @@ func Test_parseCFlagsEntry(t *testing.T) {
{
"cjson_prefix_with_I",
args{
trimStr,
cflags,
cflags,
[]string{".h"},
[]string{"internal"},
},
Expand All @@ -583,6 +590,7 @@ func Test_parseCFlagsEntry(t *testing.T) {
{
"cjson_not_prefix_with_I",
args{
cflags,
inc,
[]string{".h"},
[]string{},
Expand All @@ -592,6 +600,7 @@ func Test_parseCFlagsEntry(t *testing.T) {
{
"cjson_walk_dir_err",
args{
cflags,
"-I/a/b/c",
[]string{".h"},
[]string{},
Expand All @@ -601,7 +610,7 @@ func Test_parseCFlagsEntry(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := parseCFlagsEntry(tt.args.l, tt.args.exts, tt.args.excludeSubdirs)
got := parseCFlagsEntry(tt.args.cflags, tt.args.cflag, tt.args.exts, tt.args.excludeSubdirs)
if got != nil && tt.want != nil && !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseCFlagsEntry() = %v, want %v", got, tt.want)
}
Expand Down

0 comments on commit cb454a0

Please sign in to comment.