Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions tool/_testc/python-3.14.8/cpython-pythread.go

This file was deleted.

1 change: 1 addition & 0 deletions tool/_testc/python-3.14.8/llcppg.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"MacroIgnore": [],
"TypeIgnore": [],
"GroupSubdirBy": "fname",
"FailFast": 10,
"IgnoreInline": true,
"Language": "c"
Expand Down
13 changes: 12 additions & 1 deletion tool/_testc/python-3.14.8/pythread.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tool/_testcpp/llvm-22.1.8-support/llcppg-adt.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"Rename": {
},
"TypeIgnore": [],
"NSIgnore": []
"NSIgnore": [],
"GroupSubdirBy": "dir"
}
3 changes: 2 additions & 1 deletion tool/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ type Config struct {
FailFast int `json:"FailFast"` // exit on first N errors, optional
IgnoreInline bool `json:"IgnoreInline"` // quietly ignore inline functions
NoManglingIgnore bool `json:"NoManglingIgnore"` // quietly ignore functions with no mangled symbol
GroupSubdir bool `json:"GroupSubdir"` // treats sub-directory files as a single file
GroupSubdir bool `json:"GroupSubdir"` // treats sub-directory files as a single file. Deprecated: use GroupSubdirBy instead.
GroupSubdirBy string `json:"GroupSubdirBy"` // criterion to group sub-directory files by, e.g., "dir" or "fname". `GroupSubdir = true` is equivalent to `GroupSubdirBy = "dir"`.
Comment thread
xushiwei marked this conversation as resolved.
}

// -----------------------------------------------------------------------------
Expand Down
33 changes: 28 additions & 5 deletions tool/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,19 @@ func (cfg *Config) NewPackage(pkgPath, pkgName, workDir string, index clang.Inde
}
defer DisposeSources(files)

groupSubdir := cfg.GroupSubdir
groupSubdirBy := groupSubdirByNone
switch cfg.GroupSubdirBy {
case "dir":
groupSubdirBy = groupSubdirByDir
case "fname":
groupSubdirBy = groupSubdirByFname
case "":
if cfg.GroupSubdir {
groupSubdirBy = groupSubdirByDir
}
default:
log.Println("[WARN] unknown GroupSubdirBy value:", cfg.GroupSubdirBy)
}
Comment thread
xushiwei marked this conversation as resolved.
srcFilePrefix := dir + string(os.PathSeparator)
if pkgName == "" {
pkgName = path.Base(cfg.Name)
Expand Down Expand Up @@ -216,7 +228,7 @@ func (cfg *Config) NewPackage(pkgPath, pkgName, workDir string, index clang.Inde
return
},
GoFileOf: func(headerFile string) (fname string, ok bool) {
return goFileOf(headerFile, srcFilePrefix, groupSubdir)
return goFileOf(headerFile, srcFilePrefix, groupSubdirBy)
},
})
return
Expand All @@ -232,16 +244,27 @@ func listHeaderFiles(selFiles []string, headerDir string) (topHeaders []string)
return
}

func goFileOf(at, srcFilePrefix string, groupSubdir bool) (fname string, ok bool) {
const (
groupSubdirByNone = iota
groupSubdirByDir
groupSubdirByFname
)

func goFileOf(at, srcFilePrefix string, groupSubdirBy int) (fname string, ok bool) {
const pathSep = string(os.PathSeparator)
const goFileExt = ".go"
fname, ok = strings.CutPrefix(at, srcFilePrefix)
if ok {
if groupSubdir {
switch groupSubdirBy {
case groupSubdirByDir:
if pos := strings.Index(fname, pathSep); pos > 0 {
fname = fname[:pos]
}
} else {
case groupSubdirByFname:
if pos := strings.LastIndex(fname, pathSep); pos >= 0 {
fname = fname[pos+1:]
}
Comment thread
xushiwei marked this conversation as resolved.
default:
fname = strings.ReplaceAll(fname, pathSep, "-")
}
if pos := strings.LastIndex(fname, "."); pos > 0 {
Expand Down
Loading