Debian Codegraph @

vertexai/internal/import-go-sentencepiece.sh

raw
1 #!/bin/bash
2
3 # Copyright 2024 Google LLC
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Imports github.com/eliben/go-sentencepiece for local vendoring in our module,
18 # with the author's permission.
19
20 # Fail on any error
21 set -eo pipefail
22
23 # Display commands being run
24 set -x
25
26 # Create a temporary directory
27 TEMP_DIR=$(mktemp -d)
28
29 # Clone the repository with --depth 1 to get only the latest files
30 git clone --depth 1 https://github.com/eliben/go-sentencepiece.git "$TEMP_DIR/go-sentencepiece"
31
32 rm -rf sentencepiece
33 mkdir -p sentencepiece
34 rsync -av \
35 --exclude='.git' \
36 --exclude='.github' \
37 --exclude='go.mod' \
38 --exclude='go.sum' \
39 --exclude='wasm' \
40 --exclude='doc' \
41 --exclude='test' \
42 --exclude='*_test.go' \
43 "$TEMP_DIR/go-sentencepiece/" sentencepiece
44
45 # Replace import paths.
46 find "sentencepiece" -type f -name '*.go' \
47 -exec sed -i 's|github.com/eliben/go-sentencepiece|cloud.google.com/go/vertexai/internal/sentencepiece|g' {} +
48
49 # Prepend the LICENSE_HEADER to each .go file
50 GO_FILES=$(find sentencepiece -type f -name '*.go')
51 LICENSE_HEADER=$(realpath "LICENSE_HEADER")
52
53 for gofile in $GO_FILES; do
54 cat "$LICENSE_HEADER" "$gofile" > "$gofile.tmp" && mv "$gofile.tmp" "$gofile"
55 done