【发布时间】:2020-10-12 11:34:42
【问题描述】:
我有一个用于 go 项目的 Makefile,它有一个生成 protobuf 源的步骤。最小的可重现示例是(假设所有必需的依赖项都已安装并且 proto 文件位置正确):
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 在 PATH 环境变量中有一些大括号,make --debug 显示为:
env PATH=/home/username/go/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/ sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files (x86)/VMware/VMware Player/bin/:/mnt/c/Ruby25-x64/bin:/mnt/ c/WINDOWS:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0:/mnt/c/Windows:/mnt/c /Windows/system32:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/ c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files (x86)/NVIDIA Corporation/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/WINDOWS:/mnt/c/WINDOWS/System32/Wbem :/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/PowerShell/7/:/mnt/c/Program Files/ Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin :/mnt/c/Ruby26-x64/bin:/mnt/c/Users/用户名/AppData/Local/Microsoft/WindowsApps:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2020.2.1/bin:/mnt/ c/Users/用户名/go/bin:/mnt/c/Program Files/JetBrains/GoLand 2020.2.2/bin:/mnt/c/Program Files/JetBrains/RubyMine 2020.2.1/bin:/snap/bin:/ home/username/go/bin:/home/username/.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 上正确运行此脚本以避免此错误?也许我需要以某种方式转义环境变量?
【问题讨论】:
标签: windows makefile path environment-variables