Intro
=====
Go packages use the d/control `XS-Go-Import-Path` field to document the
import paths that they provide. This corresponds with files installed
under /usr/share/gocode/src. It would be great if lintian validated that
`XS-Go-Import-Path` was correct.
Xs-Go-Import-Path is used by tools in the Go packaging ecosystem for
useful things like finding the debian packages required to build a
program given its import paths.
XS-Go-Import-Path Usage
=======================
Most packages provide only one import path.
For example, `golang-github-bmizerany-pat` provides `XS-Go-Import-Path:
github.com/bmizerany/pat` and it installs files under
`/usr/share/gocode/src/github.com/bmizernany`.
Some packages provide more import paths. Sometimes via symlinks for
alternate names but sometimes simply because they actually provide two
different packages.
For example, `golang-gopkg-asn1-ber.v1` provides two import paths:
```
XS-Go-Import-Path: gopkg.in/asn1-ber.v1,
github.com/go-asn1-ber/asn1-ber
```
And it installs files at both
`/usr/share/gocode/src/gopkg.in/asn1-ber.v1` and
`/usr/share/gocode/src/github.com/go-asn1-ber`
Implementing the check
======================
I am unfamiliar with Lintian internals, and with Perl, but I do have
some pointers:
- If the package installs N directories under `/usr/share/gocode/src` It
should have exactly N import paths.
This package would have one import path (github.com/aviau/project):
* /usr/share/gocode/src/github.com/aviau/project/aa.go
* /usr/share/gocode/src/github.com/aviau/project/bb.go
This package would have two import paths (github.com/aviau/project and
gitlab.com/aviau/project):
* /usr/share/gocode/src/github.com/aviau/project/aa.go
* /usr/share/gocode/src/github.com/aviau/project/bb.go
* /usr/share/gocode/src/gitlab.com/aviau/project (symlink)
- If the package installs files under
`/usr/share/gocode/src/FOO.com/BAR`, one of its import paths should
start with `foo.com/bar`.
aviau/identify-incomplete-xs-go-import-path
===========================================
I have written a python program to try and detect those mistakes, but it
only covers some use cases and depends on Debian Code Search. However it
may be useful for anyone trying to write a lintian check:
- https://salsa.debian.org/aviau/identify-incomplete-xs-go-import-path
Thank you for Lintian and thanks for taking a look at this :)
Hi Alexandre,
Should the second path be
/usr/share/gocode/src/github.com/go-asn1-ber/asn1-ber instead? (Please
note the extra final component in the file list at the very bottom of
this message.) Also, why is it a symbolic link, please? Should Lintian
merely verify that the path is present so we catch when there is a
link and not a folder?
As a side note, I had to download the installable package
golang-gopkg-asn1-ber.v1-dev_1.5.1-1_all.deb
in order to take a look at it. I tried examining the paths on
packages.d.o [1] but only saw "No such package in this suite on this
architecture." Do you know why that might be happening? Thanks!
Kind regards
Felix Lechner
[1] https://packages.debian.org/sid/all/golang-gopkg-asn1-ber.v1-dev/filelist
* * *
➤ dpkg -c /tmp/golang-gopkg-asn1-ber.v1-dev_1.5.1-1_all.deb
drwxr-xr-x root/root 0 2020-08-29 13:08 ./
drwxr-xr-x root/root 0 2020-08-29 13:08 ./usr/
drwxr-xr-x root/root 0 2020-08-29 13:08 ./usr/share/
drwxr-xr-x root/root 0 2020-08-29 13:08 ./usr/share/doc/
drwxr-xr-x root/root 0 2020-08-29 13:08
./usr/share/doc/golang-gopkg-asn1-ber.v1-dev/
-rw-r--r-- root/root 769 2020-08-29 13:08
./usr/share/doc/golang-gopkg-asn1-ber.v1-dev/changelog.Debian.gz
-rw-r--r-- root/root 1494 2020-08-29 13:08
./usr/share/doc/golang-gopkg-asn1-ber.v1-dev/copyright
drwxr-xr-x root/root 0 2020-08-29 13:08 ./usr/share/gocode/
drwxr-xr-x root/root 0 2020-08-29 13:08 ./usr/share/gocode/src/
drwxr-xr-x root/root 0 2020-08-29 13:08
./usr/share/gocode/src/github.com/
drwxr-xr-x root/root 0 2020-08-29 13:08
./usr/share/gocode/src/github.com/go-asn1-ber/
drwxr-xr-x root/root 0 2020-08-29 13:08 ./usr/share/gocode/src/gopkg.in/
drwxr-xr-x root/root 0 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/
-rw-r--r-- root/root 14751 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/ber.go
-rw-r--r-- root/root 4856 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/ber_test.go
-rw-r--r-- root/root 310 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/content_int.go
-rw-r--r-- root/root 2505 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/generalizedTime.go
-rw-r--r-- root/root 1819 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/generalizedTime_test.go
-rw-r--r-- root/root 48 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/go.mod
-rw-r--r-- root/root 793 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/header.go
-rw-r--r-- root/root 3477 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/header_test.go
-rw-r--r-- root/root 2603 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/identifier.go
-rw-r--r-- root/root 10997 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/identifier_test.go
-rw-r--r-- root/root 2026 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/length.go
-rw-r--r-- root/root 4174 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/length_test.go
-rw-r--r-- root/root 3150 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/real.go
-rw-r--r-- root/root 536 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/real_test.go
-rw-r--r-- root/root 2151 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/string_test.go
-rw-r--r-- root/root 7574 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/suite_test.go
drwxr-xr-x root/root 0 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/
-rw-r--r-- root/root 13 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc1.ber
-rw-r--r-- root/root 9 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc10.ber
-rw-r--r-- root/root 11 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc11.ber
-rw-r--r-- root/root 3 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc12.ber
-rw-r--r-- root/root 11 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc13.ber
-rw-r--r-- root/root 7 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc14.ber
-rw-r--r-- root/root 14 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc15.ber
-rw-r--r-- root/root 14 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc16.ber
-rw-r--r-- root/root 22 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc17.ber
-rw-r--r-- root/root 5 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc18.ber
-rw-r--r-- root/root 2 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc19.ber
-rw-r--r-- root/root 10 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc2.ber
-rw-r--r-- root/root 11 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc20.ber
-rw-r--r-- root/root 8 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc21.ber
-rw-r--r-- root/root 18 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc22.ber
-rw-r--r-- root/root 8 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc23.ber
-rw-r--r-- root/root 23 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc24.ber
-rw-r--r-- root/root 5 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc25.ber
-rw-r--r-- root/root 5 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc26.ber
-rw-r--r-- root/root 2 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc27.ber
-rw-r--r-- root/root 3 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc28.ber
-rw-r--r-- root/root 3 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc29.ber
-rw-r--r-- root/root 10 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc3.ber
-rw-r--r-- root/root 5 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc30.ber
-rw-r--r-- root/root 4 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc31.ber
-rw-r--r-- root/root 2 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc32.ber
-rw-r--r-- root/root 4 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc33.ber
-rw-r--r-- root/root 3 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc34.ber
-rw-r--r-- root/root 16 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc35.ber
-rw-r--r-- root/root 20 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc36.ber
-rw-r--r-- root/root 14 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc37.ber
-rw-r--r-- root/root 16 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc38.ber
-rw-r--r-- root/root 2 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc39.ber
-rw-r--r-- root/root 11 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc4.ber
-rw-r--r-- root/root 2 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc40.ber
-rw-r--r-- root/root 16 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc41.ber
-rw-r--r-- root/root 14 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc42.ber
-rw-r--r-- root/root 2 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc43.ber
-rw-r--r-- root/root 2 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc44.ber
-rw-r--r-- root/root 2 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc45.ber
-rw-r--r-- root/root 11 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc46.ber
-rw-r--r-- root/root 16 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc47.ber
-rw-r--r-- root/root 16 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc48.ber
-rw-r--r-- root/root 4 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc49.ber
-rw-r--r-- root/root 13 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc5.ber
-rw-r--r-- root/root 10 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc50.ber
-rw-r--r-- root/root 7 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc51.ber
-rw-r--r-- root/root 9 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc6.ber
-rw-r--r-- root/root 9 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc7.ber
-rw-r--r-- root/root 5 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc8.ber
-rw-r--r-- root/root 5 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/tests/tc9.ber
-rw-r--r-- root/root 452 2020-08-29 13:08
./usr/share/gocode/src/gopkg.in/asn1-ber.v1/util.go
lrwxrwxrwx root/root 0 2020-08-29 13:08
./usr/share/gocode/src/github.com/go-asn1-ber/asn1-ber ->
../../gopkg.in/asn1-ber.v1
Ideally yes, but both paths are technically correct. I don't think Lintian should go so far as it will probably be hard (or impossible) to get right. In this case the package changed name, so both folders point to the same source for backwards-compatibility. When the Go compiler imports both paths it will find the same source code. I don't think Lintian should distinguish between links and folders. No, sorry. Cheers :)
Hi Alexandre, I implemented it on an unreleased branch, but it will not work well unless the field is propagated into the control files of installed packages (for your example, golang-github-bmizerany-pat-dev). I see the field only in the dsc, but not in CONTROL [1]. Is that possible, please? Kind regards Felix Lechner [1] https://binarycontrol.debian.net/cache/unstable/golang-github-bmizerany-pat-dev/control
There is already a lintian warning that checks for the presence of XS-Go-Import-Path, maybe you can take a look at how this one works? - https://lintian.debian.org/tags/missing-xs-go-import-path-for-golang-package.html If we can check for XS-Go-Import-Path then I think that we can read it? I hope that helps! Cheers!
Hi Alexandre, The check you are referring to reads Debian sources (dsc), but the field is not present in the *installable* packages (*.deb) that place the sources in /usr/share/gocode/src. Your tag cannot be implemented unless the field is also present in the installable (aka "binary") packages. Kind regards Felix Lechner