mirror of
				https://github.com/golang/go.git
				synced 2025-10-31 08:40:55 +00:00 
			
		
		
		
	cmd/go: note when some Go files were ignored on no-Go-files errors
It is pretty confusing when there are Go files ignored for mismatching build tags and similar and we output "no buildable Go files" without giving any other information about some Go files have been ignored. Fixes #17008. Change-Id: I1766ee86a9a7a72f6694deae3f73b47bfc9d0be5 Reviewed-on: https://go-review.googlesource.com/29113 Run-TryBot: Jaana Burcu Dogan <jbd@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
		
							parent
							
								
									6abc4a7c3e
								
							
						
					
					
						commit
						eee727d085
					
				
					 3 changed files with 22 additions and 3 deletions
				
			
		|  | @ -410,11 +410,16 @@ func (ctxt *Context) ImportDir(dir string, mode ImportMode) (*Package, error) { | |||
| // containing no buildable Go source files. (It may still contain | ||||
| // test files, files hidden by build tags, and so on.) | ||||
| type NoGoError struct { | ||||
| 	Dir string | ||||
| 	Dir     string | ||||
| 	Ignored bool // whether any Go files were ignored due to build tags | ||||
| } | ||||
| 
 | ||||
| func (e *NoGoError) Error() string { | ||||
| 	return "no buildable Go source files in " + e.Dir | ||||
| 	msg := "no buildable Go source files in " + e.Dir | ||||
| 	if e.Ignored { | ||||
| 		msg += " (.go files ignored due to build tags)" | ||||
| 	} | ||||
| 	return msg | ||||
| } | ||||
| 
 | ||||
| // MultiplePackageError describes a directory containing | ||||
|  | @ -846,7 +851,7 @@ Found: | |||
| 		return p, badGoError | ||||
| 	} | ||||
| 	if len(p.GoFiles)+len(p.CgoFiles)+len(p.TestGoFiles)+len(p.XTestGoFiles) == 0 { | ||||
| 		return p, &NoGoError{p.Dir} | ||||
| 		return p, &NoGoError{Dir: p.Dir, Ignored: len(p.IgnoredGoFiles) > 0} | ||||
| 	} | ||||
| 
 | ||||
| 	for tag := range allTags { | ||||
|  |  | |||
|  | @ -93,6 +93,17 @@ func TestEmptyFolderImport(t *testing.T) { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestIgnoredGoFilesImport(t *testing.T) { | ||||
| 	_, err := Import(".", "testdata/ignored", 0) | ||||
| 	e, ok := err.(*NoGoError) | ||||
| 	if !ok { | ||||
| 		t.Fatal(`Import("testdata/ignored") did not return NoGoError.`) | ||||
| 	} | ||||
| 	if !e.Ignored { | ||||
| 		t.Fatal(`Import("testdata/ignored") should have ignored Go files.`) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestMultiplePackageImport(t *testing.T) { | ||||
| 	_, err := Import(".", "testdata/multi", 0) | ||||
| 	mpe, ok := err.(*MultiplePackageError) | ||||
|  |  | |||
							
								
								
									
										3
									
								
								src/go/build/testdata/ignored/ignored.go
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/go/build/testdata/ignored/ignored.go
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| // +build alwaysignore | ||||
| 
 | ||||
| package ignored | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jaana Burcu Dogan
						Jaana Burcu Dogan