@@ -6244,3 +6244,47 @@ func TestNoRelativeTmpdir(t *testing.T) {
6244
6244
tg .grepStderr ("relative tmpdir" , "wrong error" )
6245
6245
}
6246
6246
}
6247
+
6248
+ // Issue 24704.
6249
+ func TestLinkerTmpDirIsDeleted (t * testing.T ) {
6250
+ tg := testgo (t )
6251
+ defer tg .cleanup ()
6252
+ tg .parallel ()
6253
+ tg .tempFile ("a.go" , `package main; import "C"; func main() {}` )
6254
+ tg .run ("build" , "-ldflags" , "-v" , "-o" , os .DevNull , tg .path ("a.go" ))
6255
+ // Find line that has "host link:" in linker output.
6256
+ stderr := tg .getStderr ()
6257
+ var hostLinkLine string
6258
+ for _ , line := range strings .Split (stderr , "\n " ) {
6259
+ if ! strings .Contains (line , "host link:" ) {
6260
+ continue
6261
+ }
6262
+ hostLinkLine = line
6263
+ break
6264
+ }
6265
+ if hostLinkLine == "" {
6266
+ t .Fatal (`fail to find with "host link:" string in linker output` )
6267
+ }
6268
+ // Find parameter, like "/tmp/go-link-408556474/go.o" inside of
6269
+ // "host link:" line, and extract temp directory /tmp/go-link-408556474
6270
+ // out of it.
6271
+ tmpdir := hostLinkLine
6272
+ i := strings .Index (tmpdir , `go.o"` )
6273
+ if i == - 1 {
6274
+ t .Fatalf (`fail to find "go.o" in "host link:" line %q` , hostLinkLine )
6275
+ }
6276
+ tmpdir = tmpdir [:i - 1 ]
6277
+ i = strings .LastIndex (tmpdir , `"` )
6278
+ if i == - 1 {
6279
+ t .Fatalf (`fail to find " in "host link:" line %q` , hostLinkLine )
6280
+ }
6281
+ tmpdir = tmpdir [i + 1 :]
6282
+ // Verify that temp directory has been removed.
6283
+ _ , err := os .Stat (tmpdir )
6284
+ if err == nil {
6285
+ t .Fatalf ("temp directory %q has not been removed" , tmpdir )
6286
+ }
6287
+ if ! os .IsNotExist (err ) {
6288
+ t .Fatalf ("Stat(%q) returns unexpected error: %v" , tmpdir , err )
6289
+ }
6290
+ }
0 commit comments