You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
klog.Errorf("Package %s does not have module info. Non go modules projects are no longer supported. For feedback, refer to https://github.com/google/go-licenses/issues/128.", p.PkgPath)
// There seems to be 3 common cases in terms of go module directory structure:
127
+
// - "github" case follows github.com/<org>/<repo>
128
+
// - "k8s.io" case follow k8s.io/<module>
129
+
// - "go.starlark.net" (and probably lots others not exactly sure why/when this happens) case where go.starlark.net is the only folder in the structure
130
+
// To account for the above, the stopAt is set to the the greatest depth up to 3 subfolders
131
+
// Alternative: Since license files should only exists in the context of module folders within
132
+
// the vendor directory, and not repo (github.com) folders or the vendor folder itself, we could
133
+
// set stopAt to vendor mainly just to ensure traversal never goes above vendor, finding the main module license
klog.Warningf("module %s does not have dir and it's not vendored, cannot discover the license URL. Report to go-licenses developer if you see this.", lib.module.Path)
164
-
} else {
165
-
// This is vendored. Handle this known special case.
166
-
167
-
// Extra note why we identify a vendored package like this.
168
-
//
169
-
// For a normal package:
170
-
// * if it's not in a module, lib.module == nil
171
-
// * if it's in a module, lib.module.Dir != ""
172
-
// Only vendored modules will have lib.module != nil && lib.module.Path != "" && lib.module.Dir == "" as far as I know.
173
-
// So the if condition above is already very strict for vendored packages.
174
-
// On top of it, we checked the lib.LicensePath contains a vendor folder in it.
175
-
// So it's rare to have a false positive for both conditions at the same time, although it may happen in theory.
176
-
//
177
-
// These assumptions may change in the future,
178
-
// so we need to keep this updated with go tooling changes.
// A known cause is that the module is vendored, so some information is lost.
243
+
splits:=strings.SplitN(path, "/vendor/", 2)
244
+
iflen(splits) !=2 {
245
+
klog.Warningf("module %s does not have dir and it's not vendored, cannot discover the license URL. Report to go-licenses developer if you see this.", module.Path)
246
+
} else {
247
+
// This is vendored. Handle this known special case.
248
+
249
+
// Extra note why we identify a vendored package like this.
250
+
//
251
+
// For a normal package:
252
+
// * if it's not in a module, lib.module == nil
253
+
// * if it's in a module, lib.module.Dir != ""
254
+
// Only vendored modules will have lib.module != nil && lib.module.Path != "" && lib.module.Dir == "" as far as I know.
255
+
// So the if condition above is already very strict for vendored packages.
256
+
// On top of it, we checked the lib.LicensePath contains a vendor folder in it.
257
+
// So it's rare to have a false positive for both conditions at the same time, although it may happen in theory.
258
+
//
259
+
// These assumptions may change in the future,
260
+
// so we need to keep this updated with go tooling changes.
0 commit comments