Skip to content

Commit 00b50ee

Browse files
authored
Allow "go mod vendor" to work correctly
This adds extra `gokeep.go` files into each directory that only contains C source code, to ensure Go's "go mod vendor" command retains the source files correctly. Previously this required use of other vendor tools like modvendor, which are now no longer required.
1 parent 38c866d commit 00b50ee

File tree

42 files changed

+282
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+282
-1
lines changed

Diff for: Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ update_source: clean $(LIBDIR)
6161
# Other support files
6262
rm -fr testdata
6363
cp -a $(LIBDIR)/testdata testdata
64+
bash scripts/gokeep.sh
6465

6566
clean:
6667
-@ $(RM) -r $(LIB_TMPDIR)

Diff for: parser/build_cgo.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//go:build required
2+
// +build required
3+
4+
package parser
5+
6+
// This file exists purely to prevent the Golang toolchain from stripping
7+
// away the C source directories and files when `go mod vendor` is used
8+
// to populate a `vendor/` directory of a project depending on `github.com/pganalyze/pg_query_go/v6`.
9+
//
10+
// How it works:
11+
// - Every directory which only includes C source files receives a gokeep.go file.
12+
// - Every directory we want to preserve is included here as a _ import.
13+
// - This file is given a build tag to exclude it from the regular build.
14+
import (
15+
// Prevent Go tooling from stripping out the C source files.
16+
_ "github.com/pganalyze/pg_query_go/v6/parser/include"
17+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres"
18+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/access"
19+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/archive"
20+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/catalog"
21+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/commands"
22+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/common"
23+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/datatype"
24+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/executor"
25+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/foreign"
26+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/jit"
27+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/lib"
28+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/libpq"
29+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/mb"
30+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/nodes"
31+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/optimizer"
32+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/parser"
33+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/partitioning"
34+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port"
35+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/atomics"
36+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32"
37+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32/arpa"
38+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32/netinet"
39+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32/sys"
40+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32_msvc"
41+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32_msvc/sys"
42+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/portability"
43+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/postmaster"
44+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/regex"
45+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/replication"
46+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/rewrite"
47+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/storage"
48+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/tcop"
49+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/tsearch"
50+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/utils"
51+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/protobuf"
52+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/protobuf-c"
53+
_ "github.com/pganalyze/pg_query_go/v6/parser/include/xxhash"
54+
)

Diff for: parser/include/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/access/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/archive/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/catalog/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/commands/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/common/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/datatype/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/executor/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/foreign/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/jit/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/lib/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/libpq/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/mb/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/nodes/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/optimizer/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/parser/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/partitioning/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/port/atomics/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/port/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/port/win32/arpa/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/port/win32/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/port/win32/netinet/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/port/win32/sys/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/port/win32_msvc/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/portability/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/postmaster/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/regex/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/replication/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/rewrite/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/storage/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/tcop/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/tsearch/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/postgres/utils/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/protobuf-c/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/protobuf/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: parser/include/xxhash/gokeep.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build required
2+
// +build required
3+
4+
// package gokeep prevents go tooling from stripping the C dependencies.
5+
package gokeep

Diff for: pg_query.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: scripts/gokeep.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash -e
2+
3+
c_dir="parser/include"
4+
5+
go_module="$(go list -m)"
6+
go_imports=""
7+
8+
while IFS='' read -r c_dir; do
9+
go_imports+=" _ \"${go_module}/${c_dir}\""$'\n'
10+
cat <<EOF >"${c_dir}/gokeep.go"
11+
//go:build required
12+
// +build required
13+
14+
// package gokeep prevents go tooling from stripping the C dependencies.
15+
package gokeep
16+
EOF
17+
done < <(find ${c_dir} -type f \( -name '*.c' -o -name '*.h' \) -exec dirname {} \; | sort -u)
18+
19+
cat <<EOF >"parser/build_cgo.go"
20+
//go:build required
21+
// +build required
22+
23+
package parser
24+
25+
// This file exists purely to prevent the Golang toolchain from stripping
26+
// away the C source directories and files when \`go mod vendor\` is used
27+
// to populate a \`vendor/\` directory of a project depending on \`${go_module}\`.
28+
//
29+
// How it works:
30+
// - Every directory which only includes C source files receives a gokeep.go file.
31+
// - Every directory we want to preserve is included here as a _ import.
32+
// - This file is given a build tag to exclude it from the regular build.
33+
import (
34+
// Prevent Go tooling from stripping out the C source files.
35+
${go_imports})
36+
EOF

0 commit comments

Comments
 (0)