diff --git a/magefile.go b/magefile.go index a380e411..9b0b5785 100644 --- a/magefile.go +++ b/magefile.go @@ -26,6 +26,7 @@ import ( "path/filepath" "github.com/livekit/mageutil" + "github.com/livekit/protocol/psrpc" ) var Default = Proto @@ -141,6 +142,9 @@ func Proto() error { if err != nil { return err } + if err := psrpc.CheckCompilerVersion(psrpcPath); err != nil { + return err + } args = append([]string{ "--go_out", ".", diff --git a/psrpc/compilercheck.go b/psrpc/compilercheck.go new file mode 100644 index 00000000..c2f64c0d --- /dev/null +++ b/psrpc/compilercheck.go @@ -0,0 +1,36 @@ +// Copyright 2023 LiveKit, Inc. +// +// 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. + +package psrpc + +import ( + "bytes" + "fmt" + "os/exec" + + "github.com/livekit/psrpc/version" +) + +func CheckCompilerVersion(path string) error { + b, err := exec.Command(path, "--version").Output() + if err != nil { + return err + } + + b = bytes.Trim(b, "\r\n") + if string(b) != version.Version { + return fmt.Errorf("found psrpc compiler version %s need %s. please run:\ngo install github.com/livekit/psrpc/protoc-gen-psrpc", string(b), version.Version) + } + return nil +} diff --git a/psrpc/logging.go b/psrpc/logging.go index c5c18470..7c320a31 100644 --- a/psrpc/logging.go +++ b/psrpc/logging.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package middleware +package psrpc import ( "context" diff --git a/psrpc/metrics.go b/psrpc/metrics.go index 1c4948ee..895a30aa 100644 --- a/psrpc/metrics.go +++ b/psrpc/metrics.go @@ -1,4 +1,18 @@ -package middleware +// Copyright 2023 LiveKit, Inc. +// +// 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. + +package psrpc import ( "time"