2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
5
- // package importer implements Import for gc-generated object files.
5
+ // This file contains the FindPkg and Import functions for tests
6
+ // to use gc-generated object files.
7
+
6
8
package importer
7
9
8
10
import (
@@ -75,7 +77,11 @@ var pkgExts = [...]string{".a", ".o"} // a file from the build cache will have n
75
77
// path based on package information provided by build.Import (using
76
78
// the build.Default build.Context). A relative srcDir is interpreted
77
79
// relative to the current working directory.
80
+ //
81
+ // This function should only be used in tests.
78
82
func FindPkg (path , srcDir string ) (filename , id string , err error ) {
83
+ // TODO(taking): move FindPkg into src/internal and dedup src/go/internal/gcimporter.FindPkg
84
+
79
85
if path == "" {
80
86
return "" , "" , errors .New ("path is empty" )
81
87
}
@@ -147,6 +153,8 @@ notfound:
147
153
// Import imports a gc-generated package given its import path and srcDir, adds
148
154
// the corresponding package object to the packages map, and returns the object.
149
155
// The packages map must contain all packages already imported.
156
+ //
157
+ // This function should only be used in tests.
150
158
func Import (packages map [string ]* types2.Package , path , srcDir string , lookup func (path string ) (io.ReadCloser , error )) (pkg * types2.Package , err error ) {
151
159
var rc io.ReadCloser
152
160
var id string
@@ -208,6 +216,7 @@ func Import(packages map[string]*types2.Package, path, srcDir string, lookup fun
208
216
err = fmt .Errorf ("import %q: old textual export format no longer supported (recompile library)" , path )
209
217
210
218
case "$$B\n " :
219
+ // TODO(taking): minimize code delta with src/go/internal/gcimporter.Import.
211
220
var data []byte
212
221
var r io.Reader = buf
213
222
if size >= 0 {
@@ -225,18 +234,18 @@ func Import(packages map[string]*types2.Package, path, srcDir string, lookup fun
225
234
exportFormat := data [0 ]
226
235
s := string (data [1 :])
227
236
228
- // The indexed export format starts with an 'i'; the older
229
- // binary export format starts with a 'c', 'd', or 'v'
230
- // (from "version"). Select appropriate importer.
237
+ // The unified export format starts with a 'u'; the indexed export
238
+ // format starts with an 'i'; and the older binary export format
239
+ // starts with a 'c', 'd', or 'v' (from "version"). Select
240
+ // appropriate importer.
231
241
switch exportFormat {
232
242
case 'u' :
243
+ // TODO(taking): Look into whether this should be LastIndex instead of Index.
233
244
s = s [:strings .Index (s , "\n $$\n " )]
234
245
input := pkgbits .NewPkgDecoder (id , s )
235
246
pkg = ReadPackage (nil , packages , input )
236
- case 'i' :
237
- pkg , err = ImportData (packages , s , id )
238
247
default :
239
- err = fmt .Errorf ("import %q: old binary export format no longer supported (recompile library )" , path )
248
+ err = fmt .Errorf ("import %q: binary export format %q is no longer supported (recompile package )" , path , exportFormat )
240
249
}
241
250
242
251
default :
0 commit comments