cmd/go: clean paths before checking whether command line files are in same directory

This commit is contained in:
gerrard 2021-07-27 09:25:00 +08:00
parent cfa233d76b
commit c7c4905bb9
2 changed files with 13 additions and 6 deletions

View File

@ -2674,10 +2674,7 @@ func GoFilesPackage(ctx context.Context, opts PackageOpts, gofiles []string) *Pa
if fi.IsDir() {
base.Fatalf("%s is a directory, should be a Go file", file)
}
dir1, _ := filepath.Split(file)
if dir1 == "" {
dir1 = "./"
}
dir1 := filepath.Dir(file)
if dir == "" {
dir = dir1
} else if dir != dir1 {

View File

@ -1,11 +1,21 @@
cd rundir
! go run x.go sub/sub.go
stderr 'named files must all be in one directory; have ./ and sub/'
stderr 'named files must all be in one directory; have . and sub'
! go run sub/sub.go x.go
stderr 'named files must all be in one directory; have sub/ and ./'
stderr 'named files must all be in one directory; have sub and .'
cd ../
go run rundir/foo.go ./rundir/bar.go
stderr 'hello world'
-- rundir/sub/sub.go --
package main
-- rundir/x.go --
package main
-- rundir/foo.go --
package main
func main() { println(msg) }
-- rundir/bar.go --
package main
const msg = "hello world"