From a35f0e6cafe5705ddc9f527bb6cfe297384021ef Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 13 Dec 2024 13:10:36 +0100 Subject: 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. --- pkg/clangtool/clangtool.go | 10 +++++----- pkg/declextract/entity.go | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'pkg') 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 } -- cgit mrf-deployment