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

cmd/go: cgo generates too long a path on windows #17070

Closed
chai2010 opened this issue Sep 12, 2016 · 12 comments
Closed

cmd/go: cgo generates too long a path on windows #17070

chai2010 opened this issue Sep 12, 2016 · 12 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@chai2010
Copy link
Contributor

https://github.com/chai2010/hello-swig-bug

@Thomasdezeeuw
Copy link
Contributor

I think #3358 is related.

@chai2010
Copy link
Contributor Author

if use cgo, it is ok. the bug is only for build with x.swig.

@quentinmit
Copy link
Contributor

It looks like these filenames are chosen by SWIG, not by Go. Is there anything we can do about that?

@quentinmit quentinmit changed the title SWIG generate too long path on windows cmd/build: SWIG generates too long a path on windows Sep 12, 2016
@ianlancetaylor
Copy link
Contributor

What is the file whose path is too long?

What created that file?

Is the problem that the total path is too long, or that an individual name in the path is too long?

@chai2010
Copy link
Contributor Author

1. swig generate the hello_with_tooooooo_long_path.go

swig -go -cgo -intgosize 64 -module hello_with_tooooooo_long_path -o "C:\Users\chai\AppData\Local\Temp\go-build509547282\github.com\chai2010\hello-swig-bug_test_obj_test\hello_with_tooooooo_long_path_wrap.c" -outdir "C:\Users\chai\AppData\Local\Temp\go-build509547282\github.com\chai2010\hello-swig-bug_test_obj_test" hello_with_tooooooo_long_path.swig

the full path length is 135.

2. then cgo use the hello_with_tooooooo_long_path.go to generate xxx.cgo1.go

go tool cgo -objdir "C:\Users\chai\AppData\Local\Temp\go-build509547282\github.com\chai2010\hello-swig-bug_test_obj_test" -importpath github.com/chai2010/hello-swig-bug "C:\Users\chai\AppData\Local\Temp\go-build509547282\github.com\chai2010\hello-swig-bug_test_obj_test\hello_with_tooooooo_long_path.go"

the xxx.cgo1.go full path length large than 260 (overflow).

open C:\Users\chai\AppData\Local\Temp\go-build509547282\github.com\chai2010\hello-swig-bug_test_obj_test\C___Users__chai__AppData__Local__Temp__go-build509547282__github.com__chai2010__hello-swig-bug___test___obj_test__hello_with_tooooooo_long_path.cgo1.go: The system cannot find the path specified.

@ianlancetaylor
Copy link
Contributor

Thanks. I don't think there is any swig problem here. The problem is cgo. cgo is generating the file WORKDIR/WORKDIRNAME_FILE.cgo1.go where WORKDIRNAME is WORKDIR with the slashes replaced by underscores. When WORKDIR is long, as it often is, the resulting file name is quite long. One way to fix this is to have cmd/go pass a -srcdir option to cmd/cgo, which will cause WORKDIRNAME to contain just the file name, which is all we really need anyhow.

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Sep 14, 2016
@ianlancetaylor ianlancetaylor changed the title cmd/build: SWIG generates too long a path on windows cmd/go: cgo generates too long a path on windows Sep 14, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 6, 2016
@rsc
Copy link
Contributor

rsc commented Oct 21, 2016

The root cause here is #3358, which we have yet to fix.

Why is cgo putting WORKDIRNAME into the generated file name at all?

Also, cgo has no -srcdir option (that's a local Google modification we should upstream).

@ianlancetaylor
Copy link
Contributor

cgo putting WORKDIRNAME into the generated file name predates the go tool, when apparently cgo files could live in a separate directory. It was added in https://golang.org/cl/1734047 to fix #533. Maybe we could just stop doing that now.

@gopherbot
Copy link

CL https://golang.org/cl/32354 mentions this issue.

gopherbot pushed a commit that referenced this issue Oct 30, 2016
This is convenient for direct use of `go tool cgo`. We can also use it
from the go tool to reduce the length of the file names that cgo
generates.

Update #17070.

Change-Id: I8466a0a2cc68a732d17d07319e303497715bac8c
Reviewed-on: https://go-review.googlesource.com/32354
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
@gopherbot
Copy link

CL https://golang.org/cl/32436 mentions this issue.

@gopherbot
Copy link

CL https://golang.org/cl/32485 mentions this issue.

@gopherbot
Copy link

Change https://golang.org/cl/56280 mentions this issue: cmd/go: stop creating nested temp directory trees

gopherbot pushed a commit that referenced this issue Sep 30, 2017
Now that we have -importcfg, there's no need for the
temporary directory trees that mirror the import path structure,
and we can drop a bunch of complex code that was building
and maintaining that structure.

This should fix "file name too long" errors on systems with low limits.
(For example #10651 and #17070, although we fixed those by
adding code to deal with very long file names on Windows instead.)

Change-Id: I11e221c6c1edeb81c3b2f1d89988f5235aa2bbb9
Reviewed-on: https://go-review.googlesource.com/56280
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Aug 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants
@rsc @quentinmit @chai2010 @Thomasdezeeuw @ianlancetaylor @gopherbot and others