github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/snapshot.sh (about) 1 #!/bin/sh 2 3 if [ -z ${GOPATH} ]; then 4 echo "$GOPATH must be set" 5 exit 1 6 fi 7 8 LOC=$(pwd) 9 COCKROACHDB_LOC=$GOPATH/src/github.com/cockroachdb/cockroach 10 11 echo "Generating files in-line using dev build short" 12 cd $COCKROACHDB_LOC 13 ./dev gen parser 14 ./dev gen protobuf 15 16 echo "Copying required dependencies over" 17 rm -rf $LOC/pkg 18 bazel query 'deps(//pkg/sql/parser)' | \ 19 # only care about dependencies in the CockroachDB repo 20 grep '^//pkg' | \ 21 # remove the // prefix 22 sed -e 's_^//__' | \ 23 # remove the :build_target directive 24 sed -e 's/:.*$//' | \ 25 # remove testutils 26 grep -v 'pkg/testutils' | grep -v 'pkg/cmd/protoc-gen-gogoroach' | \ 27 # ensure everything is unique 28 sort | uniq | \ 29 # copy over each dependency 30 xargs -I from_dir $LOC/copy_files.sh from_dir $COCKROACHDB_LOC $LOC 31 echo $(git rev-parse HEAD) > $LOC/version 32 33 echo "removing excess files, fixing up file paths" 34 cd $LOC 35 # replace compiler function to avoid conflicts. 36 sed -i.bak -e 's/compilerVersion/compilerVersionParser/g' pkg/build/*.go 37 # temporarily copy embedded data over 38 cp -R $COCKROACHDB_LOC/pkg/geo/geoprojbase/data $LOC/pkg/geo/geoprojbase/data 39 # delete gitignores 40 rm pkg/sql/lexbase/.gitignore pkg/sql/parser/.gitignore 41 rm pkg/sql/plpgsql/parser/.gitignore pkg/sql/plpgsql/parser/lexbase/.gitignore 42 # delete tests and testfiles 43 find pkg -type f -name '*_test.go' | xargs rm 44 # sed replace any instances of cockroachdb 45 find pkg -type f -name '*.go' | xargs sed -i.bak -e 's_github\.com/cockroachdb/cockroach/_github.com/cockroachdb/cockroachdb-parser/_g' 46 # fix protobuf enum and type registration to avoid conficts. 47 find pkg -type f -name '*.pb.go' | xargs sed -i.bak -e 's/\"cockroach\./\"cockroach\.parser\./g' 48 goimports -w pkg/sql/sem/tree/function_name.go 49 # delete any BUILD.bazel files. These files are invalid after being extracted 50 # from the main repository and will break any bazel builds that attempt to 51 # import this repository. 52 find pkg -type f -name 'BUILD.bazel' | xargs rm 53 # delete any .bak files generated by sed, the use of -i.bak makes these sed 54 # command works on both linux and macos. 55 find pkg -type f -name '*.bak' | xargs rm 56 # embed stopwords 57 cp -R $COCKROACHDB_LOC/pkg/util/tsearch/stopwords $LOC/pkg/util/tsearch/stopwords 58 59 for f in patches/*; do 60 echo "applying patch $f" 61 git apply $f 62 done 63 64 echo "Cleaning up go and testing everything works" 65 go mod tidy 66 echo "v0.0.0" > pkg/build/version.txt 67 go test .