diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-12-13 13:10:36 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-12-13 14:42:28 +0000 |
| commit | a35f0e6cafe5705ddc9f527bb6cfe297384021ef (patch) | |
| tree | b84d40955a9098dd2b1dd6fe22d5dcca5bade402 /pkg | |
| parent | a19f666144a849b339cdda7e4186046b4dec7dd8 (diff) | |
pkg/declextract: move file update from pkg/clangtool
Currently when entities are added/changed, one may need to update
both pkg/declextract and pkg/clangtool b/c clangtool updates paths.
Move all of that updates to pkg/declextract, so that pkg/clangtool
does not need to be touched when entities change.
The idea behind pkg/clangtool is to provide lower-level infrastructure
function of running the clang tool only.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/clangtool/clangtool.go | 10 | ||||
| -rw-r--r-- | pkg/declextract/entity.go | 5 |
2 files changed, 9 insertions, 6 deletions
diff --git a/pkg/clangtool/clangtool.go b/pkg/clangtool/clangtool.go index f0f14501b..528f80c57 100644 --- a/pkg/clangtool/clangtool.go +++ b/pkg/clangtool/clangtool.go @@ -123,12 +123,12 @@ func unmarshal(data []byte) (*declextract.Output, error) { func fixupFileNames(cfg *Config, out *declextract.Output, file string) { // All includes in the tool output are relative to the build dir. // Make them relative to the source dir. - for i, inc := range out.Includes { - if file, err := filepath.Rel(cfg.KernelSrc, filepath.Join(cfg.KernelObj, inc)); err == nil { - out.Includes[i] = file + out.SetSourceFile(file, func(filename string) string { + if res, err := filepath.Rel(cfg.KernelSrc, filepath.Join(cfg.KernelObj, filename)); err == nil { + return res } - } - out.SetSourceFile(file) + return filename + }) } type compileCommand struct { diff --git a/pkg/declextract/entity.go b/pkg/declextract/entity.go index eff8eda90..7cdd5a73a 100644 --- a/pkg/declextract/entity.go +++ b/pkg/declextract/entity.go @@ -172,7 +172,10 @@ func (out *Output) SortAndDedup() { // SetSoureFile attaches the source file to the entities that need it. // The clang tool could do it, but it looks easier to do it here. -func (out *Output) SetSourceFile(file string) { +func (out *Output) SetSourceFile(file string, updatePath func(string) string) { + for i, inc := range out.Includes { + out.Includes[i] = updatePath(inc) + } for _, call := range out.Syscalls { call.SourceFile = file } |
