@@ -120,44 +120,44 @@ func gopyRunCmdPkg(cmdr *commander.Command, args []string) error {
120120 }
121121
122122 for _ , path := range args {
123- var rootdir string
124- var err error
125- if strings .HasPrefix (path , "./" ) {
126- rootdir = path
127- } else {
128- rootdir , err = GoSrcDir (path )
129- }
130- if err != nil {
131- return err
132- }
133- buildPkgRecurse (odir , path , rootdir , rootdir , exmap )
123+ buildPkgRecurse (odir , path , path , exmap )
134124 }
135125 return runBuild (bind .ModePkg , odir , name , cmdstr , vm , mainstr , symbols )
136126}
137127
138- func buildPkgRecurse (odir , path , rootdir , pathdir string , exmap map [string ]struct {}) {
139- reldir , _ := filepath .Rel (rootdir , pathdir )
140- gofiles := GoFiles (pathdir )
141- // fmt.Printf("go files: %s\n", gofiles)
128+ func buildPkgRecurse (odir , path , rootpath string , exmap map [string ]struct {}) error {
129+ buildFirst := path == rootpath
130+ bpkg , err := loadPackage (path , buildFirst )
131+ if err != nil {
132+ return fmt .Errorf ("gopy-gen: go build / load of package failed with path=%q: %v" , path , err )
133+ }
134+ gofiles := bpkg .GoFiles
142135 if len (gofiles ) == 0 || (len (gofiles ) == 1 && gofiles [0 ] == "doc.go" ) {
143- fmt .Printf ("\t skipping dir with no go files or only doc.go file: %s -- %s\n " , pathdir , gofiles )
144- } else {
145- if reldir == "" {
146- newPackage (path )
147- } else {
148- pkgpath := path + "/" + reldir
149- newPackage (pkgpath )
136+ fmt .Printf ("\t skipping dir with no go files or only doc.go file: %s -- %s\n " , path , gofiles )
137+ if len (gofiles ) == 0 {
138+ // fmt.Printf("otherfiles: %v\nignorefiles: %v\n", bpkg.OtherFiles, bpkg.IgnoredFiles)
139+ if len (bpkg .OtherFiles ) > 0 {
140+ gofiles = bpkg .OtherFiles
141+ } else if len (bpkg .IgnoredFiles ) > 0 {
142+ gofiles = bpkg .IgnoredFiles
143+ } else {
144+ return nil // done
145+ }
150146 }
147+ } else {
148+ parsePackage (bpkg )
151149 }
152150
153151 // now try all subdirs
154- drs := Dirs (pathdir )
152+ dir , _ := filepath .Split (gofiles [0 ])
153+ drs := Dirs (dir )
155154 for _ , dr := range drs {
156155 _ , ex := exmap [dr ]
157156 if ex || dr [0 ] == '.' || dr [0 ] == '_' {
158157 continue
159158 }
160- sp := filepath .Join (pathdir , dr )
161- buildPkgRecurse (odir , path , rootdir , sp , exmap )
159+ sp := filepath .Join (path , dr )
160+ buildPkgRecurse (odir , sp , rootpath , exmap )
162161 }
162+ return nil
163163}
0 commit comments