Skip to content

Commit

Permalink
Add dummy package for C sources directories to allow vendoring
Browse files Browse the repository at this point in the history
To allow 'go mod -vendor' to take directories, we create dummy packages
in each directory.

Basically it does:
for d in $(find internal -type d); do echo "package $(basename $d)" >"$d/pkg.go"; done

A script is used to maintained those dummy package besides hidapi/libusb
upgrades: internal/dummy-packages.sh

See:
- karalabe#31
- golang/go#26366
  • Loading branch information
dolmen committed Feb 20, 2022
1 parent 3bcbbb7 commit f9d91bc
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package hid

// Just for Go vendoring
// See https://github.com/golang/go/issues/26366
import _ "github.com/dolmen-go/hid/internal"
23 changes: 23 additions & 0 deletions internal/dummy-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -euo pipefail

cd "$(dirname "$0")"

for d in $(find libusb hidapi -type d)
do
echo "package $(basename $d)" >"$d/pkg.go"
done

pkg=$(cd ..; go list)/internal

{
echo 'package internal'
echo
echo 'import ('
for d in $(find hidapi libusb -type d);
do
printf '\t_ "%s/%s"\n' "$pkg" "$d"
done
echo ')'
} >pkg.go
1 change: 1 addition & 0 deletions internal/hidapi/hidapi/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package hidapi
1 change: 1 addition & 0 deletions internal/hidapi/libusb/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package libusb
1 change: 1 addition & 0 deletions internal/hidapi/mac/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package mac
1 change: 1 addition & 0 deletions internal/hidapi/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package hidapi
1 change: 1 addition & 0 deletions internal/hidapi/windows/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package windows
1 change: 1 addition & 0 deletions internal/libusb/libusb/os/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package os
1 change: 1 addition & 0 deletions internal/libusb/libusb/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package libusb
1 change: 1 addition & 0 deletions internal/libusb/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package libusb
12 changes: 12 additions & 0 deletions internal/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package internal

import (
_ "github.com/dolmen-go/hid/internal/hidapi"
_ "github.com/dolmen-go/hid/internal/hidapi/mac"
_ "github.com/dolmen-go/hid/internal/hidapi/hidapi"
_ "github.com/dolmen-go/hid/internal/hidapi/windows"
_ "github.com/dolmen-go/hid/internal/hidapi/libusb"
_ "github.com/dolmen-go/hid/internal/libusb"
_ "github.com/dolmen-go/hid/internal/libusb/libusb"
_ "github.com/dolmen-go/hid/internal/libusb/libusb/os"
)
2 changes: 2 additions & 0 deletions internal/upgrade-hidapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ if [[ -d hidapi ]]; then
fi
mv $dir hidapi
rm -Rf hidapi.orig "$archive"

./dummy-packages.sh
2 changes: 2 additions & 0 deletions internal/upgrade-libusb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ if [[ -d libusb ]]; then
fi
mv libusb-${version} libusb
rm -Rf libusb.orig "$archive"

./dummy-packages.sh

0 comments on commit f9d91bc

Please sign in to comment.