diff --git a/.gitignore b/.gitignore index 3149adca..fefcda44 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ coverage.txt /test/plugins/workspace /test/plugins/dist/ -*.pb.go \ No newline at end of file +*.pb.go +vendor/ diff --git a/CHANGES.md b/CHANGES.md index 2cfd3aa7..f7827164 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ Release Notes. * Fix users can not use async api in toolkit-trace. * Fix cannot enhance the vendor management project. * Fix SW_AGENT_REPORTER_GRPC_MAX_SEND_QUEUE not working on metricsSendCh & logSendCh chans of gRPC reporter. +* Fix ParseVendorModule error for special case in vendor/modules.txt #### Issues and PR - All issues are [here](https://github.com/apache/skywalking/milestone/197?closed=1) diff --git a/tools/go-agent/tools/testdata/special-modules.txt b/tools/go-agent/tools/testdata/special-modules.txt new file mode 100644 index 00000000..15fc713a --- /dev/null +++ b/tools/go-agent/tools/testdata/special-modules.txt @@ -0,0 +1,4 @@ +# github.com/abc/def v0.2.0 +## explicit; go 1.18 +github.com/abc/def/aa +github.com/abc/def/bb/cc \ No newline at end of file diff --git a/tools/go-agent/tools/vendor.go b/tools/go-agent/tools/vendor.go index 16d5bba1..02e6dbee 100644 --- a/tools/go-agent/tools/vendor.go +++ b/tools/go-agent/tools/vendor.go @@ -58,9 +58,10 @@ func ParseVendorModule(path string) (VendorModules, error) { return nil, fmt.Errorf("module data cannot be analyzed") } module = &VendorModule{ - Name: moduleInfo[1], + Name: strings.TrimSpace(moduleInfo[1]), Version: moduleInfo[2], } + modules[module.Name] = module continue } else if strings.HasPrefix(moduleString, "#") { // go version required, ignore diff --git a/tools/go-agent/tools/vendor_test.go b/tools/go-agent/tools/vendor_test.go index 4a3e0af8..9d824ea1 100644 --- a/tools/go-agent/tools/vendor_test.go +++ b/tools/go-agent/tools/vendor_test.go @@ -92,6 +92,19 @@ func TestParseVendorModule(t *testing.T) { return nil }, }, + { + path: "./testdata/special-modules.txt", + hasError: false, + packageCount: 3, + validate: func(modules VendorModules) error { + if m := modules["github.com/abc/def"]; m == nil { + return fmt.Errorf("module missing") + } else if m.Version != "v0.2.0" { + return fmt.Errorf("version not correct") + } + return nil + }, + }, } for _, test := range tests {