in tool/preprocess/preprocess.go [725:759]
func (dp *DepProcessor) addRuleImporter() error {
paths := map[string]bool{}
for _, bundle := range dp.bundles {
for _, funcRules := range bundle.File2FuncRules {
for _, rules := range funcRules {
for _, rule := range rules {
if rule.GetPath() != "" {
paths[rule.GetPath()] = true
}
}
}
}
}
content, err := util.ReadFile(dp.generatedOf(OtelImporter))
if err != nil {
return err
}
for path := range paths {
content += fmt.Sprintf("import _ %q\n", path)
}
cnt := 0
for _, bundle := range dp.bundles {
lb := fmt.Sprintf("//go:linkname getstatck%d %s.OtelGetStackImpl\n", cnt, bundle.ImportPath)
content += lb
s := fmt.Sprintf("var getstatck%d = debug.Stack\n", cnt)
content += s
lb = fmt.Sprintf("//go:linkname printstack%d %s.OtelPrintStackImpl\n", cnt, bundle.ImportPath)
content += lb
s = fmt.Sprintf("var printstack%d = func (bt []byte){ log.Printf(string(bt)) }\n", cnt)
content += s
cnt++
}
util.WriteFile(dp.generatedOf(OtelImporter), content)
return nil
}