生成文件在 Windows 上失败:语法错误"("意外



我有一个Makefilefor go项目,它有一个步骤来生成protobuf源。最小的可复制示例是(假设所有必需的依赖项都已安装并且原型文件已正确定位(:

OUT := ${CURDIR}/go/proto
GOPATH := $(shell go env GOPATH)
PROTOC := env PATH=$(GOPATH)/bin:${PATH} protoc
all:
$(PROTOC) --go_out=plugins=grpc:$(OUT) --go_opt=paths=source_relative *.proto

您可以在此处查看完整版本:https://github.com/cqfn/degitx/blob/master/proto/Makefile

它在Linux和CI管道上正常工作,但在WSL下的Windows上失败,错误为:

语法错误:"("出乎意料的

失败的行是$(PROTOC) --go_out=plugins=grpc:$(OUT) --go_opt=paths=source_relative *.proto

似乎Windows在PATHenv变量中有一些大括号,make --debug将其显示为:

env PATH=/home/username/go/bin:/home/username/.local/bin:/usr/local/bin://usr/sbin:/usr/bin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files(x86(/VVMware/VVMware播放器/bin/:/mnt/c/Ruby25-x64/bin:/mnt/c/WINDOWS:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS/system32/Wbem:/mnt/c/WINDOWS/system32/WindowsPowerShell/v.0:/mnt/WINDOWS:/mnt/c\WINDOWS/system32:/mnt/c/WINDOWS/system32/Wbem:/mnt/c WINDOWS/system32/WindowsPowerShell/V.0:/:/mnt/c/WINDOWS/system32/WindowsPowerShell/v.0/WINDOWS/system32/OpenSSH/:/mnt/c/程序文件(x86(/NVIDIACorporation/PhysX/Common:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Go/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/CMake/bin:/mnt/c/WINDOWS/system32:/mnt/c/c/WINDOWS/system32/Wbem:/mnt/c/WINDOWS/system32/WindowsPowerShell/v.0/:/mnt/c\WINDOWS/system32/OpenSSH/:/mnt/c/Program Files/PowerShell/7/:/mnt/c/程序文件/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version bin:/mnt/c/Ruby26-x64/bin:/mnt/c/Users/username/AppData/Local/Microsoft/WindowsApps:/mnt/c/Program Files/JetBrains/InIntelliJ IDEA 2020.2.1/bin:/mnt/c/Users/username/go/bin:/mnt/c/ProgramFiles/JetBrains/GoLand 2020.2.2/bin:/mnt/c/Program Files/JetBrains/RubyMine2020.2.1/bin:/snap/bin:/home/username/go/bin:/home/user name/.local/bin protoc--go_out=plugins=grpc:/mnt/c/Users/username/GitHub/degitx/proto/go/degitxpb--go_opt=paths=source_relative*.proto

请注意:/mnt/c/Program Files (x86)/*PATH条目。

如何在Windows上正确运行此脚本以避免此错误?也许我需要以某种方式逃离环境变量?

在POSIX shell中,您需要应用引号,如下所示:

PROTOC := env PATH="$(GOPATH)/bin:${PATH}" protoc

相关内容

  • 没有找到相关文章