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

Makefile

Lines changed: 1 addition & 0 deletions
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)

parser/build_cgo.go

Lines changed: 54 additions & 0 deletions
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+
)

parser/include/gokeep.go

Lines changed: 5 additions & 0 deletions
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
Lines changed: 5 additions & 0 deletions
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
Lines changed: 5 additions & 0 deletions
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
Lines changed: 5 additions & 0 deletions
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
Lines changed: 5 additions & 0 deletions
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
Lines changed: 5 additions & 0 deletions
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
Lines changed: 5 additions & 0 deletions
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
Lines changed: 5 additions & 0 deletions
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

0 commit comments

Comments
 (0)