summaryrefslogtreecommitdiff
path: root/hack/generate-dmi-proto.sh
blob: 7ed709c46f69a6af4f33a47adb48a42e811db5fd (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
# Copyright 2023 The KubeEdge Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

DMI_DIR=pkg/apis/dmi
DMI_VERSION=v1beta1
DMI_API_FILE=api.proto
DMI_API_GO_FILE=api.pb.go

# try to parse named parameters
while [ $# -gt 0 ]; do
  case "$1" in
    --DMI_VERSION=*)
      DMI_VERSION="${1#*=}"
      ;;
    *)
      printf "***************************\n"
      printf "* Error: Invalid argument.*\n"
      printf "***************************\n"
      exit 1
  esac
  shift
done

DMI_CLIENT_CODE='
func NewMapperClient(cc grpc.ClientConnInterface) DeviceMapperServiceClient {
	return &deviceMapperServiceClient{cc}
}

func NewDeviceManageClient(cc grpc.ClientConnInterface) DeviceManagerServiceClient {
	return &deviceManagerServiceClient{cc}
}
'

# shellcheck disable=SC1004
COPY_RIGHT_INFO_LINE_1='/*\nCopyright 2023 The KubeEdge Authors.\n'
COPY_RIGHT_INFO_LINE_2='Licensed under the Apache License, Version 2.0 (the "License");'
COPY_RIGHT_INFO_LINE_3='you may not use this file except in compliance with the License.'
COPY_RIGHT_INFO_LINE_4='You may obtain a copy of the License at\n'
COPY_RIGHT_INFO_LINE_5='     http://www.apache.org/licenses/LICENSE-2.0\n'
COPY_RIGHT_INFO_LINE_6='Unless required by applicable law or agreed to in writing, software'
COPY_RIGHT_INFO_LINE_7='distributed under the License is distributed on an "AS IS" BASIS,'
COPY_RIGHT_INFO_LINE_8='WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
COPY_RIGHT_INFO_LINE_9='See the License for the specific language governing permissions and'
COPY_RIGHT_INFO_LINE_10='limitations under the License.\n*/\n'


cd ${DMI_DIR}
#protoc -I "${DMI_VERSION}"/ --go_out=plugins=grpc:"${DMI_VERSION}" "${DMI_VERSION}/${DMI_API_FILE}"
protoc -I "${DMI_VERSION}/" --go_out="${DMI_VERSION}" --go-grpc_out="${DMI_VERSION}" "${DMI_VERSION}/${DMI_API_FILE}"

sed -i '2,15d' "${DMI_VERSION}/${DMI_API_GO_FILE}"
sed -i "1i\ $COPY_RIGHT_INFO_LINE_10"  "${DMI_VERSION}/${DMI_API_GO_FILE}"
sed -i "1i\ $COPY_RIGHT_INFO_LINE_9"  "${DMI_VERSION}/${DMI_API_GO_FILE}"
sed -i "1i\ $COPY_RIGHT_INFO_LINE_8"  "${DMI_VERSION}/${DMI_API_GO_FILE}"
sed -i "1i\ $COPY_RIGHT_INFO_LINE_7"  "${DMI_VERSION}/${DMI_API_GO_FILE}"
sed -i "1i\ $COPY_RIGHT_INFO_LINE_6"  "${DMI_VERSION}/${DMI_API_GO_FILE}"
sed -i "1i\ $COPY_RIGHT_INFO_LINE_5"  "${DMI_VERSION}/${DMI_API_GO_FILE}"
sed -i "1i\ $COPY_RIGHT_INFO_LINE_4"  "${DMI_VERSION}/${DMI_API_GO_FILE}"
sed -i "1i\ $COPY_RIGHT_INFO_LINE_3"  "${DMI_VERSION}/${DMI_API_GO_FILE}"
sed -i "1i\ $COPY_RIGHT_INFO_LINE_2"  "${DMI_VERSION}/${DMI_API_GO_FILE}"
sed -i "1i\ $COPY_RIGHT_INFO_LINE_1"  "${DMI_VERSION}/${DMI_API_GO_FILE}"

echo "${DMI_CLIENT_CODE}" >> "${DMI_VERSION}/${DMI_API_GO_FILE}"

gofmt -w "${DMI_VERSION}/${DMI_API_GO_FILE}"

echo "success to generate dmi in ${DMI_DIR}/${DMI_VERSION}/${DMI_API_GO_FILE}"