Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/build/cmd/gorebuild: uses wrong path separator for running make.bat on Windows #61951

Closed
qiulaidongfeng opened this issue Aug 11, 2023 · 7 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Milestone

Comments

@qiulaidongfeng
Copy link
Member

What version of Go are you using (go version)?

$ go version
go version devel go1.22-3393155 Mon Aug 7 23:13:36 2023 +0000 windows/amd64

Does this issue reproduce with the latest release?

yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=auto
set GOARCH=amd64
set GOBIN=
set GOCACHE=E:\TEMP\go-build
set GOENV=C:\Users\Administrator\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=E:\gofile\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\gofile
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct
set GOROOT=C:\Users\Administrator\.go\current
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=local
set GOTOOLDIR=C:\Users\Administrator\.go\current\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=devel go1.22-3393155 Mon Aug 7 23:13:36 2023 +0000
set GCCGO=gccgo
set GOAMD64=v2
set AR=ar
set CC=clang
set CXX=clang++
set CGO_ENABLED=0
set GOMOD=E:\TEMP\gorebuild-1498172390\repro-go1.21.0-windows-amd64\src\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=E:\TEMP\go-build4003734977=/tmp/go-build -gno-record-gcc-switches
GOROOT/bin/go version: go version devel go1.22-3393155 Mon Aug 7 23:13:36 2023 +0000 windows/amd64
GOROOT/bin/go tool compile -V: compile version devel go1.22-3393155 Mon Aug 7 23:13:36 2023 +0000
lldb --version: lldb version 16.0.5
gdb --version: GNU gdb (GDB for MinGW-W64 x86_64, built by Brecht Sanders) 13.2

What did you do?

On the Winwods computer.

go install golang.org/x/build/cmd/gorebuild@latest

gorebuild windows-amd64

What did you expect to see?

Program runs normally.

What did you see instead?

12:58:06.689 downloaded https://go.dev/dl/?mode=json&include=all
12:58:07.058 [bootstrap go1.17] using go1.17.13 binary distribution for go1.17
12:59:16.161 [bootstrap go1.17] downloaded https://go.dev/dl/go1.17.13.windows-amd64.zip
12:59:44.885 [go1.21.0] downloaded https://go.googlesource.com/go/+archive/refs/tags/go1.21.0.tar.gz
12:59:44.885 [go1.21.0.windows-amd64.zip] start go1.21.0.windows-amd64.zip
12:59:58.284 [go1.21.0.windows-amd64.zip] running ./make.bat env=[GOOS=windows GOARCH=amd64] args=[-distpack]
GOROOT=E:\TEMP\gorebuild-4074831885\repro-go1.21.0-windows-amd64
GOROOT_BOOTSTRAP=E:\TEMP\gorebuild-4074831885\bootstrap-go1.17\go
12:59:58.357 [go1.21.0.windows-amd64.zip] ./make.bat: exit status 1
'.' is not recognized as an internal or external command,
operable program or batch file.
13:00:07.187 [go1.21.0.windows-amd64.zip] FAIL: ./make.bat in E:\TEMP\gorebuild-4074831885\repro-go1.21.0-windows-amd64 failed
13:00:07.189 [go1.21.0.src.tar.gz] FAIL: file not checked
13:00:07.189 [go1.21.0] FAIL: go1.21.0.src.tar.gz did not verify
13:00:07.190 [go1.21.0.windows-amd64.msi] FAIL: file not checked
13:00:07.190 [go1.21.0] FAIL: go1.21.0.windows-amd64.msi did not verify
13:00:07.190 [go1.21.0] FAIL: go1.21.0.windows-amd64.zip did not verify
13:00:07.190 [v0.0.1-go1.21.0.windows-amd64.info] FAIL: file not checked
13:00:07.190 [go1.21.0] FAIL: v0.0.1-go1.21.0.windows-amd64.info did not verify
13:00:07.191 [v0.0.1-go1.21.0.windows-amd64.mod] FAIL: file not checked
13:00:07.191 [go1.21.0] FAIL: v0.0.1-go1.21.0.windows-amd64.mod did not verify
13:00:07.191 [v0.0.1-go1.21.0.windows-amd64.zip] FAIL: file not checked
13:00:07.192 [go1.21.0] FAIL: v0.0.1-go1.21.0.windows-amd64.zip did not verify
13:00:07.193 FAIL: go1.21.0 did not verify

@qiulaidongfeng
Copy link
Member Author

seem to be https://github.com/golang/go/blob/master/src/os/exec/lp_windows.go#L101 Causing this issue.
If it is changed to return lp+ext, nil, the correct absolute path will be returned, but go test os/exec will fail.
output:

--- FAIL: TestCommand (3.59s)
--- FAIL: TestCommand/15 (0.41s)
lp_windows_test.go:396: test={PATH:p2 files:[p\a.exe p2\a.exe] dir:p arg0:.\a want:p\a.exe fails:false}: exec: exit status 1 Child: fork/exec p\a.exe.exe: The system cannot find the path specified.
FAIL
exit status 1

@qmuntal qmuntal added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows labels Aug 11, 2023
@qmuntal
Copy link
Contributor

qmuntal commented Aug 11, 2023

Does this issue reproduces with go1.21? Else, can it be a regression from CL 512155?

@qiulaidongfeng
Copy link
Member Author

Both go1.21.0 and tip will reproduce on my computer.

@bcmills bcmills added this to the Go1.22 milestone Aug 11, 2023
@bcmills bcmills changed the title os/exec: If GOOS=windows, executing executable files in the current directory failed os/exec: If GOOS=windows, executing executable files in the current directory fails Aug 11, 2023
@bcmills
Copy link
Contributor

bcmills commented Aug 11, 2023

@gopherbot, please backport to Go 1.21. This is a regression from previous Go releases.

@gopherbot
Copy link

Backport issue(s) opened: #61957 (for 1.21).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@qmuntal
Copy link
Contributor

qmuntal commented Aug 11, 2023

@bcmills I don't think this is a regression. I can reproduce the same issue with all previous versions till at least go 1.12 using this self-contained reproducer:

package main

import (
	"fmt"
	"io/ioutil" // for compatibility with old Go versions
	"os"
	"os/exec"
)

func main() {
	const make = "./make.bat"
	err := ioutil.WriteFile(make, []byte("echo \"Hello\""), 0666)
	if err != nil {
		fmt.Printf("error writing make.bat: %s", err)
		os.Exit(1)
	}
	out, err := exec.Command(make).CombinedOutput()
	if err != nil {
		fmt.Printf("%s: %s\n%s", make, err, out)
		os.Exit(1)
	}
	fmt.Printf("%s completed:\n%s", make, out)
}
C:\Users\qmuntaldiaz\code\gotest>go1.12.1 run main.go 
./make.bat: exit status 1
'.' is not recognized as an internal or external command,
operable program or batch file.
exit status 1

The issue is fixed if replacing ./make.bat to .\\make.bat.

Same behavior if using just cmd:

C:\Users\qmuntaldiaz\code\gotest>./make.bat
'.' is not recognized as an internal or external command,
operable program or batch file.

@gopherbot
Copy link

Change https://go.dev/cl/518735 mentions this issue: cmd/gorebuild: fix running gorebuild on Windows

@dmitshur dmitshur changed the title os/exec: If GOOS=windows, executing executable files in the current directory fails x/build/cmd/gorebuild: uses wrong path separator for running make.bat on Windows Aug 11, 2023
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 11, 2023
@dmitshur dmitshur modified the milestones: Go1.22, Unreleased Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Projects
Archived in project
Development

No branches or pull requests

5 participants