@@ -377,7 +377,7 @@ func (b *Builder) build(a *Action) (err error) {
377
377
if b .NeedExport {
378
378
p .Export = a .built
379
379
}
380
- if need & needCompiledGoFiles != 0 && b .loadCachedGoFiles (a ) {
380
+ if need & needCompiledGoFiles != 0 && b .loadCachedSrcFiles (a ) {
381
381
need &^= needCompiledGoFiles
382
382
}
383
383
// Otherwise, we need to write files to a.Objdir (needVet, needCgoHdr).
@@ -575,7 +575,13 @@ func (b *Builder) build(a *Action) (err error) {
575
575
b .cacheCgoHdr (a )
576
576
}
577
577
}
578
- b .cacheGofiles (a , gofiles )
578
+
579
+ var srcfiles []string // .go and non-.go
580
+ srcfiles = append (srcfiles , gofiles ... )
581
+ srcfiles = append (srcfiles , sfiles ... )
582
+ srcfiles = append (srcfiles , cfiles ... )
583
+ srcfiles = append (srcfiles , cxxfiles ... )
584
+ b .cacheSrcFiles (a , srcfiles )
579
585
580
586
// Running cgo generated the cgo header.
581
587
need &^= needCgoHdr
@@ -587,11 +593,11 @@ func (b *Builder) build(a *Action) (err error) {
587
593
588
594
// Prepare Go vet config if needed.
589
595
if need & needVet != 0 {
590
- buildVetConfig (a , gofiles )
596
+ buildVetConfig (a , srcfiles )
591
597
need &^= needVet
592
598
}
593
599
if need & needCompiledGoFiles != 0 {
594
- if ! b .loadCachedGoFiles (a ) {
600
+ if ! b .loadCachedSrcFiles (a ) {
595
601
return fmt .Errorf ("failed to cache compiled Go files" )
596
602
}
597
603
need &^= needCompiledGoFiles
@@ -794,13 +800,13 @@ func (b *Builder) loadCachedCgoHdr(a *Action) bool {
794
800
return err == nil
795
801
}
796
802
797
- func (b * Builder ) cacheGofiles (a * Action , gofiles []string ) {
803
+ func (b * Builder ) cacheSrcFiles (a * Action , srcfiles []string ) {
798
804
c := cache .Default ()
799
805
if c == nil {
800
806
return
801
807
}
802
808
var buf bytes.Buffer
803
- for _ , file := range gofiles {
809
+ for _ , file := range srcfiles {
804
810
if ! strings .HasPrefix (file , a .Objdir ) {
805
811
// not generated
806
812
buf .WriteString ("./" )
@@ -815,42 +821,42 @@ func (b *Builder) cacheGofiles(a *Action, gofiles []string) {
815
821
return
816
822
}
817
823
}
818
- c .PutBytes (cache .Subkey (a .actionID , "gofiles " ), buf .Bytes ())
824
+ c .PutBytes (cache .Subkey (a .actionID , "srcfiles " ), buf .Bytes ())
819
825
}
820
826
821
827
func (b * Builder ) loadCachedVet (a * Action ) bool {
822
828
c := cache .Default ()
823
829
if c == nil {
824
830
return false
825
831
}
826
- list , _ , err := c .GetBytes (cache .Subkey (a .actionID , "gofiles " ))
832
+ list , _ , err := c .GetBytes (cache .Subkey (a .actionID , "srcfiles " ))
827
833
if err != nil {
828
834
return false
829
835
}
830
- var gofiles []string
836
+ var srcfiles []string
831
837
for _ , name := range strings .Split (string (list ), "\n " ) {
832
838
if name == "" { // end of list
833
839
continue
834
840
}
835
841
if strings .HasPrefix (name , "./" ) {
836
- gofiles = append (gofiles , name [2 :])
842
+ srcfiles = append (srcfiles , name [2 :])
837
843
continue
838
844
}
839
845
if err := b .loadCachedObjdirFile (a , c , name ); err != nil {
840
846
return false
841
847
}
842
- gofiles = append (gofiles , a .Objdir + name )
848
+ srcfiles = append (srcfiles , a .Objdir + name )
843
849
}
844
- buildVetConfig (a , gofiles )
850
+ buildVetConfig (a , srcfiles )
845
851
return true
846
852
}
847
853
848
- func (b * Builder ) loadCachedGoFiles (a * Action ) bool {
854
+ func (b * Builder ) loadCachedSrcFiles (a * Action ) bool {
849
855
c := cache .Default ()
850
856
if c == nil {
851
857
return false
852
858
}
853
- list , _ , err := c .GetBytes (cache .Subkey (a .actionID , "gofiles " ))
859
+ list , _ , err := c .GetBytes (cache .Subkey (a .actionID , "srcfiles " ))
854
860
if err != nil {
855
861
return false
856
862
}
@@ -879,6 +885,7 @@ type vetConfig struct {
879
885
Dir string // directory containing package
880
886
ImportPath string // canonical import path ("package path")
881
887
GoFiles []string // absolute paths to package source files
888
+ NonGoFiles []string // absolute paths to package non-Go files
882
889
883
890
ImportMap map [string ]string // map import path in source code to package path
884
891
PackageFile map [string ]string // map package path to .a file with export data
@@ -890,7 +897,18 @@ type vetConfig struct {
890
897
SucceedOnTypecheckFailure bool // awful hack; see #18395 and below
891
898
}
892
899
893
- func buildVetConfig (a * Action , gofiles []string ) {
900
+ func buildVetConfig (a * Action , srcfiles []string ) {
901
+ // Classify files based on .go extension.
902
+ // srcfiles does not include raw cgo files.
903
+ var gofiles , nongofiles []string
904
+ for _ , name := range srcfiles {
905
+ if strings .HasSuffix (name , ".go" ) {
906
+ gofiles = append (gofiles , name )
907
+ } else {
908
+ nongofiles = append (nongofiles , name )
909
+ }
910
+ }
911
+
894
912
// Pass list of absolute paths to vet,
895
913
// so that vet's error messages will use absolute paths,
896
914
// so that we can reformat them relative to the directory
@@ -899,6 +917,7 @@ func buildVetConfig(a *Action, gofiles []string) {
899
917
Compiler : cfg .BuildToolchainName ,
900
918
Dir : a .Package .Dir ,
901
919
GoFiles : mkAbsFiles (a .Package .Dir , gofiles ),
920
+ NonGoFiles : mkAbsFiles (a .Package .Dir , nongofiles ),
902
921
ImportPath : a .Package .ImportPath ,
903
922
ImportMap : make (map [string ]string ),
904
923
PackageFile : make (map [string ]string ),
@@ -995,6 +1014,8 @@ func (b *Builder) vet(a *Action) error {
995
1014
}
996
1015
}
997
1016
1017
+ // TODO(adonovan): delete this when we use the new vet printf checker.
1018
+ // https://github.com/golang/go/issues/28756
998
1019
if vcfg .ImportMap ["fmt" ] == "" {
999
1020
a1 := a .Deps [1 ]
1000
1021
vcfg .ImportMap ["fmt" ] = "fmt"
0 commit comments