Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: go mod vendor #131

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ update_source: clean $(LIBDIR)
# Other support files
rm -fr testdata
cp -a $(LIBDIR)/testdata testdata
bash scripts/gokeep.sh

clean:
-@ $(RM) -r $(LIB_TMPDIR)
54 changes: 54 additions & 0 deletions parser/build_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//go:build required
// +build required

package parser

// This file exists purely to prevent the Golang toolchain from stripping
// away the C source directories and files when `go mod vendor` is used
// to populate a `vendor/` directory of a project depending on `github.com/pganalyze/pg_query_go/v6`.
//
// How it works:
// - Every directory which only includes C source files receives a gokeep.go file.
// - Every directory we want to preserve is included here as a _ import.
// - This file is given a build tag to exclude it from the regular build.
import (
// Prevent Go tooling from stripping out the C source files.
_ "github.com/pganalyze/pg_query_go/v6/parser/include"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/access"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/archive"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/catalog"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/commands"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/common"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/datatype"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/executor"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/foreign"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/jit"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/lib"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/libpq"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/mb"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/nodes"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/optimizer"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/parser"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/partitioning"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/atomics"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32/arpa"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32/netinet"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32/sys"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32_msvc"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/port/win32_msvc/sys"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/portability"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/postmaster"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/regex"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/replication"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/rewrite"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/storage"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/tcop"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/tsearch"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/postgres/utils"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/protobuf"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/protobuf-c"
_ "github.com/pganalyze/pg_query_go/v6/parser/include/xxhash"
)
5 changes: 5 additions & 0 deletions parser/include/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/access/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/archive/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/catalog/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/commands/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/common/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/datatype/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/executor/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/foreign/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/jit/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/lib/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/libpq/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/mb/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/nodes/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/optimizer/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/parser/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/partitioning/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/port/atomics/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/port/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/port/win32/arpa/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/port/win32/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/port/win32/netinet/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/port/win32/sys/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/port/win32_msvc/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/port/win32_msvc/sys/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/portability/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/postmaster/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/regex/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/replication/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/rewrite/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/storage/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/tcop/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/tsearch/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/postgres/utils/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/protobuf-c/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/protobuf/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
5 changes: 5 additions & 0 deletions parser/include/xxhash/gokeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
2 changes: 1 addition & 1 deletion pg_query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions scripts/gokeep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash -e

c_dir="parser/include"

go_module="$(go list -m)"
go_imports=""

while IFS='' read -r c_dir; do
go_imports+=" _ \"${go_module}/${c_dir}\""$'\n'
cat <<EOF >"${c_dir}/gokeep.go"
//go:build required
// +build required

// package gokeep prevents go tooling from stripping the C dependencies.
package gokeep
EOF
done < <(find ${c_dir} -type f \( -name '*.c' -o -name '*.h' \) -exec dirname {} \; | sort -u)

cat <<EOF >"parser/build_cgo.go"
//go:build required
// +build required

package parser

// This file exists purely to prevent the Golang toolchain from stripping
// away the C source directories and files when \`go mod vendor\` is used
// to populate a \`vendor/\` directory of a project depending on \`${go_module}\`.
//
// How it works:
// - Every directory which only includes C source files receives a gokeep.go file.
// - Every directory we want to preserve is included here as a _ import.
// - This file is given a build tag to exclude it from the regular build.
import (
// Prevent Go tooling from stripping out the C source files.
${go_imports})
EOF